diff options
author | Caleb Callaway <enlightened.despot@gmail.com> | 2013-08-18 08:26:44 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2013-08-18 11:51:02 +0200 |
commit | 14b93b9ebbe6a16c9ffe7be5491f56fa0c564f85 (patch) | |
tree | b3ebc00257891c64416554a31bfc27d3f80b4ed5 /nslcd/nslcd.c | |
parent | 8a3f0f51b2406e6ee9537fdc96cadc0d3fa2194c (diff) |
-n switch for nslcd (prevents process from forking)
Diffstat (limited to 'nslcd/nslcd.c')
-rw-r--r-- | nslcd/nslcd.c | 12 |
1 files changed, 10 insertions, 2 deletions
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); |