chiark / gitweb /
077 release
[elogind.git] / udev.c
diff --git a/udev.c b/udev.c
index 2a6e1efc9932e1699b9f0b69e3b2222a12f8a9a0..f2d6f6653c3bc167ffdf3f981798f6d0241e3a84 100644 (file)
--- a/udev.c
+++ b/udev.c
 #include <errno.h>
 #include <signal.h>
 #include <unistd.h>
+#include <syslog.h>
 
 #include "libsysfs/sysfs/libsysfs.h"
 #include "udev_libc_wrapper.h"
 #include "udev.h"
 #include "udev_utils.h"
-#include "udev_sysfs.h"
 #include "udev_version.h"
 #include "udev_rules.h"
 #include "logging.h"
@@ -71,6 +71,7 @@ int main(int argc, char *argv[], char *envp[])
        const char *devpath;
        const char *subsystem;
        struct sigaction act;
+       int devnull;
        int retval = -EINVAL;
 
        if (argc == 2 && strcmp(argv[1], "-V") == 0) {
@@ -78,7 +79,22 @@ int main(int argc, char *argv[], char *envp[])
                exit(0);
        }
 
+       /* set std fd's to /dev/null, if the kernel forks us, we don't have them at all */
+       devnull = open("/dev/null", O_RDWR);
+       if (devnull >= 0)  {
+               if (devnull != STDIN_FILENO)
+                       dup2(devnull, STDIN_FILENO);
+               if (devnull != STDOUT_FILENO)
+                       dup2(devnull, STDOUT_FILENO);
+               if (devnull != STDERR_FILENO)
+                       dup2(devnull, STDERR_FILENO);
+               if (devnull > STDERR_FILENO)
+                       close(devnull);
+       }
+
        logging_init("udev");
+       if (devnull < 0)
+               err("fatal, could not open /dev/null: %s", strerror(errno));
        udev_init_config();
        dbg("version %s", UDEV_VERSION);
 
@@ -127,10 +143,11 @@ int main(int argc, char *argv[], char *envp[])
                        if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
                                pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, action);
                        else
-                               execute_program(name_loop->name, udev.subsystem, NULL, 0, NULL);
+                               run_program(name_loop->name, udev.subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
                }
        }
 
+       udev_rules_close(&rules);
        udev_cleanup_device(&udev);
 
 exit: