The branch stable/13 has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c7460134fb26bd41ed8da0f666b445d705e4cff2

commit c7460134fb26bd41ed8da0f666b445d705e4cff2
Author:     Chris Rees <[email protected]>
AuthorDate: 2021-04-03 17:51:56 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
CommitDate: 2026-03-04 14:46:05 +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
    
    (cherry picked from commit 3c6366067036d4573528309a0a4d3b52e2a76ae7)
---
 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 dbd8ee9b797c..aaab2923fd48 100644
--- a/usr.sbin/lpr/lpd/lpd.8
+++ b/usr.sbin/lpr/lpd/lpd.8
@@ -107,6 +107,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 21e8997bd87d..19456c9406df 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -102,6 +102,7 @@ static char sccsid[] = "@(#)lpd.c   8.7 (Berkeley) 5/10/95";
 
 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);
@@ -150,7 +151,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 */
@@ -182,6 +183,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) */ 
@@ -262,12 +266,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,
@@ -930,9 +938,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);
 }

Reply via email to