1*12743Sralph /*	startdaemon.c	4.4	83/05/27	*/
212114Sralph /*
312114Sralph  * Tell the printer daemon that there are new files in the spool directory.
412114Sralph  */
512114Sralph 
612114Sralph #include "lp.h"
712114Sralph 
812114Sralph startdaemon()
912114Sralph {
1012114Sralph 	register int rem, i, err = 0;
1112114Sralph 	char buf[BUFSIZ];
1212114Sralph 
1312531Sralph 	rem = getport(host);
14*12743Sralph 	if (rem < 0) {
15*12743Sralph 		perr();
1612114Sralph 		return(0);
17*12743Sralph 	}
1812114Sralph 	(void) sprintf(buf, "\1%s\n", printer);
1912114Sralph 	i = strlen(buf);
2012114Sralph 	if (write(rem, buf, i) != i) {
21*12743Sralph 		perr();
2212114Sralph 		(void) close(rem);
2312114Sralph 		return(0);
2412114Sralph 	}
2512114Sralph 	while ((i = read(rem, buf, sizeof(buf))) > 0) {
2612114Sralph 		(void) fwrite(buf, 1, i, stdout);
2712114Sralph 		err++;
2812114Sralph 	}
29*12743Sralph 	if (i < 0)
30*12743Sralph 		perr();
3112114Sralph 	(void) close(rem);
3212114Sralph 	return(i == 0 && err == 0);
3312114Sralph }
34*12743Sralph 
35*12743Sralph static
36*12743Sralph perr()
37*12743Sralph {
38*12743Sralph 	extern int sys_nerr;
39*12743Sralph 	extern char *sys_errlist[];
40*12743Sralph 
41*12743Sralph 	printf("%s: ", name);
42*12743Sralph 	fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout);
43*12743Sralph 	putchar('\n');
44*12743Sralph }
45