|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)startdaemon.c 4.7 (Berkeley) 7/17/83";
3: #endif
4:
5: /*
6: * Tell the printer daemon that there are new files in the spool directory.
7: */
8:
9: #include <stdio.h>
10: #include <sys/types.h>
11: #include <sys/socket.h>
12: #include <sys/un.h>
13: #include "lp.local.h"
14:
15: startdaemon(printer)
16: char *printer;
17: {
18: struct sockaddr_un sun;
19: register int s, n;
20: char buf[BUFSIZ];
21:
22: s = socket(AF_UNIX, SOCK_STREAM, 0);
23: if (s < 0) {
24: perr("socket");
25: return(0);
26: }
27: sun.sun_family = AF_UNIX;
28: strcpy(sun.sun_path, SOCKETNAME);
29: if (connect(s, &sun, strlen(sun.sun_path) + 2) < 0) {
30: perr("connect");
31: (void) close(s);
32: return(0);
33: }
34: (void) sprintf(buf, "\1%s\n", printer);
35: n = strlen(buf);
36: if (write(s, buf, n) != n) {
37: perr("write");
38: (void) close(s);
39: return(0);
40: }
41: if (read(s, buf, 1) == 1) {
42: if (buf[0] == '\0') { /* everything is OK */
43: (void) close(s);
44: return(1);
45: }
46: putchar(buf[0]);
47: }
48: while ((n = read(s, buf, sizeof(buf))) > 0)
49: fwrite(buf, 1, n, stdout);
50: (void) close(s);
51: return(0);
52: }
53:
54: static
55: perr(msg)
56: char *msg;
57: {
58: extern char *name;
59: extern int sys_nerr;
60: extern char *sys_errlist[];
61: extern int errno;
62:
63: printf("%s: %s: ", name, msg);
64: fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout);
65: putchar('\n');
66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.