Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Oct 2008 11:02:05 +0000 (UTC)
From:      Alexander Leidinger <netchild@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r183953 - in user/netchild/obsolete/src/sbin: dump restore
Message-ID:  <200810161102.m9GB25eR060125@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: netchild
Date: Thu Oct 16 11:02:05 2008
New Revision: 183953
URL: http://svn.freebsd.org/changeset/base/183953

Log:
  There was a timeframe when the signal handling in FreeBSD was not like it
  was supposed to be. Unfortunately this bug was triggered on a production
  machine. To get daily backups I used those changes.
  
  They are not needed in current or any supported stable version of FreeBSD,
  but maybe it helps someone at some place at some time out of some trouble.

Modified:
  user/netchild/obsolete/src/sbin/dump/dumprmt.c
  user/netchild/obsolete/src/sbin/dump/itime.c
  user/netchild/obsolete/src/sbin/dump/optr.c
  user/netchild/obsolete/src/sbin/dump/tape.c
  user/netchild/obsolete/src/sbin/restore/dirs.c
  user/netchild/obsolete/src/sbin/restore/symtab.c
  user/netchild/obsolete/src/sbin/restore/tape.c

Modified: user/netchild/obsolete/src/sbin/dump/dumprmt.c
==============================================================================
--- user/netchild/obsolete/src/sbin/dump/dumprmt.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/dump/dumprmt.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -110,7 +110,10 @@ rmtconnaborted(int sig __unused)
 			int i;
 			char buf[2048];
 
