From owner-svn-src-stable-12@freebsd.org Tue Dec 3 22:53:23 2019 Return-Path: Delivered-To: svn-src-stable-12@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 93DE61C09E5; Tue, 3 Dec 2019 22:53:23 +0000 (UTC) (envelope-from rpokala@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47SHMR3NCZz44gm; Tue, 3 Dec 2019 22:53:23 +0000 (UTC) (envelope-from rpokala@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 547FE1EE38; Tue, 3 Dec 2019 22:53:23 +0000 (UTC) (envelope-from rpokala@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xB3MrNPN010344; Tue, 3 Dec 2019 22:53:23 GMT (envelope-from rpokala@FreeBSD.org) Received: (from rpokala@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB3MrMw4010340; Tue, 3 Dec 2019 22:53:22 GMT (envelope-from rpokala@FreeBSD.org) Message-Id: <201912032253.xB3MrMw4010340@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rpokala set sender to rpokala@FreeBSD.org using -f From: Ravi Pokala Date: Tue, 3 Dec 2019 22:53:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r355365 - in stable/12/usr.sbin: rpc.lockd rpc.statd X-SVN-Group: stable-12 X-SVN-Commit-Author: rpokala X-SVN-Commit-Paths: in stable/12/usr.sbin: rpc.lockd rpc.statd X-SVN-Commit-Revision: 355365 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Dec 2019 22:53:23 -0000 Author: rpokala Date: Tue Dec 3 22:53:22 2019 New Revision: 355365 URL: https://svnweb.freebsd.org/changeset/base/355365 Log: MFC r355006: Add and document options to allow rpc.lockd and rpc.statd to run in the foreground. This allows a separate process to monitor when and how those programs exit. That process can then restart them if needed. Modified: stable/12/usr.sbin/rpc.lockd/lockd.c stable/12/usr.sbin/rpc.lockd/rpc.lockd.8 stable/12/usr.sbin/rpc.statd/rpc.statd.8 stable/12/usr.sbin/rpc.statd/statd.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/rpc.lockd/lockd.c ============================================================================== --- stable/12/usr.sbin/rpc.lockd/lockd.c Tue Dec 3 22:53:07 2019 (r355364) +++ stable/12/usr.sbin/rpc.lockd/lockd.c Tue Dec 3 22:53:22 2019 (r355365) @@ -120,6 +120,7 @@ main(int argc, char **argv) char *endptr, **hosts_bak; struct sigaction sigalarm; int grace_period = 30; + int foreground = 0; struct netconfig *nconf; int have_v6 = 1; int maxrec = RPC_MAXDATASIZE; @@ -127,7 +128,7 @@ main(int argc, char **argv) int attempt_cnt, port_len, port_pos, ret; char **port_list; - while ((ch = getopt(argc, argv, "d:g:h:p:")) != (-1)) { + while ((ch = getopt(argc, argv, "d:Fg:h:p:")) != (-1)) { switch (ch) { case 'd': debug_level = atoi(optarg); @@ -136,6 +137,9 @@ main(int argc, char **argv) /* NOTREACHED */ } break; + case 'F': + foreground = 1; + break; case 'g': grace_period = atoi(optarg); if (!grace_period) { @@ -422,7 +426,7 @@ main(int argc, char **argv) * Note that it is NOT sensible to run this program from inetd - the * protocol assumes that it will run immediately at boot time. */ - if (daemon(0, debug_level > 0)) { + if ((foreground == 0) && daemon(0, debug_level > 0)) { err(1, "cannot fork"); /* NOTREACHED */ } @@ -844,7 +848,7 @@ void usage() { errx(1, "usage: rpc.lockd [-d ]" - " [-g ] [-h ] [-p ]"); + " [-F] [-g ] [-h ] [-p ]"); } /* Modified: stable/12/usr.sbin/rpc.lockd/rpc.lockd.8 ============================================================================== --- stable/12/usr.sbin/rpc.lockd/rpc.lockd.8 Tue Dec 3 22:53:07 2019 (r355364) +++ stable/12/usr.sbin/rpc.lockd/rpc.lockd.8 Tue Dec 3 22:53:22 2019 (r355365) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 2, 2007 +.Dd November 21, 2019 .Dt RPC.LOCKD 8 .Os .Sh NAME @@ -38,6 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl d Ar debug_level +.Op Fl F .Op Fl g Ar grace period .Op Fl h Ar bindip .Op Fl p Ar port @@ -70,6 +71,17 @@ in the generation of one log line per protocol operati Higher debug levels can be specified, causing display of operation arguments and internal operations of the daemon. +.It Fl F +Run +.Nm +in the foreground, rather than going into daemon mode. +This is useful if some other process uses +.Xr fork 2 +and +.Xr exec 3 +to run +.Nm , +and wants to monitor when and how it exits. .It Fl g The .Fl g Modified: stable/12/usr.sbin/rpc.statd/rpc.statd.8 ============================================================================== --- stable/12/usr.sbin/rpc.statd/rpc.statd.8 Tue Dec 3 22:53:07 2019 (r355364) +++ stable/12/usr.sbin/rpc.statd/rpc.statd.8 Tue Dec 3 22:53:22 2019 (r355365) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 1, 2007 +.Dd November 21, 2019 .Dt RPC.STATD 8 .Os .Sh NAME @@ -38,6 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl d +.Op Fl F .Op Fl h Ar bindip .Op Fl p Ar port .Sh DESCRIPTION @@ -71,6 +72,17 @@ These messages are logged with level LOG_DEBUG and facility LOG_DAEMON. Error conditions are logged irrespective of this option, using level LOG_ERR. +.It Fl F +Run +.Nm +in the foreground, rather than going into daemon mode. +This is useful if some other process uses +.Xr fork 2 +and +.Xr exec 3 +to run +.Nm , +and wants to monitor when and how it exits. .It Fl h Ar bindip Specify specific IP addresses to bind to. This option may be specified multiple times. Modified: stable/12/usr.sbin/rpc.statd/statd.c ============================================================================== --- stable/12/usr.sbin/rpc.statd/statd.c Tue Dec 3 22:53:07 2019 (r355364) +++ stable/12/usr.sbin/rpc.statd/statd.c Tue Dec 3 22:53:22 2019 (r355365) @@ -88,15 +88,19 @@ main(int argc, char **argv) int ch, i, s; char *endptr, **hosts_bak; int have_v6 = 1; + int foreground = 0; int maxrec = RPC_MAXDATASIZE; int attempt_cnt, port_len, port_pos, ret; char **port_list; - while ((ch = getopt(argc, argv, "dh:p:")) != -1) + while ((ch = getopt(argc, argv, "dFh:p:")) != -1) switch (ch) { case 'd': debug = 1; break; + case 'F': + foreground = 1; + break; case 'h': ++nhosts; hosts_bak = hosts; @@ -287,7 +291,11 @@ main(int argc, char **argv) /* Note that it is NOT sensible to run this program from inetd - the */ /* protocol assumes that it will run immediately at boot time. */ - daemon(0, 0); + if ((foreground == 0) && daemon(0, 0) < 0) { + err(1, "cannot fork"); + /* NOTREACHED */ + } + openlog("rpc.statd", 0, LOG_DAEMON); if (debug) syslog(LOG_INFO, "Starting - debug enabled"); else syslog(LOG_INFO, "Starting"); @@ -617,7 +625,7 @@ clearout_service(void) static void usage(void) { - fprintf(stderr, "usage: rpc.statd [-d] [-h ] [-p ]\n"); + fprintf(stderr, "usage: rpc.statd [-d] [-F] [-h ] [-p ]\n"); exit(1); }