chiark / gitweb /
prepare for new HAL udevdb dump
[elogind.git] / udev.c
diff --git a/udev.c b/udev.c
index 4096b8b3485bdf53dd439bc80e5f0fa506c36160..926c4b526ab5a82dd0107af833f5cfaf8569e98b 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <unistd.h>
+#include <syslog.h>
 
 #include "libsysfs/sysfs/libsysfs.h"
 #include "udev_libc_wrapper.h"
@@ -71,6 +72,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 +80,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");
        udev_init_config();
        dbg("version %s", UDEV_VERSION);
 
@@ -115,7 +132,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        udev_init_device(&udev, devpath, subsystem, action);
-       udev_rules_init(&rules, 0);
+       udev_rules_init(&rules, 1, 0);
 
        retval = udev_process_event(&rules, &udev);
 
@@ -123,10 +140,15 @@ int main(int argc, char *argv[], char *envp[])
                struct name_entry *name_loop;
 
                dbg("executing run list");
-               list_for_each_entry(name_loop, &udev.run_list, node)
-                       execute_program(name_loop->name, udev.subsystem, NULL, 0, NULL);
+               list_for_each_entry(name_loop, &udev.run_list, node) {
+                       if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
+                               pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, action);
+                       else
+                               run_program(name_loop->name, udev.subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+               }
        }
 
+       udev_rules_close(&rules);
        udev_cleanup_device(&udev);
 
 exit: