summaryrefslogtreecommitdiffstats
path: root/misc-utils/script.c
diff options
context:
space:
mode:
authorKarel Zak2010-04-29 12:25:06 +0200
committerKarel Zak2010-04-29 12:25:06 +0200
commitf0bc3fa0cf45f484ea696ef063a10b65d1a45e13 (patch)
tree06ef042a01480b64de2c482251388a296f3d740f /misc-utils/script.c
parentfdisk: improve 'move begin of partition' command (diff)
downloadkernel-qcow2-util-linux-f0bc3fa0cf45f484ea696ef063a10b65d1a45e13.tar.gz
kernel-qcow2-util-linux-f0bc3fa0cf45f484ea696ef063a10b65d1a45e13.tar.xz
kernel-qcow2-util-linux-f0bc3fa0cf45f484ea696ef063a10b65d1a45e13.zip
script: optionally compile with libutempter to update utmp
Use --with-utempter to enable utempter support. The libutempter calls /usr/libexec/utempter/utempter suid helper to update utmp and wtmp files. Old version: $ script Script started, file is typescript $ who i am $ exit Script done, file is typescript New version: $ script Script started, file is typescript $ who i am kzak pts/6 2010-04-29 12:30 $ exit Script done, file is typescript Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=477753 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/script.c')
-rw-r--r--misc-utils/script.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/misc-utils/script.c b/misc-utils/script.c
index e3ccb1a18..2028db664 100644
--- a/misc-utils/script.c
+++ b/misc-utils/script.c
@@ -59,11 +59,14 @@
#include "nls.h"
-
#ifdef HAVE_LIBUTIL
#include <pty.h>
#endif
+#ifdef HAVE_LIBUTEMPTER
+#include <utempter.h>
+#endif
+
void finish(int);
void done(void);
void fail(void);
@@ -77,7 +80,7 @@ void doshell(void);
char *shell;
FILE *fscript;
-int master;
+int master = -1;
int slave;
int child;
int subchild;
@@ -202,6 +205,9 @@ main(int argc, char **argv) {
printf(_("Script started, file is %s\n"), fname);
fixtty();
+#ifdef HAVE_LIBUTEMPTER
+ utempter_add_record(master, NULL);
+#endif
/* setup SIGCHLD handler */
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
@@ -391,6 +397,8 @@ doshell() {
(void) dup2(slave, 2);
(void) close(slave);
+ master = -1;
+
shname = strrchr(shell, '/');
if (shname)
shname++;
@@ -436,10 +444,16 @@ done() {
}
(void) fclose(fscript);
(void) close(master);
+
+ master = -1;
} else {
(void) tcsetattr(0, TCSADRAIN, &tt);
if (!qflg)
printf(_("Script done, file is %s\n"), fname);
+#ifdef HAVE_LIBUTEMPTER
+ if (master >= 0)
+ utempter_remove_record(master);
+#endif
}
if(eflg) {
@@ -488,9 +502,11 @@ getmaster() {
return;
}
(void) close(master);
+ master = -1;
}
}
}
+ master = -1;
fprintf(stderr, _("Out of pty's\n"));
fail();
#endif /* not HAVE_LIBUTIL */