/* recvjob.c 4.2 83/05/16 */
* Receive printer jobs from the network, queue them and
* start the printer daemon.
char tfname
[40]; /* tmp copy of cf before linking */
char *dfname
; /* data files */
* Perform lookup for printer name or abbreviation
if ((status
= pgetent(line
, printer
)) < 0)
fatal("cannot open printer description file");
fatal("unknown printer");
if ((LF
= pgetstr("lf", &bp
)) == NULL
)
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) open(LF
, FWRONLY
|FAPPEND
, 0);
fatal("cannot chdir to %s", SD
);
if (stat(LO
, &stb
) == 0 && (stb
.st_mode
& 010)) {
putchar('\1'); /* return error code */
#define ack() (void) write(1, sp, 1);
* Read printer jobs sent by lpd and copy them to the spooling directory.
* Return the number of jobs successfully transfered.
register int size
, nfiles
;
* Read a command to tell us what to do
if ((size
= read(1, cp
, 1)) != 1) {
fatal("Lost connection");
case '\1': /* cleanup because data sent was bad */
case '\2': /* read cf file */
while (*cp
>= '0' && *cp
<= '9')
size
= size
* 10 + (*cp
++ - '0');
if (!readfile(tfname
, size
)) {
if (link(tfname
, cp
) < 0)
fatal("cannot rename %s", tfname
);
case '\3': /* read df file */
while (*cp
>= '0' && *cp
<= '9')
size
= size
* 10 + (*cp
++ - '0');
(void) readfile(dfname
= cp
, size
);
fatal("protocol screwup");
* Read files send by lpd and copy them to the spooling directory.
fd
= open(file
, FWRONLY
|FCREATE
, FILMOD
);
fatal("cannot create %s", file
);
for (i
= 0; i
< size
; i
+= BUFSIZ
) {
fatal("Lost connection");
if (err
== 0 && write(fd
, buf
, amt
) != amt
)
fatal("%s: write error", file
);
if (noresponse()) { /* file sent had bad data in it */
if (read(1, &resp
, 1) != 1)
fatal("Lost connection");
* Remove all the files associated with the current job being transfered.
while (dfname
[i
]-- != 'A');
} while (dfname
[i
-2]-- != 'd');
putchar('\1'); /* return error code */