chiark / gitweb /
allow programs in /lib/udev called without the path
[elogind.git] / udev.c
diff --git a/udev.c b/udev.c
index d50f81ea5e586e55c5c92a7a37ee4bbf4e2fe33b..f2d6f6653c3bc167ffdf3f981798f6d0241e3a84 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -34,7 +34,6 @@
 #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"
@@ -72,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) {
@@ -79,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);
 
@@ -116,7 +131,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        udev_init_device(&udev, devpath, subsystem, action);
-       udev_rules_init(&rules, 1, 0);
+       udev_rules_init(&rules, 0);
 
        retval = udev_process_event(&rules, &udev);
 
@@ -128,7 +143,7 @@ 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
-                               run_program(name_loop->name, udev.subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_DEBUG));
+                               run_program(name_loop->name, udev.subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
                }
        }