diff options
author | Karel Zak <kzak@redhat.com> | 2010-04-29 12:25:06 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2010-04-29 12:25:06 +0200 |
commit | f0bc3fa0cf45f484ea696ef063a10b65d1a45e13 (patch) | |
tree | 06ef042a01480b64de2c482251388a296f3d740f /misc-utils | |
parent | 6a2de3f13134dfd49eb93c7b15552de81b868c8a (diff) | |
download | util-linux-old-f0bc3fa0cf45f484ea696ef063a10b65d1a45e13.tar.gz |
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')
-rw-r--r-- | misc-utils/Makefile.am | 7 | ||||
-rw-r--r-- | misc-utils/script.c | 20 |
2 files changed, 24 insertions, 3 deletions
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index b5b7daa6..ca272560 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -11,6 +11,7 @@ usrbin_exec_PROGRAMS = cal ddate logger look mcookie \ EXTRA_DIST += README.cal README.ddate README.namei README.namei2 mcookie_SOURCES = mcookie.c ../lib/md5.c +script_LDADD = usrbin_exec_SCRIPTS = chkdupexe @@ -66,7 +67,11 @@ endif endif if HAVE_UTIL -script_LDADD = -lutil +script_LDADD += -lutil +endif + +if HAVE_UTEMPTER +script_LDADD += -lutempter endif if HAVE_NCURSES diff --git a/misc-utils/script.c b/misc-utils/script.c index e3ccb1a1..2028db66 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 */ |