X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudevd.c;h=dbb1e16004a54cea15206cbf3b7cd0fd42f5bf5f;hb=8b4631362f29c8b9ae8d95fd731661a5434fa2f2;hp=051e8fe527b21e0c4f92983c9156070941489744;hpb=2903820a62de1085f6b5def0fb622070805dd90b;p=elogind.git diff --git a/udev/udevd.c b/udev/udevd.c index 051e8fe52..dbb1e1600 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -47,9 +47,6 @@ #include "udev.h" #include "sd-daemon.h" -#define UDEVD_PRIORITY -4 -#define UDEV_PRIORITY -2 - static bool debug; static void log_fn(struct udev *udev, int priority, @@ -267,7 +264,6 @@ static void worker_new(struct event *event) close(worker_watch[READ_END]); udev_log_close(); udev_log_init("udevd-work"); - setpriority(PRIO_PROCESS, 0, UDEV_PRIORITY); /* set signal handlers */ memset(&act, 0x00, sizeof(act)); @@ -1106,7 +1102,6 @@ static int convert_db(struct udev *udev) int main(int argc, char *argv[]) { struct udev *udev; - int fd; FILE *f; sigset_t mask; int daemonize = false; @@ -1265,15 +1260,22 @@ int main(int argc, char *argv[]) static_dev_create_from_modules(udev); /* before opening new files, make sure std{in,out,err} fds are in a sane state */ - fd = open("/dev/null", O_RDWR); - if (fd < 0) { - fprintf(stderr, "cannot open /dev/null\n"); - err(udev, "cannot open /dev/null\n"); + if (daemonize) { + int fd; + + fd = open("/dev/null", O_RDWR); + if (fd >= 0) { + if (write(STDOUT_FILENO, 0, 0) < 0) + dup2(fd, STDOUT_FILENO); + if (write(STDERR_FILENO, 0, 0) < 0) + dup2(fd, STDERR_FILENO); + if (fd > STDERR_FILENO) + close(fd); + } else { + fprintf(stderr, "cannot open /dev/null\n"); + err(udev, "cannot open /dev/null\n"); + } } - if (write(STDOUT_FILENO, 0, 0) < 0) - dup2(fd, STDOUT_FILENO); - if (write(STDERR_FILENO, 0, 0) < 0) - dup2(fd, STDERR_FILENO); /* udevadm control socket */ if (sd_listen_fds(true) == 1 && sd_is_socket(SD_LISTEN_FDS_START, AF_LOCAL, SOCK_SEQPACKET, -1)) @@ -1306,6 +1308,7 @@ int main(int argc, char *argv[]) if (daemonize) { pid_t pid; + int fd; pid = fork(); switch (pid) { @@ -1319,10 +1322,46 @@ int main(int argc, char *argv[]) rc = 0; goto exit; } + + setsid(); + + fd = open("/proc/self/oom_score_adj", O_RDWR); + if (fd < 0) { + /* Fallback to old interface */ + fd = open("/proc/self/oom_adj", O_RDWR); + if (fd < 0) { + err(udev, "error disabling OOM: %m\n"); + } else { + /* OOM_DISABLE == -17 */ + write(fd, "-17", 3); + close(fd); + } + } else { + write(fd, "-1000", 5); + close(fd); + } } else { sd_notify(1, "READY=1"); } + f = fopen("/dev/kmsg", "w"); + if (f != NULL) { + fprintf(f, "<30>udev[%u]: starting version " VERSION "\n", getpid()); + fclose(f); + } + + if (!debug) { + int fd; + + fd = open("/dev/null", O_RDWR); + if (fd >= 0) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + close(fd); + } + } + fd_inotify = udev_watch_init(udev); if (fd_inotify < 0) { fprintf(stderr, "error initializing inotify\n"); @@ -1418,41 +1457,6 @@ int main(int argc, char *argv[]) /* if needed, convert old database from earlier udev version */ convert_db(udev); - if (!debug) { - dup2(fd, STDIN_FILENO); - dup2(fd, STDOUT_FILENO); - dup2(fd, STDERR_FILENO); - } - if (fd > STDERR_FILENO) - close(fd); - - /* set scheduling priority for the main daemon process */ - setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY); - - setsid(); - - f = fopen("/dev/kmsg", "w"); - if (f != NULL) { - fprintf(f, "<30>udev[%u]: starting version " VERSION "\n", getpid()); - fclose(f); - } - - fd = open("/proc/self/oom_score_adj", O_RDWR); - if (fd < 0) { - /* Fallback to old interface */ - fd = open("/proc/self/oom_adj", O_RDWR); - if (fd < 0) { - err(udev, "error disabling OOM: %m\n"); - } else { - /* OOM_DISABLE == -17 */ - write(fd, "-17", 3); - close(fd); - } - } else { - write(fd, "-1000", 5); - close(fd); - } - if (children_max <= 0) { int memsize = mem_size_mb();