1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)startdaemon.c 5.7 (Berkeley) 03/02/91"; 10 #endif /* not lint */ 11 12 /* 13 * Tell the printer daemon that there are new files in the spool directory. 14 */ 15 16 #include <sys/types.h> 17 #include <sys/socket.h> 18 #include <sys/un.h> 19 #include <stdio.h> 20 #include "lp.local.h" 21 #include "pathnames.h" 22 23 startdaemon(printer) 24 char *printer; 25 { 26 struct sockaddr_un sun; 27 register int s, n; 28 char buf[BUFSIZ]; 29 static void perr(); 30 31 s = socket(AF_UNIX, SOCK_STREAM, 0); 32 if (s < 0) { 33 perr("socket"); 34 return(0); 35 } 36 sun.sun_family = AF_UNIX; 37 strcpy(sun.sun_path, _PATH_SOCKETNAME); 38 if (connect(s, (struct sockaddr *)&sun, strlen(sun.sun_path) + 2) < 0) { 39 perr("connect"); 40 (void) close(s); 41 return(0); 42 } 43 (void) sprintf(buf, "\1%s\n", printer); 44 n = strlen(buf); 45 if (write(s, buf, n) != n) { 46 perr("write"); 47 (void) close(s); 48 return(0); 49 } 50 if (read(s, buf, 1) == 1) { 51 if (buf[0] == '\0') { /* everything is OK */ 52 (void) close(s); 53 return(1); 54 } 55 putchar(buf[0]); 56 } 57 while ((n = read(s, buf, sizeof(buf))) > 0) 58 fwrite(buf, 1, n, stdout); 59 (void) close(s); 60 return(0); 61 } 62 63 static void 64 perr(msg) 65 char *msg; 66 { 67 extern int errno; 68 extern char *name; 69 char *strerror(); 70 71 (void)printf("%s: %s: %s\n", name, msg, strerror(errno)); 72 } 73