From 5b35e40e54a14d1a0fe4bc01b22c04066cb36b66 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 1 Dec 2007 14:46:07 +0100 Subject: [PATCH] add option to prevent daemonization Signed-off-by: Pierre Habouzit --- main-postlicyd.c | 9 +++++++-- main-srsd.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main-postlicyd.c b/main-postlicyd.c index f9b96f5..51f56ef 100644 --- a/main-postlicyd.c +++ b/main-postlicyd.c @@ -252,6 +252,7 @@ void usage(void) "Options:\n" " -l port to listen to\n" " -p file to write our pid to\n" + " -f stay in foreground\n" , stderr); } @@ -264,10 +265,11 @@ int main(int argc, char *argv[]) .sin_addr = { htonl(INADDR_LOOPBACK) }, }; const char *pidfile = NULL; + bool daemonize = true; int port = DEFAULT_PORT; int sock = -1; - for (int c = 0; (c = getopt(argc, argv, "h" "l:p:")) >= 0; ) { + for (int c = 0; (c = getopt(argc, argv, "hf" "l:p:")) >= 0; ) { switch (c) { case 'p': pidfile = optarg; @@ -275,6 +277,9 @@ int main(int argc, char *argv[]) case 'l': port = atoi(optarg); break; + case 'f': + daemonize = false; + break; default: usage(); return EXIT_FAILURE; @@ -296,7 +301,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (daemon_detach() < 0) { + if (daemonize && daemon_detach() < 0) { syslog(LOG_CRIT, "unable to fork"); return EXIT_FAILURE; } diff --git a/main-srsd.c b/main-srsd.c index 0bf5bae..c354924 100644 --- a/main-srsd.c +++ b/main-srsd.c @@ -221,6 +221,7 @@ void usage(void) " (default: "STR(DEFAULT_DECODER_PORT)")\n" " -p file to write our pid to\n" " -u unsafe mode: don't drop privilegies\n" + " -f stay in foreground\n" , stderr); } @@ -362,6 +363,7 @@ static srs_t *srs_read_secrets(const char *sfile) int main(int argc, char *argv[]) { bool unsafe = false; + bool daemonize = true; int port_enc = DEFAULT_ENCODER_PORT; int port_dec = DEFAULT_DECODER_PORT; const char *pidfile = NULL; @@ -369,11 +371,14 @@ int main(int argc, char *argv[]) int res; srs_t *srs; - for (int c = 0; (c = getopt(argc, argv, "hu" "e:d:p:")) >= 0; ) { + for (int c = 0; (c = getopt(argc, argv, "hfu" "e:d:p:")) >= 0; ) { switch (c) { case 'e': port_enc = atoi(optarg); break; + case 'f': + daemonize = false; + break; case 'd': port_dec = atoi(optarg); break; @@ -409,7 +414,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (daemon_detach() < 0) { + if (daemonize && daemon_detach() < 0) { syslog(LOG_CRIT, "unable to fork"); return EXIT_FAILURE; } -- 2.20.1