X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudevd.c;h=0ec3c3d4ec8e87f64906ace8763e837fcc1a57c3;hb=c03180194cb62cda286efcc1563391a1408394ff;hp=2808117824905c71458466fae10648e600d374d9;hpb=4ab3c463d418c74275eb8170a87c8cf75e47d973;p=elogind.git diff --git a/udev/udevd.c b/udev/udevd.c index 280811782..0ec3c3d4e 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -402,13 +402,13 @@ static void event_run(struct event *event, bool force) worker_new(event); } -static void event_queue_insert(struct udev_device *dev) +static int event_queue_insert(struct udev_device *dev) { struct event *event; event = calloc(1, sizeof(struct event)); if (event == NULL) - return; + return -1; event->udev = udev_device_get_udev(dev); event->dev = dev; @@ -429,8 +429,10 @@ static void event_queue_insert(struct udev_device *dev) /* run all events with a timeout set immediately */ if (udev_device_get_timeout(dev) > 0) { event_run(event, true); - return; + return 0; } + + return 0; } static void worker_kill(struct udev *udev, int retain) @@ -898,10 +900,14 @@ static void static_dev_create_links(struct udev *udev, DIR *dir) unsigned int i; for (i = 0; i < ARRAY_SIZE(stdlinks); i++) { - udev_selinux_setfscreateconat(udev, dirfd(dir), stdlinks[i].link, S_IFLNK); - if (symlinkat(stdlinks[i].target, dirfd(dir), stdlinks[i].link) < 0 && errno == EEXIST) - utimensat(dirfd(dir), stdlinks[i].link, NULL, AT_SYMLINK_NOFOLLOW); - udev_selinux_resetfscreatecon(udev); + struct stat sb; + + if (stat(stdlinks[i].target, &sb) == 0) { + udev_selinux_setfscreateconat(udev, dirfd(dir), stdlinks[i].link, S_IFLNK); + if (symlinkat(stdlinks[i].target, dirfd(dir), stdlinks[i].link) < 0 && errno == EEXIST) + utimensat(dirfd(dir), stdlinks[i].link, NULL, AT_SYMLINK_NOFOLLOW); + udev_selinux_resetfscreatecon(udev); + } } } @@ -958,15 +964,10 @@ static int init_notify(const char *state) int fd = -1, r; struct msghdr msghdr; struct iovec iovec; - struct ucred *ucred; union { struct sockaddr sa; struct sockaddr_un un; } sockaddr; - union { - struct cmsghdr cmsghdr; - uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; - } control; const char *e; if (!(e = getenv("NOTIFY_SOCKET"))) { @@ -996,16 +997,6 @@ static int init_notify(const char *state) iovec.iov_base = (char*) state; iovec.iov_len = strlen(state); - memset(&control, 0, sizeof(control)); - control.cmsghdr.cmsg_level = SOL_SOCKET; - control.cmsghdr.cmsg_type = SCM_CREDENTIALS; - control.cmsghdr.cmsg_len = CMSG_LEN(sizeof(struct ucred)); - - ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr); - ucred->pid = getpid(); - ucred->uid = getuid(); - ucred->gid = getgid(); - memset(&msghdr, 0, sizeof(msghdr)); msghdr.msg_name = &sockaddr; msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e); @@ -1013,8 +1004,6 @@ static int init_notify(const char *state) msghdr.msg_namelen = sizeof(struct sockaddr_un); msghdr.msg_iov = &iovec; msghdr.msg_iovlen = 1; - msghdr.msg_control = &control; - msghdr.msg_controllen = control.cmsghdr.cmsg_len; if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) { r = -errno; @@ -1292,16 +1281,23 @@ int main(int argc, char *argv[]) f = fopen("/dev/kmsg", "w"); if (f != NULL) { - fprintf(f, "<6>udev: starting version " VERSION "\n"); + fprintf(f, "<6>udev[%u]: starting version " VERSION "\n", getpid()); fclose(f); } - /* OOM_DISABLE == -17 */ - fd = open("/proc/self/oom_adj", O_RDWR); + fd = open("/proc/self/oom_score_adj", O_RDWR); if (fd < 0) { - err(udev, "error disabling OOM: %m\n"); + /* 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, "-17", 3); + write(fd, "-1000", 5); close(fd); } @@ -1351,9 +1347,8 @@ int main(int argc, char *argv[]) dev = udev_monitor_receive_device(monitor); if (dev != NULL) - event_queue_insert(dev); - else - udev_device_unref(dev); + if (event_queue_insert(dev) < 0) + udev_device_unref(dev); } /* start new events */