]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: clean up code to genenrate Star/Done messages
authorKarel Zak <kzak@redhat.com>
Mon, 23 Jun 2014 09:41:31 +0000 (11:41 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jun 2014 09:41:31 +0000 (11:41 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/script.c

index 2da75124bbacc451cc6d37c74fe46ae8b217ff81..b9f87384a0a12d1130d2d0811146bf7542c2a7a1 100644 (file)
@@ -421,7 +421,6 @@ my_strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) {
 void
 dooutput(void) {
        ssize_t cc;
-       time_t tvec;
        char obuf[BUFSIZ];
        struct timeval tv;
        double oldtime=time(NULL), newtime;
@@ -435,10 +434,11 @@ dooutput(void) {
        if (tflg && !timingfd)
                timingfd = fdopen(STDERR_FILENO, "w");
 
-       tvec = time((time_t *)NULL);
-       my_strftime(obuf, sizeof obuf, "%c\n", localtime(&tvec));
-       if (!qflg)
+       if (!qflg) {
+               time_t tvec = time((time_t *)NULL);
+               my_strftime(obuf, sizeof obuf, "%c\n", localtime(&tvec));
                fprintf(fscript, _("Script started on %s"), obuf);
+       }
 
        FD_ZERO(&readfds);
 
@@ -575,12 +575,12 @@ done(void) {
        if (subchild) {
                /* output process */
                if (fscript) {
-                       char buf[BUFSIZ];
-                       tvec = time((time_t *)NULL);
-                       my_strftime(buf, sizeof buf, "%c\n", localtime(&tvec));
-                       if (!qflg)
+                       if (!qflg) {
+                               char buf[BUFSIZ];
+                               tvec = time((time_t *)NULL);
+                               my_strftime(buf, sizeof buf, "%c\n", localtime(&tvec));
                                fprintf(fscript, _("\nScript done on %s"), buf);
-
+                       }
                        if (close_stream(fscript) != 0)
                                errx(EXIT_FAILURE, _("write error"));
                        fscript = NULL;