From c534413c6ada5778ccbb76f36bdcff672037d0cc Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Wed, 18 Jul 2001 12:54:06 +0000 Subject: [PATCH] Added -F script option to restore. --- CHANGES | 8 +++- TODO | 8 ++-- compat/include/system.h | 49 +++++++++++++++++++++ compat/lib/Makefile.in | 6 +-- compat/lib/system.c | 97 +++++++++++++++++++++++++++++++++++++++++ dump/dump.8.in | 4 +- dump/tape.c | 46 +------------------ restore/main.c | 21 +++++---- restore/restore.8.in | 23 +++++++++- restore/restore.h | 3 +- restore/tape.c | 25 +++++++++-- 11 files changed, 221 insertions(+), 69 deletions(-) create mode 100644 compat/include/system.h create mode 100644 compat/lib/system.c diff --git a/CHANGES b/CHANGES index 2565dec..3740d56 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.121 2001/07/18 11:46:31 stelian Exp $ +$Id: CHANGES,v 1.122 2001/07/18 12:54:06 stelian Exp $ Changes between versions 0.4b22 and 0.4b23 (released ????????????) ================================================================== @@ -29,6 +29,12 @@ Changes between versions 0.4b22 and 0.4b23 (released ????????????) 7. Fixed a bug in reading the operator typed file/tape path for the next volume in restore. +8. Implemented a "-F script" option to restore which permits the + user to specify a script which will be launched at the + beginning of each tape, useful for automatic programming of + tape changers for example. See the restore man page for the + script parameters and return codes. + Changes between versions 0.4b21 and 0.4b22 (released May 12, 2001) ================================================================== diff --git a/TODO b/TODO index d98b59f..11347c1 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.19 2001/05/10 20:55:09 stelian Exp $ +$Id: TODO,v 1.20 2001/07/18 12:54:06 stelian Exp $ Need to verify: --------------- @@ -50,12 +50,10 @@ All others: 10. Better readline completition in restore (escape spaces etc). -11. Implement a -F option for restore. - -12. Dump compiled with RedHat's 7.0 gcc seems to hang for some +11. Dump compiled with RedHat's 7.0 gcc seems to hang for some people. When compiled with kgcc all the problems disappear. Will the RedHat's 7.1 gcc resolve this ? -13. Dump uses /dev/tty for reporting some messages. When invoked +12. Dump uses /dev/tty for reporting some messages. When invoked from a script, /dev/tty may not exist. Why not using just stderr ? diff --git a/compat/include/system.h b/compat/include/system.h new file mode 100644 index 0000000..f27c7c3 --- /dev/null +++ b/compat/include/system.h @@ -0,0 +1,49 @@ +/* + * 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 - Alcôve , 2000 + */ + +/*- + * Copyright (c) 1980, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: system.h,v 1.1 2001/07/18 12:54:06 stelian Exp $ + */ + +#ifndef _SYSTEM_H_ +#define _SYSTEM_H_ + +int system_command(const char *command, const char *device, int volnum); + +#endif diff --git a/compat/lib/Makefile.in b/compat/lib/Makefile.in index 42239c9..12d09cb 100644 --- a/compat/lib/Makefile.in +++ b/compat/lib/Makefile.in @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.4 2000/08/20 19:41:24 stelian Exp $ +# $Id: Makefile.in,v 1.5 2001/07/18 12:54:06 stelian Exp $ top_srcdir= @top_srcdir@ srcdir= @srcdir@ @@ -7,8 +7,8 @@ srcdir= @srcdir@ INC= -I$(top_srcdir)/compat/include CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS) -SRCS= compaterr.c fstab.c compatglob.c bylabel.c -OBJS= compaterr.o fstab.o compatglob.o bylabel.o +SRCS= compaterr.c fstab.c compatglob.c bylabel.c system.c +OBJS= compaterr.o fstab.o compatglob.o bylabel.o system.o LIB= libcompat.a all:: $(LIB) diff --git a/compat/lib/system.c b/compat/lib/system.c new file mode 100644 index 0000000..3f94008 --- /dev/null +++ b/compat/lib/system.c @@ -0,0 +1,97 @@ +/* + * 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 - Alcôve , 2000 + */ + +/*- + * Copyright (c) 1980, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static const char rcsid[] = + "$Id: system.c,v 1.1 2001/07/18 12:54:06 stelian Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * 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, const char *device, int volnum) { + int pid, status; + char commandstr[4096]; + + pid = fork(); + if (pid == -1) { + perror(" DUMP: unable to fork"); + return -1; + } + if (pid == 0) { + setuid(getuid()); + setgid(getgid()); +#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("unable to execute shell"); + exit(-1); + } + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + perror("waitpid error"); + return -1; + } + } else { + if (WIFEXITED(status)) + return WEXITSTATUS(status); + else + return -1; + } + } while(1); +} + diff --git a/dump/dump.8.in b/dump/dump.8.in index 21761d5..5a1dc75 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.27 2001/07/18 09:50:48 stelian Exp $ +.\" $Id: dump.8.in,v 1.28 2001/07/18 12:54:06 stelian Exp $ .\" .Dd __DATE__ .Dt DUMP 8 @@ -202,7 +202,7 @@ The script must return 0 if .Nm should continue without asking the user to change the tape, 1 if .Nm -dump should continue but ask the user to change the tape. +should continue but ask the user to change the tape. Any other exit code will cause .Nm to abort. diff --git a/dump/tape.c b/dump/tape.c index 984fe07..5666b39 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.49 2001/07/18 09:50:48 stelian Exp $"; + "$Id: tape.c,v 1.50 2001/07/18 12:54:06 stelian Exp $"; #endif /* not lint */ #include @@ -52,6 +52,7 @@ static const char rcsid[] = #include #include #include +#include #ifdef __STDC__ #include #include @@ -116,7 +117,6 @@ 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 @@ -462,48 +462,6 @@ flushtape(void) timeest(); } -/* - * 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, const char *device, int volnum) { - int pid, status; - char commandstr[4096]; - - pid = fork(); - if (pid == -1) { - perror(" DUMP: unable to fork"); - return -1; - } - if (pid == 0) { - setuid(getuid()); - setgid(getgid()); -#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); - } - 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) { diff --git a/restore/main.c b/restore/main.c index 2a261f6..5892252 100644 --- a/restore/main.c +++ b/restore/main.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.24 2001/04/27 15:22:47 stelian Exp $"; + "$Id: main.c,v 1.25 2001/07/18 12:54:06 stelian Exp $"; #endif /* not lint */ #include @@ -99,6 +99,7 @@ int compare_ignore_not_found; int compare_errors; char filesys[NAMELEN]; static const char *stdin_opt = NULL; +char *bot_script = NULL; #ifdef __linux__ char *__progname; @@ -145,7 +146,7 @@ main(int argc, char *argv[]) ; obsolete(&argc, &argv); while ((ch = getopt(argc, argv, - "b:CcdD:f:hi" + "b:CcdD:f:F:hi" #ifdef KERBEROS "k" #endif @@ -182,6 +183,9 @@ main(int argc, char *argv[]) use_stdin("-f"); inputdev = optarg; break; + case 'F': + bot_script = optarg; + break; case 'h': hflag = 0; break; @@ -501,12 +505,12 @@ usage(void) (void)fprintf(stderr, "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n", - __progname, " -C [-c" kerbflag "Mvy] [-b blocksize] [-D filesystem] [-f file] [-s fileno]", - __progname, " -i [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] " qfaflag "[-s fileno]", - __progname, " -r [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]", - __progname, " -R [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]", - __progname, " -t [-ch" kerbflag "Muvy] [-b blocksize] [-f file] " qfaflag "[-s fileno] [-X filelist] [file ...]", - __progname, " -x [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] " qfaflag "[-s fileno] [-X filelist] [file ...]"); + __progname, " -C [-c" kerbflag "Mvy] [-b blocksize] [-D filesystem] [-f file] [-F script ] [-s fileno]", + __progname, " -i [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-F script] " qfaflag "[-s fileno]", + __progname, " -r [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory]", + __progname, " -R [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory]", + __progname, " -t [-ch" kerbflag "Muvy] [-b blocksize] [-f file] [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]", + __progname, " -x [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]"); exit(1); } @@ -543,6 +547,7 @@ obsolete(int *argcp, char **argvp[]) case 'b': case 'D': case 'f': + case 'F': case 'Q': case 's': case 'T': diff --git a/restore/restore.8.in b/restore/restore.8.in index 0c20859..7faa54a 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.14 2001/04/24 15:04:59 stelian Exp $ +.\" $Id: restore.8.in,v 1.15 2001/07/18 12:54:06 stelian Exp $ .\" .Dd __DATE__ .Dt RESTORE 8 @@ -44,6 +44,7 @@ .Op Fl b Ar blocksize .Op Fl D Ar filesystem .Op Fl f Ar file +.Op Fl F Ar script .Op Fl s Ar fileno .Op Fl T Ar directory .Nm restore @@ -51,6 +52,7 @@ .Op Fl chkmMNuvy .Op Fl b Ar blocksize .Op Fl f Ar file +.Op Fl F Ar script .Op Fl Q Ar file .Op Fl s Ar fileno .Op Fl T Ar directory @@ -59,6 +61,7 @@ .Op Fl ckMNuvy .Op Fl b Ar blocksize .Op Fl f Ar file +.Op Fl F Ar script .Op Fl s Ar fileno .Op Fl T Ar directory .Nm restore @@ -66,6 +69,7 @@ .Op Fl ckMNuvy .Op Fl b Ar blocksize .Op Fl f Ar file +.Op Fl F Ar script .Op Fl s Ar fileno .Op Fl T Ar directory .Nm restore @@ -73,6 +77,7 @@ .Op Fl chkMNuvy .Op Fl b Ar blocksize .Op Fl f Ar file +.Op Fl F Ar script .Op Fl Q Ar file .Op Fl s Ar fileno .Op Fl T Ar directory @@ -83,6 +88,7 @@ .Op Fl chkmMNuvy .Op Fl b Ar blocksize .Op Fl f Ar file +.Op Fl F Ar script .Op Fl Q Ar file .Op Fl s Ar fileno .Op Fl T Ar directory @@ -336,6 +342,21 @@ or reads from the named file on the remote host using .Xr rmt 8 . .Pp +.It Fl F Ar script +Run script at the beginning of each tape. The device name and the +current volume number are passed on the command line. +The script must return 0 if +.Nm +should continue without asking the user to change the tape, 1 if +.Nm +should continue but ask the user to change the tape. +Any other exit code will cause +.Nm +to abort. +For security reasons, +.Nm +reverts back to the real user ID and the real group ID before +running the script. .It Fl k Use Kerberos authentication when contacting the remote tape server. (Only available if this options was enabled when diff --git a/restore/restore.h b/restore/restore.h index dba1ddc..0ae65ba 100644 --- a/restore/restore.h +++ b/restore/restore.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - Alcôve , 2000 * - * $Id: restore.h,v 1.15 2001/04/10 12:46:53 stelian Exp $ + * $Id: restore.h,v 1.16 2001/07/18 12:54:06 stelian Exp $ */ /* @@ -62,6 +62,7 @@ extern int uflag; /* unlink symlink targets */ extern int vflag; /* print out actions taken */ extern int yflag; /* always try to recover from tape errors */ extern int zflag; /* tape is in compressed format */ +extern char* bot_script; /* beginning of tape script */ /* * Global variables */ diff --git a/restore/tape.c b/restore/tape.c index f7a8a10..a8616a1 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -46,13 +46,14 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.41 2001/07/18 11:46:31 stelian Exp $"; + "$Id: tape.c,v 1.42 2001/07/18 12:54:06 stelian Exp $"; #endif /* not lint */ #include #include #include #include +#include #include #include #include @@ -257,10 +258,18 @@ newcomprbuf(int size) void setup(void) { - int i, j, *ip; + int i, j, *ip, bot_code; struct STAT stbuf; Vprintf(stdout, "Verify tape and initialize maps\n"); + if (bot_script) { + msg("Launching %s\n", bot_script); + bot_code = system_command(bot_script, magtape, 1); + if (bot_code != 0 && bot_code != 1) { + msg("Restore aborted by the beginning of tape script\n"); + exit(1); + } + } #ifdef RRESTORE if (host) mt = rmtopen(magtape, 0); @@ -374,7 +383,7 @@ getvol(long nextvol) union u_spcl tmpspcl; # define tmpbuf tmpspcl.s_spcl char buf[TP_BSIZE]; - int haderror = 0; + int haderror = 0, bot_code; if (nextvol == 1) { tapesread = 0; @@ -438,7 +447,15 @@ again: snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol); magtape[MAXPATHLEN - 1] = '\0'; } - if (!Mflag || haderror) { + if (bot_script && !haderror) { + msg("Launching %s\n", bot_script); + bot_code = system_command(bot_script, magtape, newvol); + if (bot_code != 0 && bot_code != 1) { + msg("Restore aborted by the beginning of tape script\n"); + exit(1); + } + } + if (haderror || (bot_code && !Mflag)) { haderror = 0; fprintf(stderr, "Mount tape volume %ld\n", (long)newvol); fprintf(stderr, "Enter ``none'' if there are no more tapes\n"); -- 2.39.5