-			if ((i = read(errfd, buf, sizeof(buf) - 1)) > 0) {
+			do {
+				i = read(errfd, buf, sizeof(buf));
+			} while ((i == -1) && (errno == EINTR));
+			if (i - 1 > 0) {
 				buf[i] = '\0';
 				msg("on %s: %s%s", rmtpeer, buf,
 					buf[i - 1] == '\n' ? "" : "\n");
@@ -229,7 +232,9 @@ rmtread(char *buf, int count)
 		/* rmtcall() properly sets errno for us on errors. */
 		return (n);
 	for (i = 0; i < n; i += cc) {
-		cc = read(rmtape, buf+i, n - i);
+		do {
+			cc = read(rmtape, buf+i, n - i);
+		} while ((cc == -1) && (errno == EINTR));
 		if (cc <= 0)
 			rmtconnaborted(0);
 	}
@@ -347,8 +352,12 @@ int
 rmtgetb(void)
 {
 	char c;
+	int ret_val;
 
-	if (read(rmtape, &c, 1) != 1)
+	do {
+		ret_val = read(rmtape, &c, 1);
+	} while ((ret_val == -1) && (errno == EINTR));
+	if (ret_val != 1)
 		rmtconnaborted(0);
 	return (c);
 }

Modified: user/netchild/obsolete/src/sbin/dump/itime.c
==============================================================================
--- user/netchild/obsolete/src/sbin/dump/itime.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/dump/itime.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -71,7 +71,10 @@ initdumptimes(void)
 {
 	FILE *df;
 
-	if ((df = fopen(dumpdates, "r")) == NULL) {
+	do {
+		df = fopen(dumpdates, "r");
+	} while ((df == NULL) && (errno == EINTR));
+	if (df == NULL) {
 		if (errno != ENOENT) {
 			msg("WARNING: cannot read %s: %s\n", dumpdates,
 			    strerror(errno));
@@ -81,13 +84,19 @@ initdumptimes(void)
 		 * Dumpdates does not exist, make an empty one.
 		 */
 		msg("WARNING: no file `%s', making an empty one\n", dumpdates);
-		if ((df = fopen(dumpdates, "w")) == NULL) {
+		do {
+			df = fopen(dumpdates, "w");
+		} while ((df == NULL) && (errno == EINTR));
+		if (df == NULL) {
 			msg("WARNING: cannot create %s: %s\n", dumpdates,
 			    strerror(errno));
 			return;
 		}
 		(void) fclose(df);
-		if ((df = fopen(dumpdates, "r")) == NULL) {
+		do {
+			df = fopen(dumpdates, "r");
+		} while ((df == NULL) && (errno == EINTR));
+		if (df == NULL) {
 			quit("cannot read %s even after creating it: %s\n",
 			    dumpdates, strerror(errno));
 			/* NOTREACHED */
@@ -167,7 +176,10 @@ putdumptime(void)
 
 	if(uflag == 0)
 		return;
-	if ((df = fopen(dumpdates, "r+")) == NULL)
+	do {
+		df = fopen(dumpdates, "r+");
+	} while ((df == NULL) && (errno == EINTR));
+	if (df == NULL)
 		quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno));
 	fd = fileno(df);
 	(void) flock(fd, LOCK_EX);

Modified: user/netchild/obsolete/src/sbin/dump/optr.c
==============================================================================
--- user/netchild/obsolete/src/sbin/dump/optr.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/dump/optr.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -80,7 +80,10 @@ query(const char *question)
 	int	back, errcount;
 	FILE	*mytty;
 
-	if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
+	do {
+		mytty = fopen(_PATH_TTY, "r");
+	} while ((mytty == NULL) && (errno == EINTR));
+	if (mytty == NULL)
 		quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
 	attnmessage = question;
 	timeout = 0;

Modified: user/netchild/obsolete/src/sbin/dump/tape.c
==============================================================================
--- user/netchild/obsolete/src/sbin/dump/tape.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/dump/tape.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -327,7 +327,7 @@ trewind(void)
 				quit("or use no size estimate at all.\n");
 			}
 		}
-		(void) close(slaves[f].fd);
+		while ((close(slaves[f].fd) < 0) && (errno == EINTR)) /* nop */;
 	}
 	while (wait((int *)NULL) >= 0)	/* wait for any signals from slaves */
 		/* void */;
@@ -356,10 +356,10 @@ trewind(void)
 		(void)close(tapefd);
 		return;
 	}
-	(void) close(tapefd);
+	while ((close(tapefd) < 0) && (errno == EINTR)) /* nop */;
 	while ((f = open(tape, 0)) < 0)
 		sleep (10);
-	(void) close(f);
+	while ((close(f) < 0) && (errno == EINTR)) /* nop */;
 }
 
 void
@@ -720,7 +720,8 @@ enslave(void)
 		slaves[i].sent = 0;
 		if (slaves[i].pid == 0) { 	    /* Slave starts up here */
 			for (j = 0; j <= i; j++)
-			        (void) close(slaves[j].fd);
+			        while ((close(slaves[j].fd) < 0)
+					&& (errno == EINTR)) /* nop */;
 			signal(SIGINT, SIG_IGN);    /* Master handles this */
 			doslave(cmd[0], i);
 			Exit(X_FINOK);
@@ -763,8 +764,11 @@ doslave(int cmd, int slave_number)
 	/*
 	 * Need our own seek pointer.
 	 */
-	(void) close(diskfd);
-	if ((diskfd = open(disk, O_RDONLY)) < 0)
+	while ((close(diskfd) < 0) && (errno == EINTR)) /* nop */;
+	do {
+		diskfd = open(disk, O_RDONLY);
+	} while ((diskfd < 0) && (errno == EINTR));
+	if (diskfd < 0)
 		quit("slave couldn't reopen disk: %s\n", strerror(errno));
 
 	/*
@@ -874,7 +878,13 @@ atomic(ssize_t (*func)(), int fd, char *
 {
 	int got, need = count;
 
-	while ((got = (*func)(fd, buf, need)) > 0 && (need -= got) > 0)
-		buf += got;
+	do {
+		do {
+			got = (*func)(fd, buf, need);
+		} while ((got == -1) && (errno == EINTR));
+
+		if ((got > 0) && ((need -= got) > 0))
+			buf += got;
+	} while (got > 0 && need > 0);
 	return (got < 0 ? got : count - need);
 }

Modified: user/netchild/obsolete/src/sbin/restore/dirs.c
==============================================================================
--- user/netchild/obsolete/src/sbin/restore/dirs.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/restore/dirs.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -143,11 +143,19 @@ extractdirs(int genmode)
 	if (command != 'r' && command != 'R') {
 		(void *) strcat(dirfile, "-XXXXXX");
 		fd = mkstemp(dirfile);
-	} else
-		fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
-	if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
+	} else {
+		do {
+			fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
+		} while ((fd == -1) && (errno == EINTR));
+	}
+	if (fd != -1) {
+		do {
+			df = fdopen(fd, "w");
+		} while ((df == NULL) && (errno == EINTR));
+	}
+	if (fd == -1 || df == NULL) {
 		if (fd != -1)
-			close(fd);
+			while ((close(fd) == -1) && (errno == EINTR)) /* nop */;
 		warn("%s: cannot create directory database", dirfile);
 		done(1);
 	}
@@ -156,11 +164,20 @@ extractdirs(int genmode)
 		if (command != 'r' && command != 'R') {
 			(void *) strcat(modefile, "-XXXXXX");
 			fd = mkstemp(modefile);
-		} else
-			fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
-		if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
+		} else {
+			do {
+				fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
+			} while ((fd == -1) && (errno == EINTR));
+		}
+		if (fd != -1) {
+			do {
+				mf = fdopen(fd, "w");
+			} while ((mf == NULL) && (errno == EINTR));
+		}
+		if (fd == -1 || mf == NULL) {
 			if (fd != -1)
-				close(fd);
+				while ((close(fd) == -1) && (errno == EINTR))
+					/* nop */;
 			warn("%s: cannot create modefile", modefile);
 			done(1);
 		}
@@ -442,7 +459,10 @@ rst_seekdir(RST_DIR *dirp, long loc, lon
 	(void) lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET);
 	dirp->dd_loc = loc & (DIRBLKSIZ - 1);
 	if (dirp->dd_loc != 0)
-		dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
+		do {
+			dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
+			    DIRBLKSIZ);
+		} while ((dirp->dd_size == -1) && (errno == EINTR));
 }
 
 /*
@@ -455,8 +475,10 @@ rst_readdir(RST_DIR *dirp)
 
 	for (;;) {
 		if (dirp->dd_loc == 0) {
-			dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
-			    DIRBLKSIZ);
+			do {
+				dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
+				    DIRBLKSIZ);
+			} while ((dirp->dd_size == -1) && (errno == EINTR));
 			if (dirp->dd_size <= 0) {
 				dprintf(stderr, "error reading directory\n");
 				return (NULL);
@@ -513,7 +535,7 @@ rst_closedir(void *arg)
 	RST_DIR *dirp;
 
 	dirp = arg;
-	(void)close(dirp->dd_fd);
+	while ((close(dirp->dd_fd) == -1) && (errno == EINTR)) /* nop */;
 	free(dirp);
 	return;
 }
