common.c (75253) | common.c (78146) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 27 unchanged lines hidden (view full) --- 36 * SUCH DAMAGE. 37 */ 38 39#ifndef lint 40/* 41static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; 42*/ 43static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 27 unchanged lines hidden (view full) --- 36 * SUCH DAMAGE. 37 */ 38 39#ifndef lint 40/* 41static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; 42*/ 43static const char rcsid[] = |
44 "$FreeBSD: head/usr.sbin/lpr/common_source/common.c 75253 2001-04-06 02:14:39Z gad $"; | 44 "$FreeBSD: head/usr.sbin/lpr/common_source/common.c 78146 2001-06-12 16:38:20Z gad $"; |
45#endif /* not lint */ 46 47#include <sys/param.h> 48#include <sys/stat.h> 49#include <sys/time.h> 50#include <sys/types.h> 51 52#include <dirent.h> --- 6 unchanged lines hidden (view full) --- 59#include "lp.h" 60#include "lp.local.h" 61#include "pathnames.h" 62 63/* 64 * Routines and data common to all the line printer functions. 65 */ 66char line[BUFSIZ]; | 45#endif /* not lint */ 46 47#include <sys/param.h> 48#include <sys/stat.h> 49#include <sys/time.h> 50#include <sys/types.h> 51 52#include <dirent.h> --- 6 unchanged lines hidden (view full) --- 59#include "lp.h" 60#include "lp.local.h" 61#include "pathnames.h" 62 63/* 64 * Routines and data common to all the line printer functions. 65 */ 66char line[BUFSIZ]; |
67char *name; /* program name */ | 67const char *name; /* program name */ |
68 69extern uid_t uid, euid; 70 | 68 69extern uid_t uid, euid; 70 |
71static int compar __P((const void *, const void *)); | 71static int compar(const void *_p1, const void *_p2); |
72 73/* 74 * Getline reads a line from the control file cfp, removes tabs, converts 75 * new-line to null and leaves it in line. 76 * Returns 0 at EOF or the number of characters read. 77 */ 78int | 72 73/* 74 * Getline reads a line from the control file cfp, removes tabs, converts 75 * new-line to null and leaves it in line. 76 * Returns 0 at EOF or the number of characters read. 77 */ 78int |
79getline(cfp) 80 FILE *cfp; | 79getline(FILE *cfp) |
81{ 82 register int linel = 0; 83 register char *lp = line; 84 register int c; 85 86 while ((c = getc(cfp)) != '\n' && linel+1 < sizeof(line)) { 87 if (c == EOF) 88 return(0); --- 12 unchanged lines hidden (view full) --- 101} 102 103/* 104 * Scan the current directory and make a list of daemon files sorted by 105 * creation time. 106 * Return the number of entries and a pointer to the list. 107 */ 108int | 80{ 81 register int linel = 0; 82 register char *lp = line; 83 register int c; 84 85 while ((c = getc(cfp)) != '\n' && linel+1 < sizeof(line)) { 86 if (c == EOF) 87 return(0); --- 12 unchanged lines hidden (view full) --- 100} 101 102/* 103 * Scan the current directory and make a list of daemon files sorted by 104 * creation time. 105 * Return the number of entries and a pointer to the list. 106 */ 107int |
109getq(pp, namelist) 110 const struct printer *pp; 111 struct jobqueue *(*namelist[]); | 108getq(const struct printer *pp, struct jobqueue *(*namelist[])) |
112{ 113 register struct dirent *d; 114 register struct jobqueue *q, **queue; 115 register int nitems; 116 struct stat stbuf; 117 DIR *dirp; 118 int arraysz, statres; 119 --- 54 unchanged lines hidden (view full) --- 174 seteuid(uid); 175 return (-1); 176} 177 178/* 179 * Compare modification times. 180 */ 181static int | 109{ 110 register struct dirent *d; 111 register struct jobqueue *q, **queue; 112 register int nitems; 113 struct stat stbuf; 114 DIR *dirp; 115 int arraysz, statres; 116 --- 54 unchanged lines hidden (view full) --- 171 seteuid(uid); 172 return (-1); 173} 174 175/* 176 * Compare modification times. 177 */ 178static int |
182compar(p1, p2) 183 const void *p1, *p2; | 179compar(const void *p1, const void *p2) |
184{ 185 const struct jobqueue *qe1, *qe2; 186 187 qe1 = *(const struct jobqueue **)p1; 188 qe2 = *(const struct jobqueue **)p2; 189 190 if (qe1->job_time < qe2->job_time) 191 return (-1); --- 10 unchanged lines hidden (view full) --- 202 return (-1); 203 if ((qe1->job_cfname[3] == '0') && (qe2->job_cfname[3] == '9')) 204 return (1); 205 return (strcmp(qe1->job_cfname, qe2->job_cfname)); 206} 207 208/* sleep n milliseconds */ 209void | 180{ 181 const struct jobqueue *qe1, *qe2; 182 183 qe1 = *(const struct jobqueue **)p1; 184 qe2 = *(const struct jobqueue **)p2; 185 186 if (qe1->job_time < qe2->job_time) 187 return (-1); --- 10 unchanged lines hidden (view full) --- 198 return (-1); 199 if ((qe1->job_cfname[3] == '0') && (qe2->job_cfname[3] == '9')) 200 return (1); 201 return (strcmp(qe1->job_cfname, qe2->job_cfname)); 202} 203 204/* sleep n milliseconds */ 205void |
210delay(n) 211 int n; | 206delay(int millisec) |
212{ 213 struct timeval tdelay; 214 | 207{ 208 struct timeval tdelay; 209 |
215 if (n <= 0 || n > 10000) | 210 if (millisec <= 0 || millisec > 10000) |
216 fatal((struct printer *)0, /* fatal() knows how to deal */ | 211 fatal((struct printer *)0, /* fatal() knows how to deal */ |
217 "unreasonable delay period (%d)", n); 218 tdelay.tv_sec = n / 1000; 219 tdelay.tv_usec = n * 1000 % 1000000; | 212 "unreasonable delay period (%d)", millisec); 213 tdelay.tv_sec = millisec / 1000; 214 tdelay.tv_usec = millisec * 1000 % 1000000; |
220 (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay); 221} 222 223char * | 215 (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay); 216} 217 218char * |
224lock_file_name(pp, buf, len) 225 const struct printer *pp; 226 char *buf; 227 size_t len; | 219lock_file_name(const struct printer *pp, char *buf, size_t len) |
228{ 229 static char staticbuf[MAXPATHLEN]; 230 231 if (buf == 0) 232 buf = staticbuf; 233 if (len == 0) 234 len = MAXPATHLEN; 235 236 if (pp->lock_file[0] == '/') { 237 buf[0] = '\0'; 238 strncpy(buf, pp->lock_file, len); 239 } else { 240 snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file); 241 } 242 return buf; 243} 244 245char * | 220{ 221 static char staticbuf[MAXPATHLEN]; 222 223 if (buf == 0) 224 buf = staticbuf; 225 if (len == 0) 226 len = MAXPATHLEN; 227 228 if (pp->lock_file[0] == '/') { 229 buf[0] = '\0'; 230 strncpy(buf, pp->lock_file, len); 231 } else { 232 snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file); 233 } 234 return buf; 235} 236 237char * |
246status_file_name(pp, buf, len) 247 const struct printer *pp; 248 char *buf; 249 size_t len; | 238status_file_name(const struct printer *pp, char *buf, size_t len) |
250{ 251 static char staticbuf[MAXPATHLEN]; 252 253 if (buf == 0) 254 buf = staticbuf; 255 if (len == 0) 256 len = MAXPATHLEN; 257 258 if (pp->status_file[0] == '/') { 259 buf[0] = '\0'; 260 strncpy(buf, pp->status_file, len); 261 } else { 262 snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file); 263 } 264 return buf; 265} 266 267/* routine to get a current timestamp, optionally in a standard-fmt string */ 268void | 239{ 240 static char staticbuf[MAXPATHLEN]; 241 242 if (buf == 0) 243 buf = staticbuf; 244 if (len == 0) 245 len = MAXPATHLEN; 246 247 if (pp->status_file[0] == '/') { 248 buf[0] = '\0'; 249 strncpy(buf, pp->status_file, len); 250 } else { 251 snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file); 252 } 253 return buf; 254} 255 256/* routine to get a current timestamp, optionally in a standard-fmt string */ 257void |
269lpd_gettime(tsp, strp, strsize) 270 struct timespec *tsp; 271 char *strp; 272 int strsize; | 258lpd_gettime(struct timespec *tsp, char *strp, int strsize) |
273{ 274 struct timespec local_ts; 275 struct timeval btime; 276 char *destp; 277 char tempstr[TIMESTR_SIZE]; 278 279 if (tsp == NULL) 280 tsp = &local_ts; --- 45 unchanged lines hidden (view full) --- 326 strsize = TIMESTR_SIZE; 327 strp[TIMESTR_SIZE+1] = '\0'; 328 } 329 strncpy(strp, tempstr, strsize); 330} 331 332/* routines for writing transfer-statistic records */ 333void | 259{ 260 struct timespec local_ts; 261 struct timeval btime; 262 char *destp; 263 char tempstr[TIMESTR_SIZE]; 264 265 if (tsp == NULL) 266 tsp = &local_ts; --- 45 unchanged lines hidden (view full) --- 312 strsize = TIMESTR_SIZE; 313 strp[TIMESTR_SIZE+1] = '\0'; 314 } 315 strncpy(strp, tempstr, strsize); 316} 317 318/* routines for writing transfer-statistic records */ 319void |
334trstat_init(pp, fname, filenum) 335 struct printer *pp; 336 const char *fname; 337 int filenum; | 320trstat_init(struct printer *pp, const char *fname, int filenum) |
338{ 339 register const char *srcp; 340 register char *destp, *endp; 341 342 /* 343 * Figure out the job id of this file. The filename should be 344 * 'cf', 'df', or maybe 'tf', followed by a letter (or sometimes 345 * two), followed by the jobnum, followed by a hostname. --- 18 unchanged lines hidden (view full) --- 364 * save those away along with the file-number */ 365 pp->jobdfnum = filenum; 366 lpd_gettime(&pp->tr_start, pp->tr_timestr, TIMESTR_SIZE); 367 368 return; 369} 370 371void | 321{ 322 register const char *srcp; 323 register char *destp, *endp; 324 325 /* 326 * Figure out the job id of this file. The filename should be 327 * 'cf', 'df', or maybe 'tf', followed by a letter (or sometimes 328 * two), followed by the jobnum, followed by a hostname. --- 18 unchanged lines hidden (view full) --- 347 * save those away along with the file-number */ 348 pp->jobdfnum = filenum; 349 lpd_gettime(&pp->tr_start, pp->tr_timestr, TIMESTR_SIZE); 350 351 return; 352} 353 354void |
372trstat_write(pp, sendrecv, bytecnt, userid, otherhost, orighost) 373 struct printer *pp; 374 tr_sendrecv sendrecv; 375 size_t bytecnt; 376 const char *userid; 377 const char *otherhost; 378 const char *orighost; | 355trstat_write(struct printer *pp, tr_sendrecv sendrecv, size_t bytecnt, 356 const char *userid, const char *otherhost, const char *orighost) |
379{ 380#define STATLINE_SIZE 1024 381 double trtime; 382 int remspace, statfile; 383 char thishost[MAXHOSTNAMELEN], statline[STATLINE_SIZE]; 384 char *eostat; 385 const char *lprhost, *recvdev, *recvhost, *rectype; 386 const char *sendhost, *statfname; --- 202 unchanged lines hidden (view full) --- 589/* 590 * Close all file descriptors from START on up. 591 * This is a horrific kluge, since getdtablesize() might return 592 * ``infinity'', in which case we will be spending a long time 593 * closing ``files'' which were never open. Perhaps it would 594 * be better to close the first N fds, for some small value of N. 595 */ 596void | 357{ 358#define STATLINE_SIZE 1024 359 double trtime; 360 int remspace, statfile; 361 char thishost[MAXHOSTNAMELEN], statline[STATLINE_SIZE]; 362 char *eostat; 363 const char *lprhost, *recvdev, *recvhost, *rectype; 364 const char *sendhost, *statfname; --- 202 unchanged lines hidden (view full) --- 567/* 568 * Close all file descriptors from START on up. 569 * This is a horrific kluge, since getdtablesize() might return 570 * ``infinity'', in which case we will be spending a long time 571 * closing ``files'' which were never open. Perhaps it would 572 * be better to close the first N fds, for some small value of N. 573 */ 574void |
597closeallfds(start) 598 int start; | 575closeallfds(int start) |
599{ 600 int stop = getdtablesize(); 601 for (; start < stop; start++) 602 close(start); 603} 604 | 576{ 577 int stop = getdtablesize(); 578 for (; start < stop; start++) 579 close(start); 580} 581 |