From owner-freebsd-current@FreeBSD.ORG Wed Feb 4 00:24:38 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3CBCF16A4CE for ; Wed, 4 Feb 2004 00:24:38 -0800 (PST) Received: from smtp1.powertech.no (smtp1.powertech.no [195.159.0.145]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2DE6A43D1F for ; Wed, 4 Feb 2004 00:24:33 -0800 (PST) (envelope-from frode@nordahl.net) Received: from [195.159.6.12] (dhcp12.ns5.powertech.no [195.159.6.12]) by smtp1.powertech.no (Postfix) with ESMTP id C42F88429; Wed, 4 Feb 2004 09:24:31 +0100 (CET) In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v612) Content-Type: multipart/mixed; boundary=Apple-Mail-5-939108050 Message-Id: <8EDE1BA7-56EB-11D8-83F2-000A95A9A574@nordahl.net> From: Frode Nordahl Date: Wed, 4 Feb 2004 09:24:32 +0100 To: Wang Lam X-Mailer: Apple Mail (2.612) cc: current@freebsd.org Subject: Re: patch: teaching dump(8) to change tapes X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Feb 2004 08:24:38 -0000 --Apple-Mail-5-939108050 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On Feb 4, 2004, at 03:26, Wang Lam wrote: > I was just skimming the patch (and probably missed something since I'm > not > familiar with dump's source code), and had a question: Does the line > > +char *script; /* name of the script for changing tapes */ > > need to say > > +char *script=NULL; /* name of the script for changing tapes */ > hmm, you're right. I originally defined it with initialization in main.c, but moved it to dump.h. Moved it back to main now and defined is as extern in tape.c, new patch included. Thank you for your feedback! > Wang Lam Mvh, Frode --Apple-Mail-5-939108050 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="dump.patch" Content-Disposition: attachment; filename=dump.patch diff -ru /usr/src/sbin/dump/main.c dump/main.c --- /usr/src/sbin/dump/main.c Sun Nov 16 09:01:58 2003 +++ dump/main.c Wed Feb 4 09:20:48 2004 @@ -85,6 +85,7 @@ long dev_bsize = 1; /* recalculated below */ long blocksperfile; /* output blocks per file */ char *host = NULL; /* remote host (if any) */ +char *script = NULL; /* name of the script for changing tapes */ /* * Possible superblock locations ordered from most to least likely. @@ -127,7 +128,7 @@ obsolete(&argc, &argv); while ((ch = getopt(argc, argv, - "0123456789aB:b:C:cD:d:f:h:LnSs:T:uWw")) != -1) + "0123456789aB:b:C:cD:d:f:F:h:LnSs:T:uWw")) != -1) switch (ch) { /* dump level */ case '0': case '1': case '2': case '3': case '4': @@ -171,6 +172,10 @@ tape = optarg; break; + case 'F': /* changer script */ + script = optarg; + break; + case 'h': honorlevel = numarg("honor level", 0L, 10L); break; @@ -559,8 +564,8 @@ { fprintf(stderr, "usage: dump [-0123456789acLnSu] [-B records] [-b blocksize] [-C cachesize]\n" - " [-D dumpdates] [-d density] [-f file] [-h level] [-s feet]\n" - " [-T date] filesystem\n" + " [-D dumpdates] [-d density] [-f file] [-F script] [-h level]\n" + " [-s feet] [-T date] filesystem\n" " dump -W | -w\n"); exit(X_STARTUP); } diff -ru /usr/src/sbin/dump/tape.c dump/tape.c --- /usr/src/sbin/dump/tape.c Wed Sep 25 06:06:35 2002 +++ dump/tape.c Wed Feb 4 09:16:54 2004 @@ -70,6 +70,7 @@ extern int ntrec; /* blocking factor on tape */ extern int cartridge; extern char *host; +extern char *script; char *nexttape; static int atomic(ssize_t (*)(), int, char *, int); @@ -118,6 +119,41 @@ static jmp_buf jmpbuf; /* where to jump to if we are ready when the */ /* SIGUSR2 arrives from the previous slave */ + +int +runscript(void) +{ + char *cmd; + size_t cmd_len; + int rc; + + if (script != NULL) { + cmd_len = strlen(script) + strlen(disk) + 10; + if ((cmd = (char*) malloc(sizeof(char)*cmd_len)) == NULL) { + perror(" DUMP: could not allocate memory for command buffer."); + return(1); + } + + snprintf(cmd, cmd_len, "%s %s %d", script, disk, tapeno); + rc = system(cmd); + + if (rc == -1) { + perror(" DUMP: execution of script failed"); + return(1); + } else if (rc == (127 << 8)) { + msg("Change Volumes: execution of shell failed while running changer script"); + return(1); + } else { + msg("Change Volumes: changer script failed with return code %d\n", (rc >> 8)); + return(1); + } + + return(0); + } + + return(1); +} + int alloctape(void) { @@ -368,15 +404,17 @@ if (nexttape) return; (void)time((time_t *)&(tstart_changevol)); - if (!nogripe) { - msg("Change Volumes: Mount volume #%d\n", tapeno+1); - broadcast("CHANGE DUMP VOLUMES!\a\a\n"); - } - while (!query("Is the new volume mounted and ready to go?")) - if (query("Do you want to abort?")) { - dumpabort(0); - /*NOTREACHED*/ + if (runscript()) { + if (!nogripe) { + msg("Change Volumes: Mount volume #%d\n", tapeno+1); + broadcast("CHANGE DUMP VOLUMES!\a\a\n"); } + while (!query("Is the new volume mounted and ready to go?")) + if (query("Do you want to abort?")) { + dumpabort(0); + /*NOTREACHED*/ + } + } (void)time((time_t *)&(tend_changevol)); if ((tstart_changevol != (time_t)-1) && (tend_changevol != (time_t)-1)) tstart_writing += (tend_changevol - tstart_changevol); --Apple-Mail-5-939108050 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed --Apple-Mail-5-939108050--