diff --git a/daemon/alix-usvd.c b/daemon/alix-usvd.c index c463d73..f00dccf 100644 --- a/daemon/alix-usvd.c +++ b/daemon/alix-usvd.c @@ -397,7 +397,6 @@ int main(int argc, char *argv[]) log_print(LOG_INFO, "alix-usvd started (pid: %d)", getpid()); const char *socket_path = config_get_string("global", "socket", DEFAULT_SOCKET); - unlink(socket_path); int sockfd = unix_listen(socket_path); if (sockfd < 0) exit(1); diff --git a/daemon/logging.c b/daemon/logging.c index fd0ab0b..7d7bb14 100644 --- a/daemon/logging.c +++ b/daemon/logging.c @@ -18,10 +18,12 @@ ***************************************************************************/ #include #include +#include + #include #include #include -#include +#include #include "logging.h" @@ -92,6 +94,12 @@ int log_init(const char *logfile) fprintf(stderr, "log_init(): can not open logfile"); return -1; } + + if (fcntl(fileno(log_fd), F_SETFD, FD_CLOEXEC) < 0) { + fprintf(stderr, "log_init(): fcntl(FD_CLOEXEC)"); + return -1; + } + return 0; } diff --git a/daemon/unixsocket.c b/daemon/unixsocket.c index f568213..f15ff81 100644 --- a/daemon/unixsocket.c +++ b/daemon/unixsocket.c @@ -16,8 +16,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include +#include + +#include #include #include #include @@ -33,11 +35,21 @@ int unix_listen(const char *filename) return -1; } + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { + log_print(LOG_WARN, "unix_listen(): fcntl(FD_CLOEXEC)"); + return -1; + } + struct sockaddr_un addr; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, filename, sizeof(addr.sun_path)); int len = sizeof(addr.sun_family) + strlen(addr.sun_path); + if (unlink(addr.sun_path) == -1) { + log_print(LOG_ERROR, "unix_listen: unlink()"); + return -1; + } + mode_t old_umask = umask(0077); int ret = bind(sockfd, (struct sockaddr *) &addr, len); umask(old_umask);