summaryrefslogtreecommitdiff
path: root/daemons/cmirrord/clogd.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemons/cmirrord/clogd.c')
-rw-r--r--daemons/cmirrord/clogd.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/daemons/cmirrord/clogd.c b/daemons/cmirrord/clogd.c
index 8d9a7b9..adf7a92 100644
--- a/daemons/cmirrord/clogd.c
+++ b/daemons/cmirrord/clogd.c
@@ -121,7 +121,8 @@ static void process_signals(void)
static void remove_lockfile(void)
{
- unlink(CMIRRORD_PIDFILE);
+ if (unlink(CMIRRORD_PIDFILE))
+ LOG_ERROR("Unable to remove \"" CMIRRORD_PIDFILE "\" %s", strerror(errno));
}
/*
@@ -133,6 +134,12 @@ static void daemonize(void)
{
int pid;
int status;
+ int devnull;
+
+ if ((devnull = open("/dev/null", O_RDWR)) == -1) {
+ LOG_ERROR("Can't open /dev/null: %s", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
signal(SIGTERM, &parent_exit_handler);
@@ -178,13 +185,22 @@ static void daemonize(void)
}
setsid();
- chdir("/");
+ if (chdir("/")) {
+ LOG_ERROR("Failed to chdir /: %s", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
umask(0);
- close(0); close(1); close(2);
- open("/dev/null", O_RDONLY); /* reopen stdin */
- open("/dev/null", O_WRONLY); /* reopen stdout */
- open("/dev/null", O_WRONLY); /* reopen stderr */
+ if (close(0) || close(1) || close(2)) {
+ LOG_ERROR("Failed to close terminal FDs");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((dup2(devnull, 0) < 0) || /* reopen stdin */
+ (dup2(devnull, 1) < 0) || /* reopen stdout */
+ (dup2(devnull, 2) < 0)) /* reopen stderr */
+ exit(EXIT_FAILURE);
LOG_OPEN("cmirrord", LOG_PID, LOG_DAEMON);