From 3d78f5f2dbe4f24a0c80f286e67ce79e9ef377c4 Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Sun, 28 May 2000 16:51:13 +0000 Subject: [PATCH] Error code to restore when compare errors detected. --- CHANGES | 7 ++++++- restore/main.c | 8 +++++++- restore/restore.8.in | 10 +++++++++- restore/restore.c | 12 +++++++++--- restore/restore.h | 3 ++- restore/tape.c | 15 ++++++++++++++- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index bd89261..275e2d6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.55 2000/05/28 16:24:13 stelian Exp $ +$Id: CHANGES,v 1.56 2000/05/28 16:51:13 stelian Exp $ Changes between versions 0.4b16 and 0.4b17 (released ??????????????) ==================================================================== @@ -11,6 +11,11 @@ Changes between versions 0.4b16 and 0.4b17 (released ??????????????) with libc5. Thanks to Jeff Johnson for the patch. +3. Made the exit code of restore in case of a 'C'ompare + command reflect the result of the compare. An exit status + of 0 means the dump archive is correct, 1 means tape errors, + 2 means that some files were modified. + Changes between versions 0.4b15 and 0.4b16 (released March 11, 2000) ==================================================================== diff --git a/restore/main.c b/restore/main.c index 1cd1a66..344ec5c 100644 --- a/restore/main.c +++ b/restore/main.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.11 2000/03/09 13:12:31 stelian Exp $"; + "$Id: main.c,v 1.12 2000/05/28 16:52:21 stelian Exp $"; #endif /* not lint */ #include @@ -87,6 +87,7 @@ time_t dumpdate; FILE *terminal; char *tmpdir; int compare_ignore_not_found; +int compare_errors; char filesys[NAMELEN]; static const char *stdin_opt = NULL; @@ -250,6 +251,7 @@ main(int argc, char *argv[]) Vprintf(stdout, "Begin compare restore\n"); compare_ignore_not_found = 0; + compare_errors = 0; setup(); printf("filesys = %s\n", filesys); if (stat(filesys, &stbuf) < 0) @@ -262,6 +264,10 @@ main(int argc, char *argv[]) treescan(".", ROOTINO, nodeupdates); compareleaves(); checkrestore(); + if (compare_errors) { + printf("Some files were modified!\n"); + exit(2); + } break; } diff --git a/restore/restore.8.in b/restore/restore.8.in index 89fbf40..3bf87de 100644 --- a/restore/restore.8.in +++ b/restore/restore.8.in @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: restore.8.in,v 1.9 2000/03/09 13:12:31 stelian Exp $ +.\" $Id: restore.8.in,v 1.10 2000/05/28 16:52:21 stelian Exp $ .\" .Dd __DATE__ .Dt RESTORE 8 @@ -481,6 +481,14 @@ After a dump read error, may have to resynchronize itself. This message lists the number of blocks that were skipped over. .El +.Pp +.Nm Restore +exits with zero status on success. +Tape errors are indicated with an exit code of 1. +.Pp +When doing a comparison of files from a dump, an exit code +of 2 indicates that some files were modified or deleted since +the dump was made. .Sh ENVIRONMENT If the following environment variable exists it will be utilized by .Nm restore : diff --git a/restore/restore.c b/restore/restore.c index 2f68c54..c577084 100644 --- a/restore/restore.c +++ b/restore/restore.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: restore.c,v 1.7 2000/01/21 10:17:41 stelian Exp $"; + "$Id: restore.c,v 1.8 2000/05/28 16:52:21 stelian Exp $"; #endif /* not lint */ #include @@ -610,8 +610,10 @@ removeoldnodes(void) static void compare_entry(struct entry *ep, int do_compare) { - if ((ep->e_flags & (NEW|EXTRACT)) == 0) + if ((ep->e_flags & (NEW|EXTRACT)) == 0) { badentry(ep, "unexpected file on tape"); + compare_errors = 1; + } if (do_compare) (void) comparefile(myname(ep)); ep->e_flags &= ~(NEW|EXTRACT); } @@ -642,6 +644,7 @@ compareleaves(void) if (ep == NULL) panic("%d: bad first\n", first); fprintf(stderr, "%s: not found on tape\n", myname(ep)); + compare_errors = 1; ep->e_flags &= ~(NEW|EXTRACT); first = lowerbnd(first); } @@ -655,12 +658,15 @@ compareleaves(void) if (first != curfile.ino) { fprintf(stderr, "expected next file %ld, got %lu\n", (long)first, (unsigned long)curfile.ino); + compare_errors = 1; skipfile(); goto next; } ep = lookupino(curfile.ino); - if (ep == NULL) + if (ep == NULL) { panic("unknown file on tape\n"); + compare_errors = 1; + } compare_entry(ep, 1); for (ep = ep->e_links; ep != NULL; ep = ep->e_links) { compare_entry(ep, 0); diff --git a/restore/restore.h b/restore/restore.h index 44bbca3..480f4d0 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.8 2000/03/02 11:34:51 stelian Exp $ + * $Id: restore.h,v 1.9 2000/05/28 16:52:21 stelian Exp $ */ /* @@ -79,6 +79,7 @@ extern int compare_ignore_not_found; /* used to compare incremental dumps, */ /* so messages about "not found" files */ /* isn't seen. */ +extern int compare_errors; /* did we encounter any compare errors? */ extern char filesys[NAMELEN];/* name of dumped filesystem */ /* diff --git a/restore/tape.c b/restore/tape.c index d393469..1b567bd 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -45,7 +45,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.14 2000/03/03 11:00:55 stelian Exp $"; + "$Id: tape.c,v 1.15 2000/05/28 16:52:21 stelian Exp $"; #endif /* not lint */ #include @@ -918,12 +918,14 @@ cmpfiles(char *tapefile, char *diskfile, struct stat *sbuf_disk) if (stat(tapefile, &sbuf_tape) != 0) { panic("Can't lstat tmp file %s: %s\n", tapefile, strerror(errno)); + compare_errors = 1; } if (sbuf_disk->st_size != sbuf_tape.st_size) { fprintf(stderr, "%s: size changed from %ld to %ld.\n", diskfile, (long)sbuf_tape.st_size, (long)sbuf_disk->st_size); + compare_errors = 1; #ifdef COMPARE_FAIL_KEEP_FILE return (0); #else @@ -933,10 +935,12 @@ cmpfiles(char *tapefile, char *diskfile, struct stat *sbuf_disk) if ((fd_tape = open(tapefile, O_RDONLY)) < 0) { panic("Can't open %s: %s\n", tapefile, strerror(errno)); + compare_errors = 1; } if ((fd_disk = open(diskfile, O_RDONLY)) < 0) { close(fd_tape); panic("Can't open %s: %s\n", diskfile, strerror(errno)); + compare_errors = 1; } if (do_cmpfiles(fd_tape, fd_disk, sbuf_tape.st_size)) { @@ -944,6 +948,7 @@ cmpfiles(char *tapefile, char *diskfile, struct stat *sbuf_disk) diskfile); close(fd_tape); close(fd_disk); + compare_errors = 1; #ifdef COMPARE_FAIL_KEEP_FILE /* rename the file to live in /tmp */ /* rename `tapefile' to /tmp/ */ @@ -990,6 +995,7 @@ comparefile(char *name) if ((r = lstat(name, &sb)) != 0) { warn("%s: does not exist (%d)", name, r); + compare_errors = 1; skipfile(); return; } @@ -1004,6 +1010,7 @@ comparefile(char *name) if (sb.st_mode != mode) { fprintf(stderr, "%s: mode changed from 0%o to 0%o.\n", name, mode & 07777, sb.st_mode & 07777); + compare_errors = 1; } switch (mode & IFMT) { default: @@ -1025,6 +1032,7 @@ comparefile(char *name) if (!(sb.st_mode & S_IFLNK)) { fprintf(stderr, "%s: is no longer a symbolic link\n", name); + compare_errors = 1; return; } lnkbuf[0] = '\0'; @@ -1034,17 +1042,20 @@ comparefile(char *name) fprintf(stderr, "%s: zero length symbolic link (ignored)\n", name); + compare_errors = 1; return; } if ((lsize = readlink(name, lbuf, MAXPATHLEN)) < 0) { panic("readlink of %s failed: %s", name, strerror(errno)); + compare_errors = 1; } lbuf[lsize] = 0; if (strcmp(lbuf, lnkbuf) != 0) { fprintf(stderr, "%s: symbolic link changed from %s to %s.\n", name, lnkbuf, lbuf); + compare_errors = 1; return; } return; @@ -1055,6 +1066,7 @@ comparefile(char *name) if (!(sb.st_mode & (S_IFCHR|S_IFBLK))) { fprintf(stderr, "%s: no longer a special file\n", name); + compare_errors = 1; skipfile(); return; } @@ -1067,6 +1079,7 @@ comparefile(char *name) (int)curfile.dip->di_rdev & 0xff, ((int)sb.st_rdev >> 8) & 0xff, (int)sb.st_rdev & 0xff); + compare_errors = 1; } skipfile(); return; -- 2.39.2