From: Karel Zak Date: Thu, 29 Apr 2010 10:25:06 +0000 (+0200) Subject: script: optionally compile with libutempter to update utmp X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0bc3fa0cf45f484ea696ef063a10b65d1a45e13;p=util-linux 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 --- diff --git a/configure.ac b/configure.ac index 121ac502..7fe2d111 100644 --- a/configure.ac +++ b/configure.ac @@ -451,6 +451,21 @@ fi AM_CONDITIONAL(USE_SLANG, test "x$use_slang" = xyes) +AC_ARG_WITH([utempter], + AS_HELP_STRING([--with-utempter], [compile script(1) with libutempter]), + [], with_utempter=no +) + +if test "x$with_utempter" = xyes; then + UTIL_CHECK_LIB(utempter, utempter_add_record) + if test "x$have_utempter" = xno; then + AC_MSG_ERROR([utempter selected but libutempter not found]) + fi +else + AM_CONDITIONAL(HAVE_UTEMPTER, false) +fi + + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #define _XOPEN_SOURCE #include 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 #endif +#ifdef HAVE_LIBUTEMPTER +#include +#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 */