Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Feb 2004 09:24:32 +0100
From:      Frode Nordahl <frode@nordahl.net>
To:        Wang Lam <wlam@cs.stanford.edu>
Cc:        current@freebsd.org
Subject:   Re: patch: teaching dump(8) to change tapes
Message-ID:  <8EDE1BA7-56EB-11D8-83F2-000A95A9A574@nordahl.net>
In-Reply-To: <Pine.GSO.4.44.0402031816180.18472-100000@elaine2.Stanford.EDU>
References:  <Pine.GSO.4.44.0402031816180.18472-100000@elaine2.Stanford.EDU>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8EDE1BA7-56EB-11D8-83F2-000A95A9A574>