From 14b93b9ebbe6a16c9ffe7be5491f56fa0c564f85 Mon Sep 17 00:00:00 2001 From: Caleb Callaway Date: Sat, 17 Aug 2013 23:26:44 -0700 Subject: -n switch for nslcd (prevents process from forking) --- nslcd/nslcd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'nslcd/nslcd.c') diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 8cc29c6..59323eb 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -81,6 +81,9 @@ /* flag to indicate if we are in debugging mode */ static int nslcd_debugging = 0; +/* flag to indicate we shouldn't daemonize */ +static int nslcd_nofork = 0; + /* flag to indicate user requested the --check option */ static int nslcd_checkonly = 0; @@ -126,6 +129,7 @@ static void display_usage(FILE *fp, const char *program_name) fprintf(fp, "Name Service LDAP connection daemon.\n"); fprintf(fp, " -c, --check check if the daemon already is running\n"); fprintf(fp, " -d, --debug don't fork and print debugging to stderr\n"); + fprintf(fp, " -n, --nofork don't fork\n"); fprintf(fp, " --help display this help and exit\n"); fprintf(fp, " --version output version information and exit\n"); fprintf(fp, "\n" "Report bugs to <%s>.\n", PACKAGE_BUGREPORT); @@ -135,11 +139,12 @@ static void display_usage(FILE *fp, const char *program_name) static struct option const nslcd_options[] = { {"check", no_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'd'}, + {"nofork", no_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, 0, NULL, 0} }; -#define NSLCD_OPTIONSTRING "cdhV" +#define NSLCD_OPTIONSTRING "cndhV" /* parse command line options and save settings in struct */ static void parse_cmdline(int argc, char *argv[]) @@ -156,6 +161,9 @@ static void parse_cmdline(int argc, char *argv[]) nslcd_debugging++; log_setdefaultloglevel(LOG_DEBUG); break; + case 'n': /* -n, --nofork don't fork */ + nslcd_nofork++; + break; case 'h': /* --help display this help and exit */ display_usage(stdout, argv[0]); exit(EXIT_SUCCESS); @@ -697,7 +705,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } /* daemonize */ - if ((!nslcd_debugging) && (daemon(0, 0) < 0)) + if ((!nslcd_debugging) && (!nslcd_nofork) && (daemon(0, 0) < 0)) { log_log(LOG_ERR, "unable to daemonize: %s", strerror(errno)); exit(EXIT_FAILURE); -- cgit v1.2.3