svn commit: r216039 - stable/8/usr.sbin/lpr/lpd

Garance A Drosehn gad at FreeBSD.org
Mon Nov 29 04:57:47 UTC 2010


Author: gad
Date: Mon Nov 29 04:57:46 2010
New Revision: 216039
URL: http://svn.freebsd.org/changeset/base/216039

Log:
  = MFC of r211190:
  - Improve the wait4data() routine so it behaves better when checking
    print-jobs which have last-modification times that are in the future.
    This shouldn't happen, of course, but it can.  And when it did happen,
    the previous check could cause completely-spooled jobs to sit in the
    queue for 20 minutes per job.  The new code waits until the last-modify
    time is not changing, instead of making decisions based on the specific
    value of last-modify.

Modified:
  stable/8/usr.sbin/lpr/lpd/printjob.c
Directory Properties:
  stable/8/usr.sbin/lpr/   (props changed)

Modified: stable/8/usr.sbin/lpr/lpd/printjob.c
==============================================================================
--- stable/8/usr.sbin/lpr/lpd/printjob.c	Mon Nov 29 04:31:25 2010	(r216038)
+++ stable/8/usr.sbin/lpr/lpd/printjob.c	Mon Nov 29 04:57:46 2010	(r216039)
@@ -1263,8 +1263,9 @@ wait4data(struct printer *pp, const char
 {
 	const char *cp;
 	int statres;
+	u_int sleepreq;
 	size_t dlen, hlen;
-	time_t amtslept, checktime;
+	time_t amtslept, cur_time, prev_mtime;
 	struct stat statdf;
 
 	/* Skip these checks if the print job is from the local host. */
@@ -1297,15 +1298,30 @@ wait4data(struct printer *pp, const char
 
 	/*
 	 * The file exists, so keep waiting until the data file has not
-	 * changed for some reasonable amount of time.
+	 * changed for some reasonable amount of time.  Extra care is
+	 * taken when computing wait-times, just in case there are data
+	 * files with a last-modify time in the future.  While that is
+	 * very unlikely to happen, it can happen when the system has
+	 * a flakey time-of-day clock.
 	 */
-	while (statres == 0 && amtslept < MAXWAIT_4DATA) {
-		checktime = time(NULL) - MINWAIT_4DATA;
-		if (statdf.st_mtime <= checktime)
-			break;
+	prev_mtime = statdf.st_mtime;
+	cur_time = time(NULL);
+	if (statdf.st_mtime >= cur_time - MINWAIT_4DATA) {
+		if (statdf.st_mtime >= cur_time)	/* some TOD oddity */
+			sleepreq = MINWAIT_4DATA;
+		else
+			sleepreq = cur_time - statdf.st_mtime;
 		if (amtslept == 0)
 			pstatus(pp, "Waiting for data file from remote host");
-		amtslept += MINWAIT_4DATA - sleep(MINWAIT_4DATA);
+		amtslept += sleepreq - sleep(sleepreq);
+		statres = stat(dfile, &statdf);
+	}
+	sleepreq = MINWAIT_4DATA;
+	while (statres == 0 && amtslept < MAXWAIT_4DATA) {
+		if (statdf.st_mtime == prev_mtime)
+			break;
+		prev_mtime = statdf.st_mtime;
+		amtslept += sleepreq - sleep(sleepreq);
 		statres = stat(dfile, &statdf);
 	}
 


More information about the svn-src-all mailing list