]> git.wh0rd.org - dump.git/blobdiff - dump/tape.c
Added the throughput information in dump's progression messages.
[dump.git] / dump / tape.c
index 69715003e67bf772103bfad8d0b5d996a64c03ec..c3628ccc0b4a83d31d26d24e7e0bcc72d63021dc 100644 (file)
@@ -2,7 +2,8 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *     Stelian Pop <pop@cybercable.fr>, 1999-2000
+ *     Stelian Pop <pop@noos.fr>, 1999-2000
+ *     Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
  */
 
 /*-
@@ -40,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.19 2000/05/28 16:24:14 stelian Exp $";
+       "$Id: tape.c,v 1.26 2000/12/05 16:31:36 stelian Exp $";
 #endif /* not lint */
 
 #ifdef __linux__
@@ -294,36 +295,49 @@ do_stats(void)
        return(tnow);
 }
 
+char *
+mktimeest(time_t tnow)
+{
+       static char msgbuf[128];
+       time_t deltat;
+
+       msgbuf[0] = '\0';
+
+       if (blockswritten < 500)
+               return NULL;
+       if (blockswritten > tapesize)
+               tapesize = blockswritten;
+       deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
+               / blockswritten * tapesize;
+       (void)snprintf(msgbuf, sizeof(msgbuf),
+               "%3.2f%% done at %ld KB/s, finished in %d:%02d\n",
+               (blockswritten * 100.0) / tapesize,
+               (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume),
+               (int)(deltat / 3600), (int)((deltat % 3600) / 60));
+
+       return msgbuf;
+}
+
 #if defined(SIGINFO)
 /*
  * statussig --
  *     information message upon receipt of SIGINFO
- *     (derived from optr.c::timeest())
  */
 void
 statussig(int notused)
 {
-       time_t  tnow, deltat;
-       char    msgbuf[128];
+       time_t tnow;
        int save_errno = errno;
+       char *buf;
 
-       if (blockswritten < 500)
-               return;
 #ifdef __linux__
        (void) time4(&tnow);
 #else
        (void) time((time_t *) &tnow);
 #endif
-       if (blockswritten > tapesize)
-               tapesize = blockswritten;
-       deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
-               / blockswritten * tapesize;
-       (void)snprintf(msgbuf, sizeof(msgbuf),
-               "%3.2f%% done at %ld KB/s, finished in %d:%02d\n",
-               (blockswritten * 100.0) / tapesize,
-               (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume),
-               (int)(deltat / 3600), (int)((deltat % 3600) / 60));
-       write(STDERR_FILENO, msgbuf, strlen(msgbuf));
+       buf = mktimeest(tnow);
+       if (buf)
+               write(STDERR_FILENO, buf, strlen(buf));
        errno = save_errno;
 }
 #endif
@@ -422,7 +436,11 @@ int system_command(const char *command, const char *device, int volnum) {
        if (pid == 0) {
                setuid(getuid());
                setgid(getgid());
+#if OLD_STYLE_FSCRIPT
+               snprintf(commandstr, sizeof(commandstr), "%s", command);
+#else
                snprintf(commandstr, sizeof(commandstr), "%s %s %d", command, device, volnum);
+#endif
                commandstr[sizeof(commandstr) - 1] = '\0';
                execl("/bin/sh", "sh", "-c", commandstr, NULL);
                perror("  DUMP: unable to execute shell");
@@ -873,9 +891,9 @@ Exit(int status)
 static void
 proceed(int signo)
 {
-       caught++;
        if (ready)
                siglongjmp(jmpbuf, 1);
+       caught++;
 }
 
 void
@@ -891,6 +909,8 @@ enslave(void)
        master = getpid();
 
     {  struct sigaction sa;
+       memset(&sa, 0, sizeof sa);
+       sigemptyset(&sa.sa_mask);
        sa.sa_handler = dumpabort;
        sigaction(SIGTERM, &sa, NULL); /* Slave sends SIGTERM on dumpabort() */
        sa.sa_handler = sigpipe;
@@ -1077,6 +1097,7 @@ doslave(int cmd, int slave_number)
                if (wrote < 0) {
                        (void) kill(master, SIGUSR1);
                        sigemptyset(&sigset);
+                       sigaddset(&sigset, SIGINT);
                        for (;;)
                                sigsuspend(&sigset);
                } else {