@@ -537,10 +559,13 @@ opendirfile(const char *name)
 	RST_DIR *dirp;
 	int fd;
 
-	if ((fd = open(name, O_RDONLY)) == -1)
+	do {
+		fd = open(name, O_RDONLY);
+	} while ((fd == -1) && (errno == EINTR));
+	if (fd == -1)
 		return (NULL);
 	if ((dirp = malloc(sizeof(RST_DIR))) == NULL) {
-		(void)close(fd);
+		while ((close(fd) == -1) && (errno == EINTR)) /* nop */;
 		return (NULL);
 	}
 	dirp->dd_fd = fd;
@@ -572,7 +597,9 @@ setdirmodes(int flags)
 		fprintf(stderr, "directory mode, owner, and times not set\n");
 		return;
 	}
-	mf = fopen(modefile, "r");
+	do {
+		mf = fopen(modefile, "r");
+	} while ((mf == NULL) && (errno == EINTR));
 	if (mf == NULL) {
 		fprintf(stderr, "fopen: %s\n", strerror(errno));
 		fprintf(stderr, "cannot open mode file %s\n", modefile);
@@ -676,7 +703,10 @@ genliteraldir(char *name, ino_t ino)
 	itp = inotablookup(ino);
 	if (itp == NULL)
 		panic("Cannot find directory inode %d named %s\n", ino, name);
-	if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
+	do {
+		ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+	} while ((ofile == -1) && (errno == EINTR));
+	if (ofile < 0) {
 		fprintf(stderr, "%s: ", name);
 		(void) fflush(stderr);
 		fprintf(stderr, "cannot create file: %s\n", strerror(errno));
@@ -685,8 +715,12 @@ genliteraldir(char *name, ino_t ino)
 	rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
 	dp = dup(dirp->dd_fd);
 	for (i = itp->t_size; i > 0; i -= BUFSIZ) {
+		int ret_val = 0;
 		size = i < BUFSIZ ? i : BUFSIZ;
-		if (read(dp, buf, (int) size) == -1) {
+		do {
+			ret_val = read(dp, buf, (int) size);
+		} while ((ret_val == -1) && (errno == EINTR));
+		if (ret_val == -1) {
 			fprintf(stderr,
 				"write error extracting inode %d, name %s\n",
 				curfile.ino, curfile.name);
@@ -701,8 +735,8 @@ genliteraldir(char *name, ino_t ino)
 			done(1);
 		}
 	}
-	(void) close(dp);
-	(void) close(ofile);
+	while((close(dp) == -1) && (errno == EINTR)) /* nop */;
+	while((close(ofile) == -1) && (errno == EINTR)) /* nop */;
 	return (GOOD);
 }
 

Modified: user/netchild/obsolete/src/sbin/restore/symtab.c
==============================================================================
--- user/netchild/obsolete/src/sbin/restore/symtab.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/restore/symtab.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -446,7 +446,10 @@ dumpsymtable(char *filename, long checkp
 	vprintf(stdout, "Check pointing the restore\n");
 	if (Nflag)
 		return;
-	if ((fd = fopen(filename, "w")) == NULL) {
+	do {
+		fd = fopen(filename, "w");
+	} while ((fd == NULL) && (errno == EINTR));
+	if (fd == NULL) {
 		fprintf(stderr, "fopen: %s\n", strerror(errno));
 		panic("cannot create save file %s for symbol table\n",
 			filename);
@@ -529,7 +532,7 @@ initsymtable(char *filename)
 	struct symtableheader hdr;
 	struct stat stbuf;
 	long i;
-	int fd;
+	int fd, ret_val;
 
 	vprintf(stdout, "Initialize symbol table.\n");
 	if (filename == NULL) {
@@ -542,7 +545,10 @@ initsymtable(char *filename)
 		ep->e_flags |= NEW;
 		return;
 	}
-	if ((fd = open(filename, O_RDONLY, 0)) < 0) {
+	do {
+		fd = open(filename, O_RDONLY, 0);
+	} while ((fd == -1) && (errno == EINTR));
+	if (fd < 0) {
 		fprintf(stderr, "open: %s\n", strerror(errno));
 		panic("cannot open symbol table file %s\n", filename);
 	}
@@ -554,8 +560,17 @@ initsymtable(char *filename)
 	base = calloc(sizeof(char), (unsigned)tblsize);
 	if (base == NULL)
 		panic("cannot allocate space for symbol table\n");
-	if (read(fd, base, (int)tblsize) < 0 ||
-	    read(fd, (char *)&hdr, sizeof(struct symtableheader)) < 0) {
+	do {
+		ret_val = read(fd, base, (int)tblsize);
+	} while ((ret_val == -1) && (errno == EINTR));
+	if (ret_val == -1) {
+		fprintf(stderr, "read: %s\n", strerror(errno));
+		panic("cannot read symbol table file %s\n", filename);
+	}
+	do {
+		ret_val = read(fd, (char *)&hdr, sizeof(struct symtableheader));
+	} while ((ret_val == -1) && (errno == EINTR));
+	if (ret_val == -1) {
 		fprintf(stderr, "read: %s\n", strerror(errno));
 		panic("cannot read symbol table file %s\n", filename);
 	}

Modified: user/netchild/obsolete/src/sbin/restore/tape.c
==============================================================================
--- user/netchild/obsolete/src/sbin/restore/tape.c	Thu Oct 16 10:58:52 2008	(r183952)
+++ user/netchild/obsolete/src/sbin/restore/tape.c	Thu Oct 16 11:02:05 2008	(r183953)
@@ -151,11 +151,15 @@ setinput(char *source, int ispipecommand
 		 * Since input is coming from a pipe we must establish
 		 * our own connection to the terminal.
 		 */
-		terminal = fopen(_PATH_TTY, "r");
+		do {
+			terminal = fopen(_PATH_TTY, "r");
+		} while ((terminal == NULL) && (errno == EINTR));
 		if (terminal == NULL) {
 			(void)fprintf(stderr, "cannot open %s: %s\n",
 			    _PATH_TTY, strerror(errno));
-			terminal = fopen(_PATH_DEVNULL, "r");
+			do {
+				terminal = fopen(_PATH_DEVNULL, "r");
+			} while ((terminal == NULL) && (errno == EINTR));
 			if (terminal == NULL) {
 				(void)fprintf(stderr, "cannot open %s: %s\n",
 				    _PATH_DEVNULL, strerror(errno));
@@ -218,8 +222,11 @@ setup(void)
 #endif
 	if (pipein)
 		mt = 0;
-	else
-		mt = open(magtape, O_RDONLY, 0);
+	else {
+		do {
+			mt = open(magtape, O_RDONLY, 0);
+		} while ((mt == -1) && (errno == EINTR));
+	}
 	if (mt < 0) {
 		fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
 		done(1);
@@ -415,7 +422,9 @@ getpipecmdhdr:
 		mt = rmtopen(magtape, 0);
 	else
 #endif
-		mt = open(magtape, O_RDONLY, 0);
+		do {
+			mt = open(magtape, O_RDONLY, 0);
+		} while ((mt == -1) && (errno == EINTR));
 
 	if (mt == -1) {
 		fprintf(stderr, "Cannot open %s\n", magtape);
@@ -698,9 +707,11 @@ extractfile(char *name)
 			return (GOOD);
 		}
 		if (uflag)
-			(void) unlink(name);
-		if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
-		    0600)) < 0) {
+			(void)unlink(name);
+		do {
+			ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+		} while ((ofile <0) && (errno == EINTR));
+		if (ofile < 0) {
 			fprintf(stderr, "%s: cannot create file: %s\n",
 			    name, strerror(errno));
 			skipfile();
@@ -715,7 +726,7 @@ extractfile(char *name)
 		(void) futimes(ofile, ctimep);
 		(void) futimes(ofile, mtimep);
 		(void) fchflags(ofile, flags);
-		(void) close(ofile);
+		while((close(ofile) == -1) && (errno == EINTR)) /* nop */;
 		return (GOOD);
 	}
 	/* NOTREACHED */
@@ -1199,7 +1210,9 @@ getmore:
 		i = rmtread(&tapebuf[rd], cnt);
 	else
 #endif
-		i = read(mt, &tapebuf[rd], cnt);
+		do {
+			i = read(mt, &tapebuf[rd], cnt);
+		} while ((i == -1) && (errno == EINTR));
 	/*
 	 * Check for mid-tape short read error.
 	 * If found, skip rest of buffer and start with the next.
@@ -1310,7 +1323,9 @@ findtapeblksize(void)
 		i = rmtread(tapebuf, ntrec * TP_BSIZE);
 	else
 #endif
-		i = read(mt, tapebuf, ntrec * TP_BSIZE);
+		do {
+			i = read(mt, tapebuf, ntrec * TP_BSIZE);
+		} while ((i == -1) && (errno == EINTR));
 
 	if (i <= 0) {
 		fprintf(stderr, "tape read error: %s\n", strerror(errno));
@@ -1341,7 +1356,7 @@ closemt(void)
 		rmtclose();
 	else
 #endif
-		(void) close(mt);
+		while((close(mt) == -1) && (errno == EINTR)) /* nop */;
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810161102.m9GB25eR060125>