122440Sdist /* 222440Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 542801Sbostic * %sccs.include.redist.c% 622440Sdist */ 722440Sdist 813955Ssam #ifndef lint 9*50885Storek static char sccsid[] = "@(#)startdaemon.c 5.8 (Berkeley) 08/21/91"; 1034203Sbostic #endif /* not lint */ 1113955Ssam 1212114Sralph /* 1312114Sralph * Tell the printer daemon that there are new files in the spool directory. 1412114Sralph */ 1512114Sralph 1613443Sralph #include <sys/types.h> 1713443Sralph #include <sys/socket.h> 1813443Sralph #include <sys/un.h> 1937968Sbostic #include <stdio.h> 2013443Sralph #include "lp.local.h" 2137968Sbostic #include "pathnames.h" 2212114Sralph 2313443Sralph startdaemon(printer) 2413443Sralph char *printer; 2512114Sralph { 26*50885Storek struct sockaddr_un un; 2713443Sralph register int s, n; 2812114Sralph char buf[BUFSIZ]; 2946910Sbostic static void perr(); 3012114Sralph 3113443Sralph s = socket(AF_UNIX, SOCK_STREAM, 0); 3213443Sralph if (s < 0) { 3313443Sralph perr("socket"); 3412114Sralph return(0); 3512743Sralph } 36*50885Storek un.sun_family = AF_UNIX; 37*50885Storek strcpy(un.sun_path, _PATH_SOCKETNAME); 38*50885Storek if (connect(s, (struct sockaddr *)&un, strlen(un.sun_path) + 2) < 0) { 3913443Sralph perr("connect"); 4013443Sralph (void) close(s); 4113443Sralph return(0); 4213443Sralph } 4312114Sralph (void) sprintf(buf, "\1%s\n", printer); 4413443Sralph n = strlen(buf); 4513443Sralph if (write(s, buf, n) != n) { 4613443Sralph perr("write"); 4713443Sralph (void) close(s); 4812114Sralph return(0); 4912114Sralph } 5013443Sralph if (read(s, buf, 1) == 1) { 5113443Sralph if (buf[0] == '\0') { /* everything is OK */ 5213443Sralph (void) close(s); 5313443Sralph return(1); 5413443Sralph } 5513443Sralph putchar(buf[0]); 5612114Sralph } 5713443Sralph while ((n = read(s, buf, sizeof(buf))) > 0) 5813443Sralph fwrite(buf, 1, n, stdout); 5913443Sralph (void) close(s); 6013443Sralph return(0); 6112114Sralph } 6212743Sralph 6346910Sbostic static void 6413443Sralph perr(msg) 6513443Sralph char *msg; 6612743Sralph { 6742424Sbostic extern int errno; 6813443Sralph extern char *name; 6942424Sbostic char *strerror(); 7012743Sralph 7142424Sbostic (void)printf("%s: %s: %s\n", name, msg, strerror(errno)); 7212743Sralph } 73