diff options
author | Dustin Sallings <dustin@spy.net> | 2009-01-19 23:45:38 +0000 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-01-20 11:23:14 -0800 |
commit | 2c196ed6cacfd3eea845a3b9a5758a698096d97b (patch) | |
tree | dda6ba0ad959dc58e60f95f4f5f14952fae8ff1c /daemon.c | |
parent | ad00048ad5373ad62c96c47845c3221ab47eaa7e (diff) | |
download | memcached-2c196ed6cacfd3eea845a3b9a5758a698096d97b.tar.gz |
Build fixes for ubuntu 8.10/64.
gcc seems to have been wise to all of the syscalls being cast to void
to avoid doing real result checking in unlikely errors.
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -35,6 +35,7 @@ #endif #include <fcntl.h> +#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -56,15 +57,33 @@ int daemonize(int nochdir, int noclose) if (setsid() == -1) return (-1); - if (nochdir == 0) - (void)chdir("/"); + if (nochdir == 0) { + if(chdir("/") != 0) { + perror("chdir"); + return (-1); + } + } if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > STDERR_FILENO) - (void)close(fd); + if(dup2(fd, STDIN_FILENO) < 0) { + perror("dup2 stdin"); + return (-1); + } + if(dup2(fd, STDOUT_FILENO) < 0) { + perror("dup2 stdout"); + return (-1); + } + if(dup2(fd, STDERR_FILENO) < 0) { + perror("dup2 stderr"); + return (-1); + } + + if (fd > STDERR_FILENO) { + if(close(fd) < 0) { + perror("close"); + return (-1); + } + } } return (0); } |