aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/lpr/lpd/printjob.c
diff options
context:
space:
mode:
authorGarance A Drosehn <gad@FreeBSD.org>2006-07-07 01:12:26 +0000
committerGarance A Drosehn <gad@FreeBSD.org>2006-07-07 01:12:26 +0000
commitae39ffc92eeb4a2ec863702791f80601d270197a (patch)
tree51e56f73a59fc55280b74727bb058da59068de03 /usr.sbin/lpr/lpd/printjob.c
parente4256d1e8d9d048e78b3ca2fb8c666055a92276d (diff)
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
Notes
Notes: svn path=/head/; revision=160147
Diffstat (limited to 'usr.sbin/lpr/lpd/printjob.c')
-rw-r--r--usr.sbin/lpr/lpd/printjob.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c
index ae5ffc55be08..58efe6db272b 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,