X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=dump%2Ftape.c;h=16328bd0a313ca691400985edf414bd888776104;hb=d6967896bc4e18f9b4359a2ef5be5c0f1bcc456a;hp=34779491504f6526e0eff171ebc73d0973ce28b1;hpb=0d7af9c5f2cc7d4a97e934692ea8665e09fd5500;p=dump.git diff --git a/dump/tape.c b/dump/tape.c index 3477949..16328bd 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -2,7 +2,8 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999-2000 + * Stelian Pop , 1999-2000 + * Stelian Pop - AlcĂ´ve , 2000 */ /*- @@ -40,9 +41,10 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.15 2000/03/02 11:34:51 stelian Exp $"; + "$Id: tape.c,v 1.27 2000/12/21 11:14:54 stelian Exp $"; #endif /* not lint */ +#include #ifdef __linux__ #include #include @@ -107,6 +109,7 @@ static void enslave __P((void)); static void flushtape __P((void)); static void killall __P((void)); static void rollforward __P((void)); +static int system_command __P((const char *, const char *, int)); /* * Concurrent dump mods (Caltech) - disk block reading and tape writing @@ -293,36 +296,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 @@ -409,8 +425,9 @@ flushtape(void) * Returns -1 if an error occured, the exit status of * the command on success. */ -int system_command(const char *command) { +int system_command(const char *command, const char *device, int volnum) { int pid, status; + char commandstr[4096]; pid = fork(); if (pid == -1) { @@ -420,7 +437,13 @@ int system_command(const char *command) { if (pid == 0) { setuid(getuid()); setgid(getgid()); - execl("/bin/sh", "sh", "-c", command, NULL); +#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"); exit(-1); } @@ -484,18 +507,17 @@ trewind(void) rmtclose(); } else -#else +#endif { (void) close(tapefd); while ((f = open(tape, 0)) < 0) sleep (10); (void) close(f); } -#endif eot_code = 1; - if (eot_script) { + if (eot_script && spcl.c_type != TS_END) { msg("Launching %s\n", eot_script); - eot_code = system_command(eot_script); + eot_code = system_command(eot_script, tape, tapeno); } if (eot_code != 0 && eot_code != 1) { msg("Dump aborted by the end of tape script\n"); @@ -614,12 +636,13 @@ rollforward(void) } slp->req[0] = *q; nextblock = slp->tblock; - if (q->dblk == 0) + if (q->dblk == 0) { #ifdef __linux__ - *(union u_spcl *)(*(nextblock)++) = *(union u_spcl *)tslp->tblock; -#else - nextblock++; + /* XXX post increment triggers an egcs-1.1.2-12 bug on alpha/sparc */ + *(union u_spcl *)(*nextblock) = *(union u_spcl *)tslp->tblock; #endif + nextblock++; + } trecno = 1; /* @@ -673,17 +696,21 @@ startnewtape(int top) int status; int waitpid; char *p; + #ifdef __linux__ - void (*interrupt_save) __P((int signo)); + sigset_t sigs; + sigemptyset(&sigs); + sigaddset(&sigs, SIGINT); + sigprocmask(SIG_BLOCK, &sigs, NULL); #else /* __linux__ */ #ifdef sunos void (*interrupt_save)(); #else sig_t interrupt_save; #endif + interrupt_save = signal(SIGINT, SIG_IGN); #endif /* __linux__ */ - interrupt_save = signal(SIGINT, SIG_IGN); parentpid = getpid(); tapea_volume = spcl.c_tapea; #ifdef __linux__ @@ -693,7 +720,11 @@ startnewtape(int top) #endif restore_check_point: +#ifdef __linux__ + sigprocmask(SIG_UNBLOCK, &sigs, NULL); +#else (void)signal(SIGINT, interrupt_save); +#endif /* * All signals are inherited... */ @@ -709,7 +740,11 @@ restore_check_point: * until the child doing all of the work returns. * don't catch the interrupt */ +#ifdef __linux__ + sigprocmask(SIG_BLOCK, &sigs, NULL); +#else signal(SIGINT, SIG_IGN); +#endif #ifdef TDEBUG msg("Tape: %d; parent process: %d child process %d\n", tapeno+1, parentpid, childpid); @@ -857,7 +892,6 @@ Exit(int status) static void proceed(int signo) { - if (ready) siglongjmp(jmpbuf, 1); caught++; @@ -875,10 +909,19 @@ enslave(void) master = getpid(); - signal(SIGTERM, dumpabort); /* Slave sends SIGTERM on dumpabort() */ - signal(SIGPIPE, sigpipe); - signal(SIGUSR1, tperror); /* Slave sends SIGUSR1 on tape errors */ - signal(SIGUSR2, proceed); /* Slave sends SIGUSR2 to next slave */ + { 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; + sigaction(SIGPIPE, &sa, NULL); + sa.sa_handler = tperror; + sigaction(SIGUSR1, &sa, NULL); /* Slave sends SIGUSR1 on tape errors */ + sa.sa_handler = proceed; + sa.sa_flags = SA_RESTART; + sigaction(SIGUSR2, &sa, NULL); /* Slave sends SIGUSR2 to next slave */ + } for (i = 0; i < SLAVES; i++) { if (i == slp - &slaves[0]) { @@ -895,12 +938,15 @@ enslave(void) slaves[i].fd = cmd[1]; slaves[i].sent = 0; if (slaves[i].pid == 0) { /* Slave starts up here */ + sigset_t sigs; for (j = 0; j <= i; j++) (void) close(slaves[j].fd); - signal(SIGINT, SIG_IGN); /* Master handles this */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGINT); /* Master handles this */ #if defined(SIGINFO) - signal(SIGINFO, SIG_IGN); + sigaddset(&sigs, SIGINFO); #endif + sigprocmask(SIG_BLOCK, &sigs, NULL); #ifdef LINUX_FORK_BUG if (atomic_write( cmd[0], (char *) &i, sizeof i) @@ -1000,7 +1046,7 @@ doslave(int cmd, int slave_number) quit("master/slave protocol botched.\n"); } } - if (setjmp(jmpbuf) == 0) { + if (sigsetjmp(jmpbuf, 1) == 0) { ready = 1; if (!caught) (void) pause(); @@ -1052,6 +1098,7 @@ doslave(int cmd, int slave_number) if (wrote < 0) { (void) kill(master, SIGUSR1); sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); for (;;) sigsuspend(&sigset); } else {