8000 minix/commands/simple/lpd.c at v3.1.4 · lgqgood/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
executable file
·
368 lines (304 loc) · 6.61 KB

lpd.c

File metadata and controls

executable file
·
368 lines (304 loc) · 6.61 KB
void haunt(void)
/* Become a daemon, print jobs while there are any, exit. */
{
int fd;
if ((fd= open("/dev/tty", O_RDONLY)) != -1) {
/* We have a controlling tty! Disconnect. */
close(fd);
switch(fork()) {
case -1: fatal("can't fork");
case 0: break;
default: exit(0);
}
if ((fd= open("/dev/null", O_RDONLY)) < 0) fatal("/dev/null");
dup2(fd, 0);
close(fd);
if ((fd= open(LOG, O_WRONLY)) < 0) fatal(LOG);
dup2(fd, 1);
dup2(fd, 2);
close(fd);
setsid();
}
getcap();
do {
if ((lp= open(PRINTER, O_WRONLY)) < 0) {
/* Another lpd? */
if (errno == EBUSY) exit(0);
fatal(PRINTER);
}
while (job()) work();
close(lp);
} while (job());
}
int main(int argc, char **argv)
{
if (argc > 2) {
fprintf(stderr, "Usage: %s [path | stdin < path]\n", argv[0]);
exit(1);
}
umask(0077);
if (chdir(SPOOL) < 0) fatal(SPOOL);
if (argc == 2) spool(argv[1]);
haunt();
}
0