Subject: bin/2557: more fixes to restore(8)
To: None <gnats-bugs@NetBSD.ORG>
From: Luke Mewburn <lukem@supp.cpr.itg.telecom.com.au>
List: netbsd-bugs
Date: 06/18/1996 11:04:38
>Number:         2557
>Category:       bin
>Synopsis:       more fixes to restore(8)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   lm
>Arrival-Date:   Mon Jun 17 21:20:03 1996
>Last-Modified:
>Originator:     Luke Mewburn
>Organization:
Telstra
>Release:        1.2_ALPHA
>Environment:
System: NetBSD shelob 1.2_ALPHA NetBSD 1.2_ALPHA (SHELOB) #8: Fri Jun 14 04:30:50 EST 1996 root@shelob:/z/src/sys/arch/i386/compile/SHELOB i386

>Description:
	in <bin/2544> I submitted a patch to use unique filenames
	for the /tmp/rst* files used by restore, so you could do
	multiple restores at the same time on dumps with the same
	dumpdate (and for that matter, use the same dumpfile)
	Due to an oversight, this broke the 'r' and 'R' (mainly the
	latter) into being useless. Also, I missed a place where
	the tempfilename needed to have the unique string applied.

>How-To-Repeat:
	(as <bin/2544>, but also try the 'r' and 'R' modes)

>Fix:
	apply <bin/2544>, then apply this. it also fixes the man page
	to document that multiple 'r' or 'R' restores shouldn't be run
	on dumps with the same dumpdate

	PS: this patch will be offset by a couple of lines, since my
	version of restore has ifdef's for ULTRIX support that change
	the line numbering...

Index: dirs.c
===================================================================
RCS file: /support/cvsroot/util/bsddump/restore/dirs.c,v
retrieving revision 1.2
diff -c -r1.2 dirs.c
*** dirs.c	1996/06/13 05:24:09	1.2
--- dirs.c	1996/06/17 07:16:38
***************
*** 163,174 ****
  	struct direct nulldir;
  
  	vprintf(stdout, "Extract directories from tape\n");
! 	(void) sprintf(dirfile, "%s/rstdir%d-XXXXXX", _PATH_TMP, dumpdate);
! 	if (mktemp(dirfile) == NULL) {
! 		fprintf(stderr,
! 		    "restore: %s - cannot generate directory temporary\n",
! 		    dirfile);
! 		exit(1);
  	}
  	df = fopen(dirfile, "w");
  	if (df == NULL) {
--- 163,177 ----
  	struct direct nulldir;
  
  	vprintf(stdout, "Extract directories from tape\n");
! 	(void) sprintf(dirfile, "%s/rstdir%d", _PATH_TMP, dumpdate);
! 	if (command != 'r' && command != 'R') {
! 		(void *) strcat(dirfile, "-XXXXXX");
! 		if (mktemp(dirfile) == NULL) {
! 			fprintf(stderr,
! 			    "restore: %s - cannot mktemp directory temporary\n",
! 			    dirfile);
! 			exit(1);
! 		}
  	}
  	df = fopen(dirfile, "w");
  	if (df == NULL) {
***************
*** 179,191 ****
  		exit(1);
  	}
  	if (genmode != 0) {
! 		(void) sprintf(modefile, "%s/rstmode%d-XXXXXX", _PATH_TMP,
! 			       dumpdate);
! 		if (mktemp(modefile) == NULL) {
! 			fprintf(stderr,
! 			    "restore: %s - cannot generate modefile\n",
! 			    modefile);
! 			exit(1);
  		}
  		mf = fopen(modefile, "w");
  		if (mf == NULL) {
--- 182,196 ----
  		exit(1);
  	}
  	if (genmode != 0) {
! 		(void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
! 		if (command != 'r' && command != 'R') {
! 			(void *) strcat(modefile, "-XXXXXX");
! 			if (mktemp(modefile) == NULL) {
! 				fprintf(stderr,
! 				    "restore: %s - cannot mktemp modefile\n",
! 				    modefile);
! 				exit(1);
! 			}
  		}
  		mf = fopen(modefile, "w");
  		if (mf == NULL) {
***************
*** 622,628 ****
  	char *cp;
  	
  	vprintf(stdout, "Set directory mode, owner, and times.\n");
! 	(void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
  	mf = fopen(modefile, "r");
  	if (mf == NULL) {
  		fprintf(stderr, "fopen: %s\n", strerror(errno));
--- 627,639 ----
  	char *cp;
  	
  	vprintf(stdout, "Set directory mode, owner, and times.\n");
! 	if (command == 'r' || command == 'R')
! 		(void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
! 	if (modefile[0] == '#') {
! 		panic("modefile not defined\n");
! 		fprintf(stderr, "directory mode, owner, and times not set\n");
! 		return;
! 	}
  	mf = fopen(modefile, "r");
  	if (mf == NULL) {
  		fprintf(stderr, "fopen: %s\n", strerror(errno));
Index: restore.8
===================================================================
RCS file: /support/cvsroot/util/bsddump/restore/restore.8,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 restore.8
*** restore.8	1996/06/07 05:58:21	1.1.1.1
--- restore.8	1996/06/17 07:33:59
***************
*** 423,428 ****
--- 423,450 ----
  thus a full dump must be done to get a new set of directories
  reflecting the new inode numbering,
  even though the contents of the files is unchanged.
+ .Pp
+ The temporary files
+ .Pa /tmp/rstdir*
+ and
+ .Pa /tmp/rstmode*
+ are generated with a unique name based on the date of the dump
+ and the process ID (see
+ .Xr mktemp 3 ),
+ except for when 
+ .Fl r
+ or
+ .Fl R
+ is used.
+ Because
+ .Fl R
+ allows you to restart a
+ .Fl r
+ operation that may have been interrupted, the temporary files should
+ be the same across different processes.
+ In all other cases, the files are unique because it is possible to
+ have two different dumps started at the same time, and separate
+ operations shouldn't conflict with each other.
  .Sh HISTORY
  The
  .Nm restore
>Audit-Trail:
>Unformatted: