]> git.wh0rd.org - dump.git/commitdiff
Error code to restore when compare errors detected.
authorStelian Pop <stelian@popies.net>
Sun, 28 May 2000 16:51:13 +0000 (16:51 +0000)
committerStelian Pop <stelian@popies.net>
Sun, 28 May 2000 16:51:13 +0000 (16:51 +0000)
CHANGES
restore/main.c
restore/restore.8.in
restore/restore.c
restore/restore.h
restore/tape.c

diff --git a/CHANGES b/CHANGES
index bd892616cb962ae6d2bb8ed0eeb348f9de1bbe50..275e2d618727440beb16dfd354f041b92089726e 100644 (file)
--- 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 <jbj@redhat.com> 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)
 ====================================================================
 
index 1cd1a662981ec7b85210053568106c19048176eb..344ec5cacf0567ea5561991e30dbc4473e033a9d 100644 (file)
@@ -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 <sys/param.h>
@@ -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;
        }
 
index 89fbf401649b46cd762c743ff30a746c536bece7..3bf87deb24e10c0b0f8caa29c2c04e4d61bb74d5 100644 (file)
@@ -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 :
index 2f68c541d04232493c74362629d17fed83118685..c5770849b4eaf01c85806fe6892914c91837429f 100644 (file)
@@ -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 <sys/types.h>
@@ -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);
index 44bbca301d2262cc427b0880fcb6deeff3a0a25f..480f4d028ffdc068b75dd566949f7dd393322316 100644 (file)
@@ -4,7 +4,7 @@
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
  *     Stelian Pop <pop@cybercable.fr>, 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 */
 
 /*
index d393469355c703b0afc4a22e23bfae384350b503..1b567bdf9b136cad291d23b9c06f5eb5f9b379d6 100644 (file)
@@ -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 <sys/param.h>
@@ -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/<basename of diskfile> */
@@ -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;