recvjob.c (68735) | recvjob.c (78146) |
---|---|
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: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95"; 44#endif 45static const char rcsid[] = | 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: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95"; 44#endif 45static const char rcsid[] = |
46 "$FreeBSD: head/usr.sbin/lpr/lpd/recvjob.c 68735 2000-11-14 22:08:52Z gad $"; | 46 "$FreeBSD: head/usr.sbin/lpr/lpd/recvjob.c 78146 2001-06-12 16:38:20Z gad $"; |
47#endif /* not lint */ 48 49/* 50 * Receive printer jobs from the network, queue them and 51 * start the printer daemon. 52 */ 53#include <sys/param.h> 54#include <sys/mount.h> --- 11 unchanged lines hidden (view full) --- 66#include "lp.local.h" 67#include "extern.h" 68#include "pathnames.h" 69 70#define ack() (void) write(1, sp, 1); 71 72static char dfname[NAME_MAX]; /* data files */ 73static int minfree; /* keep at least minfree blocks available */ | 47#endif /* not lint */ 48 49/* 50 * Receive printer jobs from the network, queue them and 51 * start the printer daemon. 52 */ 53#include <sys/param.h> 54#include <sys/mount.h> --- 11 unchanged lines hidden (view full) --- 66#include "lp.local.h" 67#include "extern.h" 68#include "pathnames.h" 69 70#define ack() (void) write(1, sp, 1); 71 72static char dfname[NAME_MAX]; /* data files */ 73static int minfree; /* keep at least minfree blocks available */ |
74static char *sp = ""; | 74static const char *sp = ""; |
75static char tfname[NAME_MAX]; /* tmp copy of cf before linking */ 76 | 75static char tfname[NAME_MAX]; /* tmp copy of cf before linking */ 76 |
77static int chksize __P((int)); 78static void frecverr __P((const char *, ...)); 79static int noresponse __P((void)); 80static void rcleanup __P((int)); 81static int read_number __P((char *)); 82static int readfile __P((struct printer *pp, char *, int)); 83static int readjob __P((struct printer *pp)); | 77static int chksize(int _size); 78static void frecverr(const char *_msg, ...); 79static int noresponse(void); 80static void rcleanup(int _signo); 81static int read_number(const char *_fn); 82static int readfile(struct printer *_pp, char *_file, int _size); 83static int readjob(struct printer *_pp); |
84 85 86void | 84 85 86void |
87recvjob(printer) 88 const char *printer; | 87recvjob(const char *printer) |
89{ 90 struct stat stb; 91 int status; 92 struct printer myprinter, *pp = &myprinter; 93 94 /* 95 * Perform lookup for printer name or abbreviation 96 */ --- 36 unchanged lines hidden (view full) --- 133 printjob(pp); 134} 135 136/* 137 * Read printer jobs sent by lpd and copy them to the spooling directory. 138 * Return the number of jobs successfully transfered. 139 */ 140static int | 88{ 89 struct stat stb; 90 int status; 91 struct printer myprinter, *pp = &myprinter; 92 93 /* 94 * Perform lookup for printer name or abbreviation 95 */ --- 36 unchanged lines hidden (view full) --- 132 printjob(pp); 133} 134 135/* 136 * Read printer jobs sent by lpd and copy them to the spooling directory. 137 * Return the number of jobs successfully transfered. 138 */ 139static int |
141readjob(pp) 142 struct printer *pp; | 140readjob(struct printer *pp) |
143{ 144 register int size; 145 register char *cp; 146 int cfcnt, dfcnt; 147 char givenid[32], givenhost[MAXHOSTNAMELEN]; 148 149 ack(); 150 cfcnt = 0; --- 90 unchanged lines hidden (view full) --- 241 /*NOTREACHED*/ 242 } 243} 244 245/* 246 * Read files send by lpd and copy them to the spooling directory. 247 */ 248static int | 141{ 142 register int size; 143 register char *cp; 144 int cfcnt, dfcnt; 145 char givenid[32], givenhost[MAXHOSTNAMELEN]; 146 147 ack(); 148 cfcnt = 0; --- 90 unchanged lines hidden (view full) --- 239 /*NOTREACHED*/ 240 } 241} 242 243/* 244 * Read files send by lpd and copy them to the spooling directory. 245 */ 246static int |
249readfile(pp, file, size) 250 struct printer *pp; 251 char *file; 252 int size; | 247readfile(struct printer *pp, char *file, int size) |
253{ 254 register char *cp; 255 char buf[BUFSIZ]; 256 register int i, j, amt; 257 int fd, err; 258 259 fd = open(file, O_CREAT|O_EXCL|O_WRONLY, FILMOD); 260 if (fd < 0) { --- 35 unchanged lines hidden (view full) --- 296 (void) unlink(file); 297 return (0); 298 } 299 ack(); 300 return (1); 301} 302 303static int | 248{ 249 register char *cp; 250 char buf[BUFSIZ]; 251 register int i, j, amt; 252 int fd, err; 253 254 fd = open(file, O_CREAT|O_EXCL|O_WRONLY, FILMOD); 255 if (fd < 0) { --- 35 unchanged lines hidden (view full) --- 291 (void) unlink(file); 292 return (0); 293 } 294 ack(); 295 return (1); 296} 297 298static int |
304noresponse() | 299noresponse(void) |
305{ 306 char resp; 307 308 if (read(1, &resp, 1) != 1) { 309 frecverr("lost connection in noresponse()"); 310 /*NOTREACHED*/ 311 } 312 if (resp == '\0') 313 return(0); 314 return(1); 315} 316 317/* 318 * Check to see if there is enough space on the disk for size bytes. 319 * 1 == OK, 0 == Not OK. 320 */ 321static int | 300{ 301 char resp; 302 303 if (read(1, &resp, 1) != 1) { 304 frecverr("lost connection in noresponse()"); 305 /*NOTREACHED*/ 306 } 307 if (resp == '\0') 308 return(0); 309 return(1); 310} 311 312/* 313 * Check to see if there is enough space on the disk for size bytes. 314 * 1 == OK, 0 == Not OK. 315 */ 316static int |
322chksize(size) 323 int size; | 317chksize(int size) |
324{ 325 int spacefree; 326 struct statfs sfb; 327 328 if (statfs(".", &sfb) < 0) { 329 syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); 330 return (1); 331 } 332 spacefree = sfb.f_bavail * (sfb.f_bsize / 512); 333 size = (size + 511) / 512; 334 if (minfree + size > spacefree) 335 return(0); 336 return(1); 337} 338 339static int | 318{ 319 int spacefree; 320 struct statfs sfb; 321 322 if (statfs(".", &sfb) < 0) { 323 syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); 324 return (1); 325 } 326 spacefree = sfb.f_bavail * (sfb.f_bsize / 512); 327 size = (size + 511) / 512; 328 if (minfree + size > spacefree) 329 return(0); 330 return(1); 331} 332 333static int |
340read_number(fn) 341 char *fn; | 334read_number(const char *fn) |
342{ 343 char lin[80]; 344 register FILE *fp; 345 346 if ((fp = fopen(fn, "r")) == NULL) 347 return (0); 348 if (fgets(lin, 80, fp) == NULL) { 349 fclose(fp); 350 return (0); 351 } 352 fclose(fp); 353 return (atoi(lin)); 354} 355 356/* 357 * Remove all the files associated with the current job being transfered. 358 */ 359static void | 335{ 336 char lin[80]; 337 register FILE *fp; 338 339 if ((fp = fopen(fn, "r")) == NULL) 340 return (0); 341 if (fgets(lin, 80, fp) == NULL) { 342 fclose(fp); 343 return (0); 344 } 345 fclose(fp); 346 return (atoi(lin)); 347} 348 349/* 350 * Remove all the files associated with the current job being transfered. 351 */ 352static void |
360rcleanup(signo) 361 int signo; | 353rcleanup(int signo __unused) |
362{ 363 if (tfname[0] && strchr(tfname, '/') == NULL) 364 (void) unlink(tfname); 365 if (dfname[0] && strchr(dfname, '/') == NULL) { 366 do { 367 do 368 (void) unlink(dfname); 369 while (dfname[2]-- != 'A'); --- 49 unchanged lines hidden --- | 354{ 355 if (tfname[0] && strchr(tfname, '/') == NULL) 356 (void) unlink(tfname); 357 if (dfname[0] && strchr(dfname, '/') == NULL) { 358 do { 359 do 360 (void) unlink(dfname); 361 while (dfname[2]-- != 'A'); --- 49 unchanged lines hidden --- |