From 0d7af9c5f2cc7d4a97e934692ea8665e09fd5500 Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Thu, 2 Mar 2000 11:34:51 +0000 Subject: [PATCH] Added '-F script' option to dump. Fixed the compare option of restore (filesys changed in 0.4b14) Fixed the treatment for old BSD syntax options. --- CHANGES | 13 ++++++- TODO | 5 +-- dump/dump.8.in | 12 ++++++- dump/dump.h | 5 +-- dump/main.c | 19 +++++++--- dump/tape.c | 88 +++++++++++++++++++++++++++++++++++++---------- restore/main.c | 11 +++--- restore/restore.h | 5 +-- restore/tape.c | 15 ++++++-- 9 files changed, 132 insertions(+), 41 deletions(-) diff --git a/CHANGES b/CHANGES index e4fdabf..c667180 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.45 2000/03/01 10:16:05 stelian Exp $ +$Id: CHANGES,v 1.46 2000/03/02 11:34:51 stelian Exp $ Changes between versions 0.4b14 and 0.4b15 (released ?????????????????) ======================================================================= @@ -12,6 +12,17 @@ Changes between versions 0.4b14 and 0.4b15 (released ?????????????????) reporting this on Bugtraq (and to several dump users who forwarded me his mail). +3. Added the '-F script' option to dump in order to + launch a script at the end of each tape (to be used + with a tape changer, or to notify the sysadmin by + pager etc.). + +4. Fixed a bug in restore compare code caused by the changes + I made in 0.4b14. + +5. Fixed the treatment of options using the old BSD syntax + in both dump and restore. + Changes between versions 0.4b13 and 0.4b14 (released February 10, 2000) ======================================================================= diff --git a/TODO b/TODO index 20fb483..679f724 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.11 2000/02/10 10:22:04 stelian Exp $ +$Id: TODO,v 1.12 2000/03/02 11:34:51 stelian Exp $ Need to verify: --------------- @@ -42,6 +42,3 @@ All others: the specified archive_file to be used by ufsrestore(1M) to determine whether a file is in the dump file that is being restored. - -9. Add a '--new-volume-script' option to dump (and restore), - such as found in tar. diff --git a/dump/dump.8.in b/dump/dump.8.in index 469ff1b..9085f1a 100644 --- a/dump/dump.8.in +++ b/dump/dump.8.in @@ -30,7 +30,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: dump.8.in,v 1.11 2000/02/04 20:22:21 stelian Exp $ +.\" $Id: dump.8.in,v 1.12 2000/03/02 11:34:51 stelian Exp $ .\" .Dd __DATE__ .Dt DUMP 8 @@ -44,7 +44,9 @@ .Op Fl B Ar records .Op Fl b Ar blocksize .Op Fl d Ar density +.Op Fl e Ar inode number .Op Fl f Ar file +.Op Fl F Ar script .Op Fl h Ar level .Op Fl L Ar label .Op Fl s Ar feet @@ -55,7 +57,9 @@ .Op Fl B Ar records .Op Fl b Ar blocksize .Op Fl d Ar density +.Op Fl e Ar inode number .Op Fl f Ar file +.Op Fl F Ar script .Op Fl h Ar level .Op Fl L Ar label .Op Fl s Ar feet @@ -190,6 +194,12 @@ program is .Pa /etc/rmt ; this can be overridden by the environment variable .Ev RMT . +.It Fl F Ar script +Run script at the end of each tape. The script must return 0 +if the dump should continue without asking the user to change +the tape, 1 if the dump should continue but ask the user +to change the tape. Any other exit code will cause dump to +abort. .It Fl k Use Kerberos authentication to talk to remote tape servers. (Only available if this option was enabled when diff --git a/dump/dump.h b/dump/dump.h index 37b3c8b..3eea35a 100644 --- a/dump/dump.h +++ b/dump/dump.h @@ -4,7 +4,7 @@ * Remy Card , 1994-1997 * Stelian Pop , 1999-2000 * - * $Id: dump.h,v 1.12 2000/03/01 10:16:05 stelian Exp $ + * $Id: dump.h,v 1.13 2000/03/02 11:34:51 stelian Exp $ */ /*- @@ -71,6 +71,7 @@ char lastlevel; /* dump level of previous dump */ char level; /* dump level of this dump */ int uflag; /* update flag */ int Mflag; /* multi-volume flag */ +char *eot_script; /* end of volume script fiag */ int diskfd; /* disk file descriptor */ int tapefd; /* tape file descriptor */ int pipeout; /* true => output to standard output */ @@ -143,7 +144,7 @@ int alloctape __P((void)); void close_rewind __P((void)); void dumpblock __P((daddr_t blkno, int size)); void startnewtape __P((int top)); -void trewind __P((void)); +time_t trewind __P((void)); void writerec __P((const void *dp, int isspcl)); void Exit __P((int status)); diff --git a/dump/main.c b/dump/main.c index 553a1e6..277e422 100644 --- a/dump/main.c +++ b/dump/main.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.17 2000/03/01 10:16:05 stelian Exp $"; + "$Id: main.c,v 1.18 2000/03/02 11:34:51 stelian Exp $"; #endif /* not lint */ #include @@ -141,6 +141,7 @@ main(int argc, char *argv[]) #endif tsize = 0; /* Default later, based on 'c' option for cart tapes */ + eot_script = NULL; if ((tapeprefix = getenv("TAPE")) == NULL) tapeprefix = _PATH_DEFTAPE; dumpdates = _PATH_DUMPDATES; @@ -154,9 +155,9 @@ main(int argc, char *argv[]) obsolete(&argc, &argv); #ifdef KERBEROS -#define optstring "0123456789aB:b:cd:e:f:h:kL:Mns:ST:uWw" +#define optstring "0123456789aB:b:cd:e:f:F:h:kL:Mns:ST:uWw" #else -#define optstring "0123456789aB:b:cd:e:f:h:L:Mns:ST:uWw" +#define optstring "0123456789aB:b:cd:e:f:F:h:L:Mns:ST:uWw" #endif while ((ch = getopt(argc, argv, optstring)) != -1) #undef optstring @@ -209,6 +210,10 @@ main(int argc, char *argv[]) tapeprefix = optarg; break; + case 'F': /* end of tape script */ + eot_script = optarg; + break; + case 'h': honorlevel = numarg("honor level", 0L, 10L); break; @@ -655,6 +660,9 @@ main(int argc, char *argv[]) spcl.c_type = TS_END; for (i = 0; i < ntrec; i++) writeheader(maxino - 1); + + tnow = trewind(); + if (pipeout) msg("DUMP: %ld tape blocks\n", spcl.c_tapea); else @@ -669,7 +677,6 @@ main(int argc, char *argv[]) tend_writing - tstart_writing, spcl.c_tapea / (tend_writing - tstart_writing)); - tnow = do_stats(); putdumptime(); #ifdef __linux__ msg("DUMP: Date of this level %c dump: %s", level, @@ -682,7 +689,6 @@ main(int argc, char *argv[]) msg("DUMP: Average transfer rate: %ld KB/s\n", xferrate / tapeno); - trewind(); broadcast("DUMP IS DONE!\7\7\n"); msg("DUMP IS DONE\n"); Exit(X_FINOK); @@ -812,8 +818,11 @@ obsolete(int *argcp, char **argvp[]) case 'B': case 'b': case 'd': + case 'e': case 'f': + case 'F': case 'h': + case 'L': case 's': case 'T': if (*argv == NULL) { diff --git a/dump/tape.c b/dump/tape.c index 5a50ff9..3477949 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.14 2000/03/01 10:16:05 stelian Exp $"; + "$Id: tape.c,v 1.15 2000/03/02 11:34:51 stelian Exp $"; #endif /* not lint */ #ifdef __linux__ @@ -73,6 +73,7 @@ static const char rcsid[] = #include #include #include +#include #ifdef __STDC__ #include #include @@ -97,6 +98,7 @@ extern int cartridge; extern char *host; char *nexttape; extern pid_t rshpid; +int eot_code = 1; static ssize_t atomic_read __P((int, void *, size_t)); static ssize_t atomic_write __P((int, const void *, size_t)); @@ -402,7 +404,42 @@ flushtape(void) timeest(); } -void +/* + * Executes the command in a shell. + * Returns -1 if an error occured, the exit status of + * the command on success. + */ +int system_command(const char *command) { + int pid, status; + + pid = fork(); + if (pid == -1) { + perror(" DUMP: unable to fork"); + return -1; + } + if (pid == 0) { + setuid(getuid()); + setgid(getgid()); + execl("/bin/sh", "sh", "-c", command, NULL); + perror(" DUMP: unable to execute shell"); + exit(-1); + } + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + perror(" DUMP: waitpid error"); + return -1; + } + } else { + if (WIFEXITED(status)) + return WEXITSTATUS(status); + else + return -1; + } + } while(1); +} + +time_t trewind(void) { int f; @@ -435,32 +472,45 @@ trewind(void) while (wait((int *)NULL) >= 0) /* wait for any signals from slaves */ /* void */; - if (pipeout) - return; + if (!pipeout) { - msg("Closing %s\n", tape); + msg("Closing %s\n", tape); #ifdef RDUMP - if (host) { - rmtclose(); - while (rmtopen(tape, 0) < 0) - sleep(10); - rmtclose(); - return; - } + if (host) { + rmtclose(); + while (rmtopen(tape, 0) < 0) + sleep(10); + rmtclose(); + } + else +#else + { + (void) close(tapefd); + while ((f = open(tape, 0)) < 0) + sleep (10); + (void) close(f); + } #endif - (void) close(tapefd); - while ((f = open(tape, 0)) < 0) - sleep (10); - (void) close(f); + eot_code = 1; + if (eot_script) { + msg("Launching %s\n", eot_script); + eot_code = system_command(eot_script); + } + if (eot_code != 0 && eot_code != 1) { + msg("Dump aborted by the end of tape script\n"); + dumpabort(0); + } + } + return do_stats(); } + void close_rewind(void) { - trewind(); - (void)do_stats(); - if (nexttape || Mflag) + (void)trewind(); + if (nexttape || Mflag || (eot_code == 0) ) return; if (!nogripe) { msg("Change Volumes: Mount volume #%d\n", tapeno+1); diff --git a/restore/main.c b/restore/main.c index 36ee2a4..292d0cc 100644 --- a/restore/main.c +++ b/restore/main.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.8 2000/01/21 10:17:41 stelian Exp $"; + "$Id: main.c,v 1.9 2000/03/02 11:34:51 stelian Exp $"; #endif /* not lint */ #include @@ -87,7 +87,7 @@ time_t dumpdate; FILE *terminal; char *tmpdir; int compare_ignore_not_found; -char *filesys = NULL; +char filesys[NAMELEN]; #ifdef __linux__ char *__progname; @@ -107,7 +107,7 @@ main(int argc, char *argv[]) /* Temp files should *not* be readable. We set permissions later. */ (void) umask(077); - + filesys[0] = '\0'; #ifdef __linux__ __progname = argv[0]; #endif @@ -144,7 +144,8 @@ main(int argc, char *argv[]) cvtflag = 1; break; case 'D': - filesys = optarg; + strncpy(filesys, optarg, NAMELEN); + filesys[NAMELEN - 1] = '\0'; break; case 'T': tmpdir = optarg; @@ -402,8 +403,10 @@ obsolete(int *argcp, char **argvp[]) for (flags = 0; *ap; ++ap) { switch (*ap) { case 'b': + case 'D': case 'f': case 's': + case 'T': if (*argv == NULL) { warnx("option requires an argument -- %c", *ap); usage(); diff --git a/restore/restore.h b/restore/restore.h index a3c2b55..44bbca3 100644 --- a/restore/restore.h +++ b/restore/restore.h @@ -4,7 +4,7 @@ * Remy Card , 1994-1997 * Stelian Pop , 1999-2000 * - * $Id: restore.h,v 1.7 2000/01/21 10:17:41 stelian Exp $ + * $Id: restore.h,v 1.8 2000/03/02 11:34:51 stelian Exp $ */ /* @@ -45,6 +45,7 @@ * SUCH DAMAGE. */ +#include /* * Flags */ @@ -78,7 +79,7 @@ extern int compare_ignore_not_found; /* used to compare incremental dumps, */ /* so messages about "not found" files */ /* isn't seen. */ -extern char *filesys; /* name of dumped filesystem */ +extern char filesys[NAMELEN];/* name of dumped filesystem */ /* * Each file in the file system is described by one of these entries diff --git a/restore/tape.c b/restore/tape.c index 0489574..4bce13d 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -45,7 +45,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.12 2000/03/01 10:16:05 stelian Exp $"; + "$Id: tape.c,v 1.13 2000/03/02 11:34:51 stelian Exp $"; #endif /* not lint */ #include @@ -239,8 +239,17 @@ setup(void) } if (vflag || command == 't' || command == 'C') printdumpinfo(); - if (filesys == NULL) { - filesys = spcl.c_filesys; + if (filesys[0] == '\0') { + char *dirptr; +printf("spcl.c_filesys = %s\n", spcl.c_filesys); + strncpy(filesys, spcl.c_filesys, NAMELEN); + filesys[NAMELEN - 1] = '\0'; + dirptr = strstr(filesys, " (dir"); +printf("dirptr = %s\n", dirptr); + if (dirptr != NULL) + *dirptr = '\0'; +printf("dirptr = %s\n", dirptr); +printf("filesys = %s\n", filesys); } dumptime = spcl.c_ddate; dumpdate = spcl.c_date; -- 2.39.2