]> granicus.if.org Git - sudo/commitdiff
Add support for pausing and changing the speed in interactive mode.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 7 Oct 2009 01:07:54 +0000 (01:07 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 7 Oct 2009 01:07:54 +0000 (01:07 +0000)
sudoreplay.c
sudoreplay.cat
sudoreplay.man.in
sudoreplay.pod

index 0c315ba55456bc0b67bb26cb220a763415935665..5576009d7d59e43578d999d84f9a40cd11d4eb50 100644 (file)
@@ -148,6 +148,7 @@ static struct search_node *node_stack[32];
 static int stack_top;
 
 extern void *emalloc __P((size_t));
+extern void *emalloc2 __P((size_t, size_t));
 extern void *erealloc __P((void *, size_t));
 extern void efree __P((void *));
 extern time_t get_date __P((char *));
@@ -171,6 +172,7 @@ void cleanup __P((int));
 
 static int list_sessions __P((int, char **, const char *, const char *, const char *));
 static int parse_expr __P((struct search_node **, char **));
+static void check_input __P((int, double *));
 static void delay __P((double));
 static void usage __P((void));
 
@@ -188,15 +190,15 @@ main(argc, argv)
     int argc;
     char **argv;
 {
-    int ch, plen, listonly = 0;
+    int ch, plen, ttyfd, interactive = 0, listonly = 0;
     const char *id, *user = NULL, *pattern = NULL, *tty = NULL;
     char path[PATH_MAX], buf[LINE_MAX], *cp, *ep;
     FILE *tfile, *sfile, *lfile;
     sigaction_t sa;
-    double seconds;
     unsigned long nbytes;
     size_t len, nread;
     ssize_t nwritten;
+    double seconds;
     double speed = 1.0;
     double max_wait = 0;
     double to_wait;
@@ -292,7 +294,12 @@ main(argc, argv)
     sa.sa_handler = SIG_IGN;
     (void) sigaction(SIGTSTP, &sa, NULL);
     (void) sigaction(SIGQUIT, &sa, NULL);
-    term_cbreak(STDOUT_FILENO);
+
+    ttyfd = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0);
+    if (ttyfd != -1) {
+       term_cbreak(ttyfd);
+       interactive = isatty(STDOUT_FILENO);
+    }
 
     /*
      * Timing file consists of line of the format: "%f %d\n"
@@ -309,6 +316,9 @@ main(argc, argv)
        if (errno == ERANGE && nbytes == ULONG_MAX)
            error(1, "invalid timing file byte count: %s", cp);
 
+       if (interactive)
+           check_input(ttyfd, &speed);
+
        /* Adjust delay using speed factor and clamp to max_wait */
        to_wait = seconds / speed;
        if (max_wait && to_wait > max_wait)
@@ -722,6 +732,58 @@ list_sessions(argc, argv, pattern, user, tty)
     return(0);
 }
 
