From owner-dev-commits-src-all@freebsd.org Thu Apr 15 11:35:35 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 519475EBC3B; Thu, 15 Apr 2021 11:35:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FLcj30qnjz3mFK; Thu, 15 Apr 2021 11:35:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 040C710B74; Thu, 15 Apr 2021 11:35:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13FBZYRQ014039; Thu, 15 Apr 2021 11:35:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13FBZYQa014038; Thu, 15 Apr 2021 11:35:34 GMT (envelope-from git) Date: Thu, 15 Apr 2021 11:35:34 GMT Message-Id: <202104151135.13FBZYQa014038@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Chris Rees Subject: git: 3c6366067036 - main - lpd: Add -F flag to prevent daemonizing MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: crees X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3c6366067036d4573528309a0a4d3b52e2a76ae7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2021 11:35:35 -0000 The branch main has been updated by crees (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=3c6366067036d4573528309a0a4d3b52e2a76ae7 commit 3c6366067036d4573528309a0a4d3b52e2a76ae7 Author: Chris Rees AuthorDate: 2021-04-03 17:51:56 +0000 Commit: Chris Rees CommitDate: 2021-04-15 11:34:01 +0000 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 --- usr.sbin/lpr/lpd/lpd.8 | 11 +++++++++++ usr.sbin/lpr/lpd/lpd.c | 22 +++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8 index 2554aba2f834..c9607265ee6f 100644 --- a/usr.sbin/lpr/lpd/lpd.8 +++ b/usr.sbin/lpr/lpd/lpd.8 @@ -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 diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index f2f8994d1fee..56821d114268 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -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 +#ifdef DEBUG + Fflag++; +#endif /* - * Set up standard environment by detaching from the parent. + * Set up standard environment by detaching from the parent + * if -F not specified */ - daemon(0, 0); -#endif + 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); }