#include <sys/utsname.h>
#include "udev.h"
+#include "sd-daemon.h"
#define UDEVD_PRIORITY -4
#define UDEV_PRIORITY -2
const char *devpath_old;
dev_t devnum;
bool is_block;
+ int ifindex;
};
static struct event *node_to_event(struct udev_list_node *node)
event->devpath_old = udev_device_get_devpath_old(dev);
event->devnum = udev_device_get_devnum(dev);
event->is_block = (strcmp("block", udev_device_get_subsystem(dev)) == 0);
+ event->ifindex = udev_device_get_ifindex(dev);
udev_queue_export_device_queued(udev_queue_export, dev);
info(event->udev, "seq %llu queued, '%s' '%s'\n", udev_device_get_seqnum(dev),
if (major(event->devnum) != 0 && event->devnum == loop_event->devnum && event->is_block == loop_event->is_block)
return true;
+ /* check network device ifindex */
+ if (event->ifindex != 0 && event->ifindex == loop_event->ifindex)
+ return true;
+
/* check our old name */
if (event->devpath_old != NULL && strcmp(loop_event->devpath, event->devpath_old) == 0) {
event->delaying_seqnum = loop_event->seqnum;
/* identical device event found */
if (loop_event->devpath_len == event->devpath_len) {
+ /* devices names might have changed/swapped in the meantime */
+ if (major(event->devnum) != 0 && (event->devnum != loop_event->devnum || event->is_block != loop_event->is_block))
+ continue;
+ if (event->ifindex != 0 && event->ifindex != loop_event->ifindex)
+ continue;
event->delaying_seqnum = loop_event->seqnum;
return true;
}
return memsize;
}
-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"))) {
- r = 0;
- goto finish;
- }
-
- /* Must be an abstract socket, or an absolute path */
- if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
- r = -EINVAL;
- goto finish;
- }
-
- if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
- r = -errno;
- goto finish;
- }
-
- memset(&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sa.sa_family = AF_UNIX;
- strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
-
- if (sockaddr.un.sun_path[0] == '@')
- sockaddr.un.sun_path[0] = 0;
-
- memset(&iovec, 0, sizeof(iovec));
- 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);
- if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
- 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;
- goto finish;
- }
-
- r = 0;
-
-finish:
- if (fd >= 0)
- close(fd);
-
- return r;
-}
-
int main(int argc, char *argv[])
{
struct udev *udev;
chdir("/");
umask(022);
+ /* create standard links, copy static nodes, create nodes from modules */
+ static_dev_create(udev);
+ 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) {
goto exit;
}
} else {
- init_notify("READY=1");
+ sd_notify(1, "READY=1");
}
/* set scheduling priority for the main daemon process */
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);
}
}
info(udev, "set children_max to %u\n", children_max);
- static_dev_create(udev);
- static_dev_create_from_modules(udev);
udev_rules_apply_static_dev_perms(rules);
udev_list_init(&event_list);