summaryrefslogtreecommitdiff
path: root/nslcd
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2014-05-04 16:19:07 +0200
committerArthur de Jong <arthur@arthurdejong.org>2014-05-04 16:22:42 +0200
commited79110fc32aba70cf1d65979a6419abc2272625 (patch)
treee6d4a6b318df00c768bab277f8d5dce52eb8f140 /nslcd
parent18d05b01dc6a53481b67839ca0332f56bf456f1e (diff)
Log daemonising failures
This also clears errno in the main function to ensure that no incorrect errno value is logged on errors.
Diffstat (limited to 'nslcd')
-rw-r--r--nslcd/daemonize.c12
-rw-r--r--nslcd/nslcd.c1
2 files changed, 13 insertions, 0 deletions
diff --git a/nslcd/daemonize.c b/nslcd/daemonize.c
index 342c61c..0d96f73 100644
--- a/nslcd/daemonize.c
+++ b/nslcd/daemonize.c
@@ -34,6 +34,7 @@
#endif /* HAVE_PTHREAD_H */
#include "daemonize.h"
+#include "log.h"
/* the write end of a pipe that is used to signal the fact that the child
process has finished initialising (see daemonize_daemon() and
@@ -80,7 +81,10 @@ static int read_response(int fd, char *buffer, size_t bufsz)
else if ((errno == EINTR) || (errno == EAGAIN))
continue; /* ignore these errors and try again */
else
+ {
+ log_log(LOG_ERR, "read_response(): read() failed: %s", strerror(errno));
return -1;
+ }
}
return r;
}
@@ -123,17 +127,22 @@ int daemonize_daemon(void)
int i;
/* set up a pipe for communication */
if (pipe(pipefds) < 0)
+ {
+ log_log(LOG_ERR, "pipe() failed: %s", strerror(errno));
return -1;
+ }
/* set O_NONBLOCK on the write end to ensure that a call to
daemonize_ready() will not lock the application */
if ((i = fcntl(pipefds[1], F_GETFL, 0)) < 0)
{
+ log_log(LOG_ERR, "fcntl() failed: %s", strerror(errno));
close(pipefds[0]);
close(pipefds[1]);
return -1;
}
if (fcntl(pipefds[1], F_SETFL, i | O_NONBLOCK) < 0)
{
+ log_log(LOG_ERR, "fcntl() failed: %s", strerror(errno));
close(pipefds[0]);
close(pipefds[1]);
return -1;
@@ -147,6 +156,7 @@ int daemonize_daemon(void)
break;
case -1:
/* we are the parent, but have an error */
+ log_log(LOG_ERR, "fork() failed: %s", strerror(errno));
close(pipefds[0]);
close(pipefds[1]);
return -1;
@@ -158,6 +168,7 @@ int daemonize_daemon(void)
/* become process leader */
if (setsid() < 0)
{
+ log_log(LOG_ERR, "setsid() failed: %s", strerror(errno));
close(pipefds[1]);
_exit(EXIT_FAILURE);
}
@@ -169,6 +180,7 @@ int daemonize_daemon(void)
break;
case -1:
/* we are the parent, but have an error */
+ log_log(LOG_ERR, "fork() failed: %s", strerror(errno));
close(pipefds[1]);
_exit(EXIT_FAILURE);
default:
diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c
index bbe6547..ea9e4e3 100644
--- a/nslcd/nslcd.c
+++ b/nslcd/nslcd.c
@@ -705,6 +705,7 @@ int main(int argc, char *argv[])
/* daemonize */
if ((!nslcd_debugging) && (!nslcd_nofork))
{
+ errno = 0;
if (daemonize_daemon() != 0)
{
log_log(LOG_ERR, "unable to daemonize: %s", strerror(errno));