]> git.wh0rd.org - dump.git/commitdiff
Added '-F script' option to dump.
authorStelian Pop <stelian@popies.net>
Thu, 2 Mar 2000 11:34:51 +0000 (11:34 +0000)
committerStelian Pop <stelian@popies.net>
Thu, 2 Mar 2000 11:34:51 +0000 (11:34 +0000)
Fixed the compare option of restore (filesys changed in 0.4b14)
Fixed the treatment for old BSD syntax options.

CHANGES
TODO
dump/dump.8.in
dump/dump.h
dump/main.c
dump/tape.c
restore/main.c
restore/restore.h
restore/tape.c

diff --git a/CHANGES b/CHANGES
index e4fdabfadceb66517f302a7db3499dbd9136a4e5..c6671805f36028d3a1d72f83832f0c2c553495e5 100644 (file)
--- 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 20fb483603fda67c9b1ddb5a0fcb3a4996641252..679f7243116f6730c0d3a7a1d4f15edded09a1e5 100644 (file)
--- 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.
index 469ff1b3b82282e9ee299bf827d25f72d957ff9e..9085f1a11a1be85a7742ca01dbceb862611f728e 100644 (file)
@@ -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
index 37b3c8bcc186d343ec40a4e25513134e5197a59c..3eea35a7b276796aee999bebd22972e7da81d656 100644 (file)
@@ -4,7 +4,7 @@
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
  *     Stelian Pop <pop@cybercable.fr>, 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));
index 553a1e66831f781e0ff628387af11ae68c6c47a0..277e422cc97737a6902ce00c15fe61dc08981221 100644 (file)
@@ -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 <sys/param.h>
@@ -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) {
index 5a50ff95aaf66e814efad447026639090b8814e9..34779491504f6526e0eff171ebc73d0973ce28b1 100644 (file)
@@ -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 <setjmp.h>
 #include <signal.h>
 #include <stdio.h>
+#include <compaterr.h>
 #ifdef __STDC__
 #include <stdlib.h>
 #include <string.h>
@@ -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);
index 36ee2a4eb85123e068b90c11421f5901c2105e32..292d0cc11d35aab429d2d3501f2194f49c1aae0f 100644 (file)
@@ -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 <sys/param.h>
@@ -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();
index a3c2b5566dd02ffe881cda4e597c5ce052103805..44bbca301d2262cc427b0880fcb6deeff3a0a25f 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.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 <protocols/dumprestore.h>
 /*
  * 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
index 0489574a5f9730acf59697b000281a5907deca64..4bce13d97400c9bf9a1ba34e83cbd00c604b87f2 100644 (file)
@@ -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 <sys/param.h>
@@ -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;