1 /* startdaemon.c 4.4 83/05/27 */ 2 /* 3 * Tell the printer daemon that there are new files in the spool directory. 4 */ 5 6 #include "lp.h" 7 8 startdaemon() 9 { 10 register int rem, i, err = 0; 11 char buf[BUFSIZ]; 12 13 rem = getport(host); 14 if (rem < 0) { 15 perr(); 16 return(0); 17 } 18 (void) sprintf(buf, "\1%s\n", printer); 19 i = strlen(buf); 20 if (write(rem, buf, i) != i) { 21 perr(); 22 (void) close(rem); 23 return(0); 24 } 25 while ((i = read(rem, buf, sizeof(buf))) > 0) { 26 (void) fwrite(buf, 1, i, stdout); 27 err++; 28 } 29 if (i < 0) 30 perr(); 31 (void) close(rem); 32 return(i == 0 && err == 0); 33 } 34 35 static 36 perr() 37 { 38 extern int sys_nerr; 39 extern char *sys_errlist[]; 40 41 printf("%s: ", name); 42 fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout); 43 putchar('\n'); 44 } 45