lpd: Add -F flag to prevent daemonizing

This is necessary for use with supervision, e.g. runit.

I chose -F simply because that is what the folks at LPRng use.

Approved by:		pfg, gad, ngie
Differential Revision:	https://reviews.freebsd.org/D29566
This commit is contained in:
Chris Rees 2021-04-03 18:51:56 +01:00
parent bbf7a4e878
commit 3c63660670
2 changed files with 27 additions and 8 deletions

View File

@ -108,6 +108,17 @@ This means that
will not accept any connections from any remote
hosts, although it will still accept print requests
from all local users.
.It Fl F
By default,
.Nm
will daemonize into the background.
The
.Fl F
flag causes
.Nm
to remain in the foreground.
Logging is still performed with
.Xr syslog 3 .
.It Fl W
By default, the
.Nm

View File

@ -104,6 +104,7 @@ __FBSDID("$FreeBSD$");
int lflag; /* log requests flag */
int sflag; /* no incoming port flag */
int Fflag; /* run in foreground flag */
int from_remote; /* from remote socket */
int main(int argc, char **_argv);
@ -152,7 +153,7 @@ main(int argc, char **argv)
errx(EX_NOPERM,"must run as root");
errs = 0;
while ((i = getopt(argc, argv, "cdlpswW46")) != -1)
while ((i = getopt(argc, argv, "cdlpswFW46")) != -1)
switch (i) {
case 'c':
/* log all kinds of connection-errors to syslog */
@ -184,6 +185,9 @@ main(int argc, char **argv)
syslog(LOG_WARNING,
"NOTE: please change your lpd config to use -W");
/* FALLTHROUGH */
case 'F':
Fflag++;
break;
case 'W':
/* allow connections coming from a non-reserved port */
/* (done by some lpr-implementations for MS-Windows) */
@ -264,12 +268,16 @@ main(int argc, char **argv)
WEXITSTATUS(status));
}
#ifndef DEBUG
/*
* Set up standard environment by detaching from the parent.
*/
daemon(0, 0);
#ifdef DEBUG
Fflag++;
#endif
/*
* Set up standard environment by detaching from the parent
* if -F not specified
*/
if (Fflag == 0) {
daemon(0, 0);
}
openlog("lpd", LOG_PID, LOG_LPR);
syslog(LOG_INFO, "lpd startup: logging=%d%s%s", lflag,
@ -932,9 +940,9 @@ static void
usage(void)
{
#ifdef INET6
fprintf(stderr, "usage: lpd [-cdlsW46] [port#]\n");
fprintf(stderr, "usage: lpd [-cdlsFW46] [port#]\n");
#else
fprintf(stderr, "usage: lpd [-cdlsW] [port#]\n");
fprintf(stderr, "usage: lpd [-cdlsFW] [port#]\n");
#endif
exit(EX_USAGE);
}