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