From ffdf784c83b5528a16f0a9625cd917c572566285 Mon Sep 17 00:00:00 2001 From: gad Date: Wed, 11 Aug 2010 19:32:49 +0000 Subject: - 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. MFC after: 2 weeks --- usr.sbin/lpr/lpd/printjob.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'usr.sbin/lpr') diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index 58efe6d..7b50f65 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -1263,8 +1263,9 @@ wait4data(struct printer *pp, const char *dfile) { 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 *dfile) /* * 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); } -- cgit v1.1