diff options
author | gad <gad@FreeBSD.org> | 2006-07-07 01:12:26 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2006-07-07 01:12:26 +0000 |
commit | f18b69f883bd456e6d5da7482ed6c2233478425b (patch) | |
tree | 51e56f73a59fc55280b74727bb058da59068de03 /usr.sbin/lpr/lpd | |
parent | e8e07ae08e0430935736e6e7b46bd55b842e2eb7 (diff) | |
download | FreeBSD-src-f18b69f883bd456e6d5da7482ed6c2233478425b.zip FreeBSD-src-f18b69f883bd456e6d5da7482ed6c2233478425b.tar.gz |
Fix checking of the "lock" file in the spool directory for a queue,
so that the checking will wind up with the correct mode-bits in
the case where the initial open() of that lock file will create it.
Due to this bug, the first job ever sent to a queue could leave
that queue in a "printing is disabled" state.
PR: 93469
Submitted by: Michael Szklarski of kco.com.pl
MFC after: 1 week
Diffstat (limited to 'usr.sbin/lpr/lpd')
-rw-r--r-- | usr.sbin/lpr/lpd/printjob.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index ae5ffc5..58efe6d 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -165,7 +165,7 @@ printjob(struct printer *pp) register int i, nitems; off_t pidoff; pid_t printpid; - int errcnt, jobcount, tempfd; + int errcnt, jobcount, statok, tempfd; jobcount = 0; init(pp); /* set up capabilities */ @@ -200,7 +200,8 @@ printjob(struct printer *pp) pp->spool_dir); exit(1); } - if (stat(pp->lock_file, &stb) == 0 && (stb.st_mode & LFM_PRINT_DIS)) + statok = stat(pp->lock_file, &stb); + if (statok == 0 && (stb.st_mode & LFM_PRINT_DIS)) exit(0); /* printing disabled */ umask(S_IWOTH); lfd = open(pp->lock_file, O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK, @@ -212,6 +213,12 @@ printjob(struct printer *pp) pp->lock_file); exit(1); } + /* + * If the initial call to stat() failed, then lock_file will have + * been created by open(). Update &stb to match that new file. + */ + if (statok != 0) + statok = stat(pp->lock_file, &stb); /* turn off non-blocking mode (was turned on for lock effects only) */ if (fcntl(lfd, F_SETFL, 0) < 0) { syslog(LOG_ERR, "%s: fcntl(%s): %m", pp->printer, |