diff options
author | gad <gad@FreeBSD.org> | 2010-08-11 19:32:49 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2010-08-11 19:32:49 +0000 |
commit | ffdf784c83b5528a16f0a9625cd917c572566285 (patch) | |
tree | 1e72ca97047159cb8b5759d0bae466acab4463d1 /usr.sbin/lpr | |
parent | 958f6877baa55ccf62380775f45358063452d3b7 (diff) | |
download | FreeBSD-src-ffdf784c83b5528a16f0a9625cd917c572566285.zip FreeBSD-src-ffdf784c83b5528a16f0a9625cd917c572566285.tar.gz |
- 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
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r-- | usr.sbin/lpr/lpd/printjob.c | 30 |
1 files changed, 23 insertions, 7 deletions
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); } |