X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udevd.c;h=8423278d6cca0bc2715656469f1a2d67c94a73fc;hb=8aafc06d943e98dfa4ff8410eb85686e49feccbf;hp=9242acce315ddd7c9ec9a21709f5751ccbf298d6;hpb=63cc8f049100c9b76ca4e37fc5c8976b6e92a207;p=elogind.git diff --git a/udevd.c b/udevd.c index 9242acce3..8423278d6 100644 --- a/udevd.c +++ b/udevd.c @@ -1,5 +1,5 @@ /* - * udevd.c - hotplug event serializer + * udevd.c - event listener and serializer * * Copyright (C) 2004-2005 Kay Sievers * Copyright (C) 2004 Chris Friesen @@ -54,7 +54,7 @@ static int udevd_sock; static int uevent_netlink_sock; static pid_t sid; -static int pipefds[2]; +static int pipefds[2] = {-1, -1}; static volatile int sigchilds_waiting; static volatile int run_msg_q; static volatile int sig_flag; @@ -785,7 +785,7 @@ int main(int argc, char *argv[], char *envp[]) { int maxsockplus; int retval; - int fd; + int devnull; struct sigaction act; fd_set readfds; const char *value; @@ -841,13 +841,12 @@ int main(int argc, char *argv[], char *envp[]) setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY); /* Set fds to dev/null */ - fd = open( "/dev/null", O_RDWR ); - if (fd >= 0) { - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd > 2) - close(fd); + devnull = open( "/dev/null", O_RDWR ); + if (devnull > 0) { + dup2(devnull, STDIN_FILENO); + dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDERR_FILENO); + close(devnull); } else err("error opening /dev/null %s", strerror(errno)); @@ -1012,6 +1011,11 @@ int main(int argc, char *argv[], char *envp[]) } exit: + if (pipefds[0] > 0) + close(pipefds[0]); + if (pipefds[1] > 0) + close(pipefds[1]); + if (udevd_sock > 0) close(udevd_sock);