]> err.no Git - util-linux/commitdiff
script: optionally compile with libutempter to update utmp
authorKarel Zak <kzak@redhat.com>
Thu, 29 Apr 2010 10:25:06 +0000 (12:25 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Apr 2010 10:25:06 +0000 (12:25 +0200)
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>
configure.ac
misc-utils/Makefile.am
misc-utils/script.c

index 121ac502ccf67637326cc93a38fc263875fdc227..7fe2d111cd7760fa2bb2e49a9cafd5fd50f6f12b 100644 (file)
@@ -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 <unistd.h>
index b5b7daa64c5c2679ec5199fe72fd0b49aa93b0a0..ca2725603f28e7367a5497d00a9d18a7296f4705 100644 (file)
@@ -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
index e3ccb1a18526e17073527bd804ade7c24da5dbfb..2028db664eba2b26b1ffa9547af05ed96807cc7a 100644 (file)
 
 #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 */