+/*
+ * Check input for ' ', '<', '>'
+ * pause, slow, fast
+ */
+static void
+check_input(ttyfd, speed)
+    int ttyfd;
+    double *speed;
+{
+    fd_set *fdsr;
+    int flags, nready;
+    struct timeval tv;
+    char ch;
+    ssize_t n;
+
+    fdsr = (fd_set *)emalloc2(howmany(ttyfd + 1, NFDBITS), sizeof(fd_mask));
+    FD_SET(ttyfd, fdsr);
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+
+    nready = select(ttyfd + 1, fdsr, NULL, NULL, &tv);
+    if (nready == 1) {
+       flags = fcntl(ttyfd, F_GETFL, 0);
+       if (flags != -1)
+           (void) fcntl(ttyfd, F_SETFL, flags | O_NONBLOCK);
+       do {
+           n = read(ttyfd, &ch, 1);
+           if (n == 1) {
+               switch (ch) {
+               case ' ':
+                   /* wait for another character */
+                   if (flags != -1)
+                       (void) fcntl(ttyfd, F_SETFL, flags);
+                   n = read(ttyfd, &ch, 1);
+                   if (flags != -1)
+                       (void) fcntl(ttyfd, F_SETFL, flags | O_NONBLOCK);
+                   break;
+               case '<':
+                   *speed /= 2;
+                   break;
+               case '>':
+                   *speed *= 2;
+                   break;
+               }
+           }
+       } while (n == 1);
+       if (flags != -1)
+           (void) fcntl(ttyfd, F_SETFL, flags);
+    }
+    free(fdsr);
+}
+
 static void
 usage()
 {
index 15399c88d1e0b0fe133aaf03f100035f9dfbcc2f..56dc10a83439e8f29bee0eba3c0940f26aad9203 100644 (file)
@@ -23,6 +23,16 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
        In list mode, s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by can be used to find the ID of a session based
        on a number of criteria such as the user, tty or command run.
 
+       In replay mode, if the standard output has not been redirected,
+       s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by will act on the following keys:
+
+       ' ' (space)
+               Pause output; press any key to resume.
+
+       '<'     Reduce the playback speed by one half.
+
+       '>'     Double the playback speed.
+
 O\bOP\bPT\bTI\bIO\bON\bNS\bS
        s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by accepts the following command line options:
 
@@ -48,20 +58,10 @@ O\bOP\bPT\bTI\bIO\bON\bNS\bS
                            Evaluates to true if the command was run with the
                            specified current working directory.
 
-                   fromdate _\bd_\ba_\bt_\be
-                           Evaluates to true if the command was run on or
-                           after _\bd_\ba_\bt_\be.  See "Date and time format" for a
-                           description of supported date and time formats.
-
-                   group _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp
-                           Evaluates to true if the command was run with the
-                           specified _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp.  Note that unless a
-                           _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp was explicitly specified when s\bsu\bud\bdo\bo was
-                           run this field will be empty in the log.
 
 
 
-1.7.2                   September 19, 2009                      1
+1.7.2                    October  6, 2009                       1
 
 
 
@@ -70,6 +70,17 @@ O\bOP\bPT\bTI\bIO\bON\bNS\bS
 SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
 
 
+                   fromdate _\bd_\ba_\bt_\be
+                           Evaluates to true if the command was run on or
+                           after _\bd_\ba_\bt_\be.  See "Date and time format" for a
+                           description of supported date and time formats.
+
+                   group _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp
+                           Evaluates to true if the command was run with the
+                           specified _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp.  Note that unless a
+                           _\br_\bu_\bn_\ba_\bs_\b__\bg_\br_\bo_\bu_\bp was explicitly specified when s\bsu\bud\bdo\bo was
+                           run this field will be empty in the log.
+
                    runas _\br_\bu_\bn_\ba_\bs_\b__\bu_\bs_\be_\br
                            Evaluates to true if the command was run as the
                            specified _\br_\bu_\bn_\ba_\bs_\b__\bu_\bs_\be_\br.  Note that s\bsu\bud\bdo\bo runs commands
@@ -113,28 +124,27 @@ SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
                    seconds it will wait between key presses or program output.
                    This can be used to slow down or speed up the display.  For
                    example, a _\bs_\bp_\be_\be_\bd_\b__\bf_\ba_\bc_\bt_\bo_\br of _\b2 would make the output twice as
-                   fast whereas a _\bs_\bp_\be_\be_\bd_\b__\bf_\ba_\bc_\bt_\bo_\br of <.5> would make the output
-                   twice as slow.
-
-       -V          The -\b-V\bV (version) option causes s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by to print its
-                   version number and exit.
 
-       D\bDa\bat\bte\be a\ban\bnd\bd t\bti\bim\bme\be f\bfo\bor\brm\bma\bat\bt
 
-       The time and date may be specified multiple ways, common formats
-       include:
 
+1.7.2                    October  6, 2009                       2
 
 
 
-1.7.2                   September 19, 2009                      2
 
 
+SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
 
 
+                   fast whereas a _\bs_\bp_\be_\be_\bd_\b__\bf_\ba_\bc_\bt_\bo_\br of <.5> would make the output
+                   twice as slow.
 
-SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
+       -V          The -\b-V\bV (version) option causes s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by to print its
+                   version number and exit.
 
+   D\bDa\bat\bte\be a\ban\bnd\bd t\bti\bim\bme\be f\bfo\bor\brm\bma\bat\bt
+       The time and date may be specified multiple ways, common formats
+       include:
 
        HH:MM:SS am MM/DD/CCYY timezone
                24 hour time may be used in place of am/pm.
@@ -181,26 +191,24 @@ SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
        10:01 am 9/17/2009
                10:01 am, September 17, 2009.
 
-       10:01 am
-               10:01 am on the current day.
-
-       10      10:00 am on the current day.
 
-       9/17/2009
-               00:00 am, September 17, 2009.
 
+1.7.2                    October  6, 2009                       3
 
 
 
 
-1.7.2                   September 19, 2009                      3
-
 
+SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
 
 
+       10:01 am
+               10:01 am on the current day.
 
-SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
+       10      10:00 am on the current day.
 
+       9/17/2009
+               00:00 am, September 17, 2009.
 
        10:01 am Sep 17, 2009
                10:01 am, September 17, 2009.
@@ -249,6 +257,17 @@ S\bSU\bUP\bPP\bPO\bOR\bRT\bT
        http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
        the archives.
 
+
+
+1.7.2                    October  6, 2009                       4
+
+
+
+
+
+SUDOREPLAY(1m)         MAINTENANCE COMMANDS        SUDOREPLAY(1m)
+
+
 D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
        s\bsu\bud\bdo\bor\bre\bep\bpl\bla\bay\by is provided ``AS IS'' and any express or implied warranties,
        including, but not limited to, the implied warranties of
@@ -259,6 +278,53 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
 
 
 
-1.7.2                   September 19, 2009                      4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1.7.2                    October  6, 2009                       5
 
 
index 6f49ff001f0ef07cefd14aa054b0dc4bc73d2fb2..6ff18363dbbb699869365b9018e1c1b8b591708a 100644 (file)
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\" 
 .\" $Sudo$
-.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
+.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07)
 .\"
 .\" Standard preamble:
 .\" ========================================================================
