- fix usage message to current reality.
- pull over "lpd [port]" code from freebsd's lpr code. - use posix signal handling.
This commit is contained in:
parent
d0dc3a7168
commit
3f207f4f5a
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: lpd.8,v 1.16 1999/12/11 01:59:43 mrg Exp $
|
.\" $NetBSD: lpd.8,v 1.17 2000/04/10 08:09:33 mrg Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1983, 1991, 1993
|
.\" Copyright (c) 1983, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
@ -44,6 +44,7 @@
|
||||||
.Op Fl dlsr
|
.Op Fl dlsr
|
||||||
.Op Fl n Ar maxchild
|
.Op Fl n Ar maxchild
|
||||||
.Op Fl w Ar maxwait
|
.Op Fl w Ar maxwait
|
||||||
|
.Op port
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm Lpd
|
.Nm Lpd
|
||||||
is the line printer daemon (spool area handler) and is normally invoked
|
is the line printer daemon (spool area handler) and is normally invoked
|
||||||
|
@ -120,6 +121,15 @@ the connection is closed and a message logged. The default is
|
||||||
120 seconds.
|
120 seconds.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
|
If the
|
||||||
|
.Op port
|
||||||
|
parameter is passed,
|
||||||
|
.Nm
|
||||||
|
listens on this port instead of the usual
|
||||||
|
.Dq printer/tcp
|
||||||
|
port from
|
||||||
|
.Pa /etc/services .
|
||||||
|
.Pp
|
||||||
Access control is provided by two means.
|
Access control is provided by two means.
|
||||||
First, all requests must come from one of the machines listed in
|
First, all requests must come from one of the machines listed in
|
||||||
the file
|
the file
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: lpd.c,v 1.21 2000/02/24 06:33:48 itojun Exp $ */
|
/* $NetBSD: lpd.c,v 1.22 2000/04/10 08:09:33 mrg Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1983, 1993, 1994
|
* Copyright (c) 1983, 1993, 1994
|
||||||
|
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993, 1994\n\
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
|
static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: lpd.c,v 1.21 2000/02/24 06:33:48 itojun Exp $");
|
__RCSID("$NetBSD: lpd.c,v 1.22 2000/04/10 08:09:33 mrg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -133,16 +133,17 @@ main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
{
|
{
|
||||||
int f, funix, *finet, options, fromlen;
|
|
||||||
fd_set defreadfds;
|
fd_set defreadfds;
|
||||||
struct sockaddr_un un, fromunix;
|
struct sockaddr_un un, fromunix;
|
||||||
struct sockaddr_storage frominet;
|
struct sockaddr_storage frominet;
|
||||||
int omask, lfd, errs, i;
|
sigset_t nmask, omask;
|
||||||
|
int lfd, errs, i, f, funix, *finet;
|
||||||
int child_max = 32; /* more then enough to hose the system */
|
int child_max = 32; /* more then enough to hose the system */
|
||||||
|
int options = 0;
|
||||||
|
struct servent *sp, serv;
|
||||||
|
|
||||||
euid = geteuid(); /* these shouldn't be different */
|
euid = geteuid(); /* these shouldn't be different */
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
options = 0;
|
|
||||||
gethostname(host, sizeof(host));
|
gethostname(host, sizeof(host));
|
||||||
host[sizeof(host) - 1] = '\0';
|
host[sizeof(host) - 1] = '\0';
|
||||||
name = argv[0];
|
name = argv[0];
|
||||||
|
@ -181,9 +182,28 @@ main(argc, argv)
|
||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
if (errs || argc != 0)
|
if (errs)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
switch (argc) {
|
||||||
|
case 1:
|
||||||
|
if ((i = atoi(argv[0])) == 0)
|
||||||
|
usage();
|
||||||
|
if (i < 0 || i > USHRT_MAX)
|
||||||
|
errx(1, "port # %d is invalid", i);
|
||||||
|
|
||||||
|
serv.s_port = htons(i);
|
||||||
|
sp = &serv;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
sp = getservbyname("printer", "tcp");
|
||||||
|
if (sp == NULL)
|
||||||
|
errx(1, "printer/tcp: unknown service");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
/*
|
/*
|
||||||
* Set up standard environment by detaching from the parent.
|
* Set up standard environment by detaching from the parent.
|
||||||
|
@ -226,8 +246,15 @@ main(argc, argv)
|
||||||
syslog(LOG_ERR, "socket: %m");
|
syslog(LOG_ERR, "socket: %m");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#define mask(s) (1 << ((s) - 1))
|
|
||||||
omask = sigblock(mask(SIGHUP)|mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
|
sigemptyset(&nmask);
|
||||||
|
sigaddset(&nmask, SIGHUP);
|
||||||
|
sigaddset(&nmask, SIGINT);
|
||||||
|
sigaddset(&nmask, SIGQUIT);
|
||||||
|
sigaddset(&nmask, SIGTERM);
|
||||||
|
sigprocmask(SIG_BLOCK, &nmask, &omask);
|
||||||
|
|
||||||
|
(void) umask(07);
|
||||||
signal(SIGHUP, mcleanup);
|
signal(SIGHUP, mcleanup);
|
||||||
signal(SIGINT, mcleanup);
|
signal(SIGINT, mcleanup);
|
||||||
signal(SIGQUIT, mcleanup);
|
signal(SIGQUIT, mcleanup);
|
||||||
|
@ -242,7 +269,8 @@ main(argc, argv)
|
||||||
syslog(LOG_ERR, "ubind: %m");
|
syslog(LOG_ERR, "ubind: %m");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
sigsetmask(omask);
|
(void) umask(0);
|
||||||
|
sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
|
||||||
FD_ZERO(&defreadfds);
|
FD_ZERO(&defreadfds);
|
||||||
FD_SET(funix, &defreadfds);
|
FD_SET(funix, &defreadfds);
|
||||||
listen(funix, 5);
|
listen(funix, 5);
|
||||||
|
@ -263,7 +291,7 @@ main(argc, argv)
|
||||||
memset(&frominet, 0, sizeof(frominet));
|
memset(&frominet, 0, sizeof(frominet));
|
||||||
memset(&fromunix, 0, sizeof(fromunix));
|
memset(&fromunix, 0, sizeof(fromunix));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int domain, nfds, s;
|
int domain, nfds, s, fromlen;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
/* "short" so it overflows in about 2 hours */
|
/* "short" so it overflows in about 2 hours */
|
||||||
short sleeptime = 10;
|
short sleeptime = 10;
|
||||||
|
@ -288,7 +316,8 @@ main(argc, argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (FD_ISSET(funix, &readfds)) {
|
if (FD_ISSET(funix, &readfds)) {
|
||||||
domain = AF_LOCAL, fromlen = sizeof(fromunix);
|
domain = AF_LOCAL;
|
||||||
|
fromlen = sizeof(fromunix);
|
||||||
s = accept(funix,
|
s = accept(funix,
|
||||||
(struct sockaddr *)&fromunix, &fromlen);
|
(struct sockaddr *)&fromunix, &fromlen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -637,7 +666,8 @@ usage()
|
||||||
{
|
{
|
||||||
extern char *__progname; /* XXX */
|
extern char *__progname; /* XXX */
|
||||||
|
|
||||||
fprintf(stderr, "usage: %s [-d] [-l]\n", __progname);
|
fprintf(stderr, "usage: %s [-dlrs] [-n maxchild] [-w maxwait] [port]\n",
|
||||||
|
__progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue