- 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
This commit is contained in:
parent
65a13e8549
commit
422605a3b9
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user