-.de Sh \" Subsection heading
-.br
-.if t .Sp
-.ne 5
-.PP
-\fB\\$1\fR
-.PP
-..
 .de Sp \" Vertical space (when we can't use .PP)
 .if t .sp .5v
 .if n .sp
@@ -69,7 +61,7 @@
 .el       .ds Aq '
 .\"
 .\" If the F register is turned on, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
 .\" entries marked with X<> in POD.  Of course, you'll have to process the
 .\" output yourself in some meaningful fashion.
 .ie \nF \{\
 .\" ========================================================================
 .\"
 .IX Title "SUDOREPLAY @mansectsu@"
-.TH SUDOREPLAY @mansectsu@ "September 19, 2009" "1.7.2" "MAINTENANCE COMMANDS"
+.TH SUDOREPLAY @mansectsu@ "October  6, 2009" "1.7.2" "MAINTENANCE COMMANDS"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -172,6 +164,16 @@ session logging enabled.
 .PP
 In list mode, \fBsudoreplay\fR can be used to find the \s-1ID\s0 of a session
 based on a number of criteria such as the user, tty or command run.
+.PP
+In replay mode, if the standard output has not been redirected,
+\&\fBsudoreplay\fR will act on the following keys:
+.IP "' ' (space)" 8
+.IX Item "' ' (space)"
+Pause output; press any key to resume.
+.IP "'<'" 8
+Reduce the playback speed by one half.
+.IP "'>'" 8
+Double the playback speed.
 .SH "OPTIONS"
 .IX Header "OPTIONS"
 \&\fBsudoreplay\fR accepts the following command line options:
@@ -255,7 +257,7 @@ a \fIspeed_factor\fR of <.5> would make the output twice as slow.
 .IX Item "-V"
 The \fB\-V\fR (version) option causes \fBsudoreplay\fR to print its version number
 and exit.
-.Sh "Date and time format"
+.SS "Date and time format"
 .IX Subsection "Date and time format"
 The time and date may be specified multiple ways, common formats include:
 .IP "\s-1HH:MM:SS\s0 am \s-1MM/DD/CCYY\s0 timezone" 8
index 46f9d0921f45d5790d01b832dff98a385e7aa674..42c12187b28433363331802c832ef7a02e054628 100644 (file)
@@ -39,6 +39,25 @@ session logging enabled.
 In list mode, B<sudoreplay> can be used to find the ID of a session
 based on a number of criteria such as the user, tty or command run.
 
+In replay mode, if the standard output has not been redirected,
+B<sudoreplay> will act on the following keys:
+
+=over 8
+
+=item ' ' (space)
+
+Pause output; press any key to resume.
+
+=item '<'
+
+Reduce the playback speed by one half.
+
+=item '>'
+
+Double the playback speed.
+
+=back
+
 =head1 OPTIONS
 
 B<sudoreplay> accepts the following command line options: