From nobody@FreeBSD.org  Tue May 13 20:55:33 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 35D34501
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 May 2014 20:55:33 +0000 (UTC)
Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by mx1.freebsd.org (Postfix) with ESMTPS id 097782DD8
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 May 2014 20:55:33 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s4DKtWww078941
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 May 2014 20:55:32 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s4DKtWnm078940;
	Tue, 13 May 2014 20:55:32 GMT
	(envelope-from nobody)
Message-Id: <201405132055.s4DKtWnm078940@cgiserv.freebsd.org>
Date: Tue, 13 May 2014 20:55:32 GMT
From: David Mackay <davidjx8p@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] amd(8) is missing an option to prevent daemonise
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         189785
>Category:       bin
>Synopsis:       [PATCH] amd(8) is missing an option to prevent daemonise
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 13 21:00:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     David Mackay
>Release:        11.0-CURRENT
>Organization:
N/A
>Environment:
FreeBSD bigbertha-fbsd 11.0-CURRENT FreeBSD 11.0-CURRENT #0 574a744(master): Sat May  3 11:43:10 BST 2014     root@bigbertha-fbsd:/usr/obj/usr/src/sys/BIGBERTHA  amd64
>Description:
amd(8) should provide a command-line option that will tell it not to daemonise. This is necessary for running under e.g. daemontools/runit supervision.
>How-To-Repeat:
N/A
>Fix:
See the attached patch. It adds a command-line-option to prevent it daemonising.

Patch attached with submission follows:

diff --git a/contrib/amd/amd/amd.c b/contrib/amd/amd/amd.c
index 3fc25f8..09edda3 100644
--- a/contrib/amd/amd/amd.c
+++ b/contrib/amd/amd/amd.c
@@ -546,7 +546,7 @@ main(int argc, char *argv[])
   }
 #endif /* HAVE_MAP_NIS */
 
-  if (!amuDebug(D_DAEMON))
+  if ((!amuDebug(D_DAEMON)) && (!gopt.nodaemon))
     ppid = daemon_mode();
 
   /*
diff --git a/contrib/amd/amd/amd.h b/contrib/amd/amd/amd.h
index 0e371b7..0f4bf38 100644
--- a/contrib/amd/amd/amd.h
+++ b/contrib/amd/amd/amd.h
@@ -281,6 +281,7 @@ struct amu_global_options {
   char *mount_type;		/* mount type for map */
   char *debug_mtab_file;        /* path for the mtab file during debug mode */
   u_int flags;			/* various CFM_* flags */
+  int nodaemon;                 /* prevents forking into background if 1 */
 
 #define AMU_TYPE_NONE -1	/* for amfs_auto_{timeo,retrans,toplvl} */
 #define AMU_TYPE_UDP 0		/* for amfs_auto_{timeo,retrans,toplvl} */
diff --git a/contrib/amd/amd/get_args.c b/contrib/amd/amd/get_args.c
index 8f743e6..a479a1b 100644
--- a/contrib/amd/amd/get_args.c
+++ b/contrib/amd/amd/get_args.c
@@ -131,7 +131,7 @@ show_usage(void)
 \t[-k kernel_arch] [-l logfile%s\n\
 \t[-t timeout.retrans] [-w wait_timeout] [-A arch] [-C cluster_name]\n\
 \t[-o op_sys_ver] [-O op_sys_name]\n\
-\t[-F conf_file] [-T conf_tag]", am_get_progname(),
+\t[-F conf_file] [-T conf_tag] [-N nodaemon]", am_get_progname(),
 #ifdef HAVE_SYSLOG
 # ifdef LOG_DAEMON
 	  "|\"syslog[:facility]\"]"
@@ -162,7 +162,7 @@ get_args(int argc, char *argv[])
 {
   int opt_ch, i;
   FILE *fp = stdin;
-  char getopt_arguments[] = "+nprvSa:c:d:k:l:o:t:w:x:y:C:D:F:T:O:HA:";
+  char getopt_arguments[] = "+nprvSNa:c:d:k:l:o:t:w:x:y:C:D:F:T:O:HA:";
   char *getopt_args;
   int print_version = 0;	/* 1 means we should print version info */
 
@@ -294,6 +294,10 @@ get_args(int argc, char *argv[])
       exit(1);
       break;
 
+    case 'N':
+      gopt.nodaemon = 1;
+      break;
+
     case 'O':
       gopt.op_sys = optarg;
       break;


>Release-Note:
>Audit-Trail:
>Unformatted:
