1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(DOSCCS) && !defined(lint)
8: static char sccsid[] = "@(#)startdaemon.c 5.1.2 (2.11BSD GTE) 1996/3/22";
9: #endif
10:
11: /*
12: * Tell the printer daemon that there are new files in the spool directory.
13: */
14:
15: #include <stdio.h>
16: #include <sys/errno.h>
17: #include <sys/signal.h>
18: #include <sys/types.h>
19: #include <sys/socket.h>
20: #include <sys/un.h>
21: #include "lp.local.h"
22:
23: startdaemon(printer)
24: char *printer;
25: {
26: struct sockaddr_un sun;
27: register int s, n;
28: char buf[BUFSIZ];
29:
30: s = socket(AF_UNIX, SOCK_STREAM, 0);
31: if (s < 0) {
32: extern errno;
33:
34: if (errno == EPROTONOSUPPORT) {
35: char current[40];
36: char *cp;
37: FILE *fp;
38:
39: if ((fp = fopen(MASTERLOCK, "r")) == NULL) {
40: perr("fopen");
41: return(0);
42: }
43: cp = current;
44: while ((*cp = getc(fp)) != EOF && *cp != '\n')
45: cp++;
46: *cp = '\0';
47: if (kill(atoi(current), SIGUSR1)) {
48: perr("kill");
49: return(0);
50: }
51: return(1);
52: }
53: perr("socket");
54: return(0);
55: }
56: sun.sun_family = AF_UNIX;
57: strcpy(sun.sun_path, SOCKETNAME);
58: if (connect(s, &sun, strlen(sun.sun_path) + 2) < 0) {
59: perr("connect");
60: (void) close(s);
61: return(0);
62: }
63: (void) sprintf(buf, "\1%s\n", printer);
64: n = strlen(buf);
65: if (write(s, buf, n) != n) {
66: perr("write");
67: (void) close(s);
68: return(0);
69: }
70: if (read(s, buf, 1) == 1) {
71: if (buf[0] == '\0') { /* everything is OK */
72: (void) close(s);
73: return(1);
74: }
75: putchar(buf[0]);
76: }
77: while ((n = read(s, buf, sizeof(buf))) > 0)
78: fwrite(buf, 1, n, stdout);
79: (void) close(s);
80: return(0);
81: }
82:
83: static
84: perr(msg)
85: char *msg;
86: {
87: extern char *name;
88:
89: printf("%s: %s: %s\n", name, msg, strerror(errno));
90: }
Defined functions
perr
defined in line
83; used 5 times
Defined variables
sccsid
defined in line
8;
never used