From owner-svn-src-all@FreeBSD.ORG Mon Nov 29 04:57:47 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B71B106564A; Mon, 29 Nov 2010 04:57:47 +0000 (UTC) (envelope-from gad@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E2A1B8FC15; Mon, 29 Nov 2010 04:57:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAT4vkXr094572; Mon, 29 Nov 2010 04:57:46 GMT (envelope-from gad@svn.freebsd.org) Received: (from gad@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAT4vkPS094570; Mon, 29 Nov 2010 04:57:46 GMT (envelope-from gad@svn.freebsd.org) Message-Id: <201011290457.oAT4vkPS094570@svn.freebsd.org> From: Garance A Drosehn Date: Mon, 29 Nov 2010 04:57:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216039 - stable/8/usr.sbin/lpr/lpd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Nov 2010 04:57:47 -0000 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); }