122440Sdist /* 222440Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 534203Sbostic * Redistribution and use in source and binary forms are permitted 6*34936Sbostic * provided that the above copyright notice and this paragraph are 7*34936Sbostic * duplicated in all such forms and that any documentation, 8*34936Sbostic * advertising materials, and other materials related to such 9*34936Sbostic * distribution and use acknowledge that the software was developed 10*34936Sbostic * by the University of California, Berkeley. The name of the 11*34936Sbostic * University may not be used to endorse or promote products derived 12*34936Sbostic * from this software without specific prior written permission. 13*34936Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34936Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34936Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622440Sdist */ 1722440Sdist 1813955Ssam #ifndef lint 19*34936Sbostic static char sccsid[] = "@(#)startdaemon.c 5.3 (Berkeley) 06/30/88"; 2034203Sbostic #endif /* not lint */ 2113955Ssam 2212114Sralph /* 2312114Sralph * Tell the printer daemon that there are new files in the spool directory. 2412114Sralph */ 2512114Sralph 2613443Sralph #include <stdio.h> 2713443Sralph #include <sys/types.h> 2813443Sralph #include <sys/socket.h> 2913443Sralph #include <sys/un.h> 3013443Sralph #include "lp.local.h" 3112114Sralph 3213443Sralph startdaemon(printer) 3313443Sralph char *printer; 3412114Sralph { 3513443Sralph struct sockaddr_un sun; 3613443Sralph register int s, n; 3712114Sralph char buf[BUFSIZ]; 3812114Sralph 3913443Sralph s = socket(AF_UNIX, SOCK_STREAM, 0); 4013443Sralph if (s < 0) { 4113443Sralph perr("socket"); 4212114Sralph return(0); 4312743Sralph } 4413443Sralph sun.sun_family = AF_UNIX; 4513443Sralph strcpy(sun.sun_path, SOCKETNAME); 4613443Sralph if (connect(s, &sun, strlen(sun.sun_path) + 2) < 0) { 4713443Sralph perr("connect"); 4813443Sralph (void) close(s); 4913443Sralph return(0); 5013443Sralph } 5112114Sralph (void) sprintf(buf, "\1%s\n", printer); 5213443Sralph n = strlen(buf); 5313443Sralph if (write(s, buf, n) != n) { 5413443Sralph perr("write"); 5513443Sralph (void) close(s); 5612114Sralph return(0); 5712114Sralph } 5813443Sralph if (read(s, buf, 1) == 1) { 5913443Sralph if (buf[0] == '\0') { /* everything is OK */ 6013443Sralph (void) close(s); 6113443Sralph return(1); 6213443Sralph } 6313443Sralph putchar(buf[0]); 6412114Sralph } 6513443Sralph while ((n = read(s, buf, sizeof(buf))) > 0) 6613443Sralph fwrite(buf, 1, n, stdout); 6713443Sralph (void) close(s); 6813443Sralph return(0); 6912114Sralph } 7012743Sralph 7112743Sralph static 7213443Sralph perr(msg) 7313443Sralph char *msg; 7412743Sralph { 7513443Sralph extern char *name; 7612743Sralph extern int sys_nerr; 7712743Sralph extern char *sys_errlist[]; 7813443Sralph extern int errno; 7912743Sralph 8013443Sralph printf("%s: %s: ", name, msg); 8112743Sralph fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout); 8212743Sralph putchar('\n'); 8312743Sralph } 84