cmm: Add do-not-daemonize cmdline arg
We usually run daemons under the supervision of babysit instead of
having the daemon fork off into the background. Most daemons like
dropbear, ntpd and nmbd provide a cmdline option to prevent them for
daemonizing on startup. This change is about adding such a feature to
cmm. There appears to be no standard for naming such a cmdline option.
We decided for "-F" to be consistent with dropbear and nmbd. It is a
bit more intuitive than dnsmasq's "-k".
Change-Id: Idc33f6449fe9aa837e625b82db3d98f4a9d9e772
diff --git a/cmm/src/cmm.c b/cmm/src/cmm.c
index fe5533d..eea5a17 100644
--- a/cmm/src/cmm.c
+++ b/cmm/src/cmm.c
@@ -295,6 +295,7 @@
//struct sched_param schedParams;
struct sigaction action;
int option;
+ int daemonize = 1;
// Forward engine programmation is enabled by default
globalConf.enable = 1;
@@ -355,7 +356,7 @@
}
// Analyse the command line
- while ((option = getopt(argc, argv, "c:f:n:hv")) != -1)
+ while ((option = getopt(argc, argv, "c:f:n:Fhv")) != -1)
{
switch (option)
{
@@ -373,6 +374,9 @@
sscanf(optarg, "%u", &nf_conntrack_max);
break;
+ case 'F': // Don't daemonize
+ daemonize = 0;
+ break;
case 'h': // Print help
cmmHelp();
return 0;
@@ -393,7 +397,7 @@
}
// Daemonize the application
- daemon(0, 1);
+ if (daemonize) daemon(0, 1);
//Ensure clean termination
action.sa_handler = sig_term_hdlr;
diff --git a/cmm/src/cmm.h b/cmm/src/cmm.h
index e4371fd..0dc3217 100644
--- a/cmm/src/cmm.h
+++ b/cmm/src/cmm.h
@@ -101,6 +101,7 @@
#define cmm_help "Usage : cmm [-c command] [-f configurationfile]-h -v \n" \
"-c command \tRun cmm to send a command. Need cmm daemon to be running\n" \
"-f conffile\tTell cmm to use the following configuration file. Available in daemon mode only\n" \
+ "-F\t\tDo not daemonize i.e. fork into background\n" \
"-h \tPrint this help\n" \
"-v \tPrint cmm version\n"