X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev.c;h=f2d6f6653c3bc167ffdf3f981798f6d0241e3a84;hp=2a6e1efc9932e1699b9f0b69e3b2222a12f8a9a0;hb=731a7d6d75fa412d676fd536ea282f33296f64cb;hpb=d455b0085d65cd25915a34d84f894a4950d313a2 diff --git a/udev.c b/udev.c index 2a6e1efc9..f2d6f6653 100644 --- a/udev.c +++ b/udev.c @@ -28,12 +28,12 @@ #include #include #include +#include #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: