chiark / gitweb /
man: fix typo
[elogind.git] / udev / udevd.c
index 0ec3c3d4ec8e87f64906ace8763e837fcc1a57c3..aa2e3657f0262dd05a892255aebffcd3b66c3dbb 100644 (file)
@@ -45,6 +45,7 @@
 #include <sys/utsname.h>
 
 #include "udev.h"
+#include "sd-daemon.h"
 
 #define UDEVD_PRIORITY                 -4
 #define UDEV_PRIORITY                  -2
@@ -122,6 +123,7 @@ struct event {
        const char *devpath_old;
        dev_t devnum;
        bool is_block;
+       int ifindex;
 };
 
 static struct event *node_to_event(struct udev_list_node *node)
@@ -418,6 +420,7 @@ static int event_queue_insert(struct udev_device *dev)
        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),
@@ -485,6 +488,10 @@ static bool is_devpath_busy(struct event *event)
                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;
@@ -500,6 +507,11 @@ static bool is_devpath_busy(struct event *event)
 
                /* 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;
                }
@@ -959,66 +971,6 @@ static int mem_size_mb(void)
        return memsize;
 }
 
-static int init_notify(const char *state)
-{
-       int fd = -1, r;
-       struct msghdr msghdr;
-       struct iovec iovec;
-       union {
-               struct sockaddr sa;
-               struct sockaddr_un un;
-       } sockaddr;
-       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(&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;
-
-       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;
@@ -1146,6 +1098,10 @@ int main(int argc, char *argv[])
        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) {
@@ -1271,7 +1227,7 @@ int main(int argc, char *argv[])
                        goto exit;
                }
        } else {
-               init_notify("READY=1");
+               sd_notify(1, "READY=1");
        }
 
        /* set scheduling priority for the main daemon process */
@@ -1312,8 +1268,6 @@ int main(int argc, char *argv[])
        }
        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);