summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFerenc Wágner <wferi@niif.hu>2015-07-08 14:41:23 +0200
committerMarian Csontos <mcsontos@redhat.com>2015-08-18 16:23:38 +0200
commit75d0e1af6394bf38549b18c8b4b7ac47d0914226 (patch)
tree7ae7c44928f803aeddf72ffe9edafa2721a39d36
parentf076f33f2da6d2825fb9adfb53f331cb78903333 (diff)
downloadlvm2-75d0e1af6394bf38549b18c8b4b7ac47d0914226.tar.gz
cmirrord: introduce the --foreground option to avoid daemonization
Also add the compulsory --help option.
-rw-r--r--daemons/cmirrord/clogd.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/daemons/cmirrord/clogd.c b/daemons/cmirrord/clogd.c
index b4736e1d3..6638843d1 100644
--- a/daemons/cmirrord/clogd.c
+++ b/daemons/cmirrord/clogd.c
@@ -15,6 +15,7 @@
#include "link_mon.h"
#include "local.h"
+#include <getopt.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
@@ -32,14 +33,49 @@ static void daemonize(void);
static void init_all(void);
static void cleanup_all(void);
-int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused)))
+static void usage (FILE *dest)
{
- daemonize();
+ fprintf (dest, "Usage: cmirrord [options]\n"
+ " -f, --foreground stay in the foreground, log to the terminal\n"
+ " -h, --help print this help\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int foreground_mode = 0;
+ struct option longopts[] = {
+ { "foreground", no_argument, NULL, 'f' },
+ { "help" , no_argument, NULL, 'h' },
+ { 0, 0, 0, 0 }
+ };
+ int opt;
+
+ while ((opt = getopt_long (argc, argv, "fh", longopts, NULL)) != -1) {
+ switch (opt) {
+ case 'f':
+ foreground_mode = 1;
+ break;
+ case 'h':
+ usage (stdout);
+ exit (0);
+ default:
+ usage (stderr);
+ exit (2);
+ }
+ }
+ if (optind < argc) {
+ usage (stderr);
+ exit (2);
+ }
+
+ if (!foreground_mode)
+ daemonize();
init_all();
/* Parent can now exit, we're ready to handle requests */
- kill(getppid(), SIGTERM);
+ if (!foreground_mode)
+ kill(getppid(), SIGTERM);
LOG_PRINT("Starting cmirrord:");
LOG_PRINT(" Built: "__DATE__" "__TIME__"\n");