Deleted Added
full compact
printjob.c (139035) printjob.c (160147)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40
41#if 0
42#ifndef lint
43static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
44#endif /* not lint */
45#endif
46
47#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40
41#if 0
42#ifndef lint
43static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
44#endif /* not lint */
45#endif
46
47#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */
48__FBSDID("$FreeBSD: head/usr.sbin/lpr/lpd/printjob.c 139035 2004-12-19 05:14:29Z gad $");
48__FBSDID("$FreeBSD: head/usr.sbin/lpr/lpd/printjob.c 160147 2006-07-07 01:12:26Z gad $");
49
50/*
51 * printjob -- print jobs in the queue.
52 *
53 * NOTE: the lock file is used to pass information to lpq and lprm.
54 * it does not need to be removed because file locks are dynamic.
55 */
56

--- 103 unchanged lines hidden (view full) ---

160printjob(struct printer *pp)
161{
162 struct stat stb;
163 register struct jobqueue *q, **qp;
164 struct jobqueue **queue;
165 register int i, nitems;
166 off_t pidoff;
167 pid_t printpid;
49
50/*
51 * printjob -- print jobs in the queue.
52 *
53 * NOTE: the lock file is used to pass information to lpq and lprm.
54 * it does not need to be removed because file locks are dynamic.
55 */
56

--- 103 unchanged lines hidden (view full) ---

160printjob(struct printer *pp)
161{
162 struct stat stb;
163 register struct jobqueue *q, **qp;
164 struct jobqueue **queue;
165 register int i, nitems;
166 off_t pidoff;
167 pid_t printpid;
168 int errcnt, jobcount, tempfd;
168 int errcnt, jobcount, statok, tempfd;
169
170 jobcount = 0;
171 init(pp); /* set up capabilities */
172 (void) write(STDOUT_FILENO, "", 1); /* ack that daemon is started */
173 (void) close(STDERR_FILENO); /* set up log file */
174 if (open(pp->log_file, O_WRONLY|O_APPEND, LOG_FILE_MODE) < 0) {
175 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer,
176 pp->log_file);

--- 18 unchanged lines hidden (view full) ---

195 /*
196 * uses short form file names
197 */
198 if (chdir(pp->spool_dir) < 0) {
199 syslog(LOG_ERR, "%s: chdir(%s): %m", pp->printer,
200 pp->spool_dir);
201 exit(1);
202 }
169
170 jobcount = 0;
171 init(pp); /* set up capabilities */
172 (void) write(STDOUT_FILENO, "", 1); /* ack that daemon is started */
173 (void) close(STDERR_FILENO); /* set up log file */
174 if (open(pp->log_file, O_WRONLY|O_APPEND, LOG_FILE_MODE) < 0) {
175 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer,
176 pp->log_file);

--- 18 unchanged lines hidden (view full) ---

195 /*
196 * uses short form file names
197 */
198 if (chdir(pp->spool_dir) < 0) {
199 syslog(LOG_ERR, "%s: chdir(%s): %m", pp->printer,
200 pp->spool_dir);
201 exit(1);
202 }
203 if (stat(pp->lock_file, &stb) == 0 && (stb.st_mode & LFM_PRINT_DIS))
203 statok = stat(pp->lock_file, &stb);
204 if (statok == 0 && (stb.st_mode & LFM_PRINT_DIS))
204 exit(0); /* printing disabled */
205 umask(S_IWOTH);
206 lfd = open(pp->lock_file, O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK,
207 LOCK_FILE_MODE);
208 if (lfd < 0) {
209 if (errno == EWOULDBLOCK) /* active daemon present */
210 exit(0);
211 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer,
212 pp->lock_file);
213 exit(1);
214 }
205 exit(0); /* printing disabled */
206 umask(S_IWOTH);
207 lfd = open(pp->lock_file, O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK,
208 LOCK_FILE_MODE);
209 if (lfd < 0) {
210 if (errno == EWOULDBLOCK) /* active daemon present */
211 exit(0);
212 syslog(LOG_ERR, "%s: open(%s): %m", pp->printer,
213 pp->lock_file);
214 exit(1);
215 }
216 /*
217 * If the initial call to stat() failed, then lock_file will have
218 * been created by open(). Update &stb to match that new file.
219 */
220 if (statok != 0)
221 statok = stat(pp->lock_file, &stb);
215 /* turn off non-blocking mode (was turned on for lock effects only) */
216 if (fcntl(lfd, F_SETFL, 0) < 0) {
217 syslog(LOG_ERR, "%s: fcntl(%s): %m", pp->printer,
218 pp->lock_file);
219 exit(1);
220 }
221 ftruncate(lfd, 0);
222 /*

--- 1776 unchanged lines hidden ---
222 /* turn off non-blocking mode (was turned on for lock effects only) */
223 if (fcntl(lfd, F_SETFL, 0) < 0) {
224 syslog(LOG_ERR, "%s: fcntl(%s): %m", pp->printer,
225 pp->lock_file);
226 exit(1);
227 }
228 ftruncate(lfd, 0);
229 /*

--- 1776 unchanged lines hidden ---