X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=libudev%2Flibudev-monitor.c;h=96c153fbd7db27b443370272c2fd5dc2d56394e9;hb=04da95b1c4958b5015bc065e7cfeeed79cd718e0;hp=c38edddc39ff638e0e56016b49c2dc24a7a012be;hpb=ce1d6d7fb47582588cfbcf0baba0c58e42a90ca6;p=elogind.git diff --git a/libudev/libudev-monitor.c b/libudev/libudev-monitor.c index c38edddc3..96c153fbd 100644 --- a/libudev/libudev-monitor.c +++ b/libudev/libudev-monitor.c @@ -34,7 +34,6 @@ * Connects to a device event source. */ -/** /** * udev_monitor: * @@ -140,13 +139,12 @@ struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char util_strscpy(&udev_monitor->sun.sun_path[1], sizeof(udev_monitor->sun.sun_path)-1, socket_path); udev_monitor->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(socket_path)+1; } - udev_monitor->sock = socket(AF_LOCAL, SOCK_DGRAM, 0); + udev_monitor->sock = socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0); if (udev_monitor->sock == -1) { err(udev, "error getting socket: %m\n"); free(udev_monitor); return NULL; } - util_set_fd_cloexec(udev_monitor->sock); dbg(udev, "monitor %p created with '%s'\n", udev_monitor, socket_path); return udev_monitor; @@ -198,13 +196,12 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char if (udev_monitor == NULL) return NULL; - udev_monitor->sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); + udev_monitor->sock = socket(PF_NETLINK, SOCK_DGRAM|SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT); if (udev_monitor->sock == -1) { err(udev, "error getting socket: %m\n"); free(udev_monitor); return NULL; } - util_set_fd_cloexec(udev_monitor->sock); udev_monitor->snl.nl_family = AF_NETLINK; udev_monitor->snl.nl_groups = group; @@ -337,7 +334,7 @@ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) /* * get the address the kernel has assigned us - * it is usually, but not neccessarily the pid + * it is usually, but not necessarily the pid */ addrlen = sizeof(struct sockaddr_nl); err = getsockname(udev_monitor->sock, (struct sockaddr *)&snl, &addrlen); @@ -505,7 +502,6 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito int action_set = 0; int maj = 0; int min = 0; - int is_kernel = 0; retry: if (udev_monitor == NULL) @@ -546,10 +542,10 @@ retry: } } else if (snl.nl_groups == UDEV_MONITOR_KERNEL) { if (snl.nl_pid > 0) { - info(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n", snl.nl_pid); + info(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n", + snl.nl_pid); return NULL; } - is_kernel = 1; } } @@ -591,9 +587,8 @@ retry: } udev_device = udev_device_new(udev_monitor->udev); - if (udev_device == NULL) { + if (udev_device == NULL) return NULL; - } while (bufpos < buflen) { char *key; @@ -617,10 +612,10 @@ retry: } else if (strncmp(key, "DEVTYPE=", 8) == 0) { udev_device_set_devtype(udev_device, &key[8]); } else if (strncmp(key, "DEVNAME=", 8) == 0) { - if (is_kernel) - udev_device_set_knodename(udev_device, &key[8]); - else + if (key[8] == '/') udev_device_set_devnode(udev_device, &key[8]); + else + udev_device_set_knodename(udev_device, &key[8]); } else if (strncmp(key, "DEVLINKS=", 9) == 0) { char devlinks[UTIL_PATH_SIZE]; char *slink; @@ -631,12 +626,12 @@ retry: next = strchr(slink, ' '); while (next != NULL) { next[0] = '\0'; - udev_device_add_devlink(udev_device, slink); + udev_device_add_devlink(udev_device, slink, 0); slink = &next[1]; next = strchr(slink, ' '); } if (slink[0] != '\0') - udev_device_add_devlink(udev_device, slink); + udev_device_add_devlink(udev_device, slink, 0); } else if (strncmp(key, "DRIVER=", 7) == 0) { udev_device_set_driver(udev_device, &key[7]); } else if (strncmp(key, "ACTION=", 7) == 0) { @@ -750,7 +745,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, /* * Use custom address for target, or the default one. * - * If we send to a muticast group, we will get + * If we send to a multicast group, we will get * ECONNREFUSED, which is expected. */ if (destination != NULL) @@ -771,7 +766,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, * udev_monitor_filter_add_match_subsystem_devtype: * @udev_monitor: the monitor * @subsystem: the subsystem value to match the incoming devices against - * @devtype: the devtype value to matvh the incoming devices against + * @devtype: the devtype value to match the incoming devices against * * The filter must be installed before the monitor is switched to listening mode. *