Description: Implement an option to run in the foreground
This introduces a -n, --nofork option that skips the deamonising step on
start-up. This may be required for running nslcd from upstart.
Origin: upstream, http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=952404da9d9085ba42005b10c2e1813e4d348c73
Origin: upstream, http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=cda6dcdc9722eb551f8698b8711ad2eae2d02ac6
Bug-Ubuntu: https://bugs.launchpad.net/bugs/806761
--- a/man/nslcd.8.xml
+++ b/man/nslcd.8.xml
@@ -104,6 +104,18 @@
+
+
+ ,
+
+
+
+ Do not fork or daemonise and run nslcd in the
+ foreground.
+
+
+
+
--- a/man/pynslcd.8.xml
+++ b/man/pynslcd.8.xml
@@ -103,6 +103,18 @@
+
+
+ ,
+
+
+
+ Do not fork or daemonise and run pynslcd in the
+ foreground.
+
+
+
+
--- 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
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"
@@ -137,11 +141,12 @@ 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[])
@@ -158,6 +163,9 @@ static void parse_cmdline(int argc,char
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);
@@ -731,7 +739,7 @@ int main(int argc,char *argv[])
for (;i>3;i--)
close(i);
/* 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);
--- a/pynslcd/pynslcd.py
+++ b/pynslcd/pynslcd.py
@@ -44,6 +44,9 @@ program_name = 'pynslcd'
# flag to indicate whether we are in debugging mode
debugging = 0
+# flag to indicate we shouldn't daemonize
+nofork = False
+
# flag to indicate user requested the --check option
checkonly = False
@@ -103,6 +106,7 @@ def display_usage(fp):
"Name Service LDAP connection daemon.\n"
" -c, --check check if the daemon already is running\n"
" -d, --debug don't fork and print debugging to stderr\n"
+ " -n, --nofork don't fork\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
"\n"
@@ -118,7 +122,7 @@ def parse_cmdline():
program_name = sys.argv[0] or program_name
try:
optlist, args = getopt.gnu_getopt(sys.argv[1:],
- 'cdhV', ('check', 'debug', 'help', 'version', ))
+ 'cdnhV', ('check', 'debug', 'nofork', 'help', 'version', ))
for flag, arg in optlist:
if flag in ('-c', '--check'):
global checkonly
@@ -126,6 +130,9 @@ def parse_cmdline():
elif flag in ('-d', '--debug'):
global debugging
debugging += 1
+ elif flag in ('-n', '--nofork'):
+ global nofork
+ nofork = True
elif flag in ('-h', '--help'):
display_usage(sys.stdout)
sys.exit(0)
@@ -309,7 +316,7 @@ if __name__ == '__main__':
config.NSLCD_PIDFILE)
sys.exit(1)
# daemonize
- if debugging:
+ if debugging or nofork:
daemon = pidfile
else:
daemon = daemon.DaemonContext(