From: Kay Sievers Date: Sun, 1 Jan 2012 03:21:15 +0000 (+0100) Subject: remove mknod() logic and rely on 'devtmpfs' X-Git-Tag: 176~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=220893b3cbdbf8932f95c44811b169a8f0d33939;p=platform%2Fupstream%2Fsystemd.git remove mknod() logic and rely on 'devtmpfs' --- diff --git a/NEWS b/NEWS index b052257..f65ae0d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ udev 175 ======== +The 'devtmpfs' filesystem is required now, udev will not create or delete +device nodes anymore, it only adjusts permissions and ownership of device +nodes and maintains additional symlinks. + A writable /run directory (tmpfs) is required now for a fully functional udev. @@ -26,7 +30,7 @@ All built-in tools can be listed and tested with 'udevadm test-builtin'. The 'udevadm control --reload-rules' option has been renamed to '--reload'. It reloads the kernel module configuration. -The systemd socket files use PassCred=yes, which requires systemd +The systemd socket files use PassCredentials=yes, which requires systemd version 38. The udev build system only creates a .xz tarball now. diff --git a/extras/cdrom_id/60-cdrom_id.rules b/extras/cdrom_id/60-cdrom_id.rules index 896af34..353f522 100644 --- a/extras/cdrom_id/60-cdrom_id.rules +++ b/extras/cdrom_id/60-cdrom_id.rules @@ -9,10 +9,10 @@ ENV{DEVTYPE}!="disk", GOTO="cdrom_end" KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1" # media eject button pressed -ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $tempnode", GOTO="cdrom_end" +ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end" # import device and media properties and lock tray to # enable the receiving of media eject button events -IMPORT{program}="cdrom_id --lock-media $tempnode" +IMPORT{program}="cdrom_id --lock-media $devnode" LABEL="cdrom_end" diff --git a/extras/edd_id/61-persistent-storage-edd.rules b/extras/edd_id/61-persistent-storage-edd.rules index 1ab1be3..6b4fb8e 100644 --- a/extras/edd_id/61-persistent-storage-edd.rules +++ b/extras/edd_id/61-persistent-storage-edd.rules @@ -5,7 +5,7 @@ SUBSYSTEM!="block", GOTO="persistent_storage_edd_end" KERNEL!="sd*|hd*|cciss*", GOTO="persistent_storage_edd_end" # BIOS Enhanced Disk Device -ENV{DEVTYPE}=="disk", IMPORT{program}="edd_id --export $tempnode" +ENV{DEVTYPE}=="disk", IMPORT{program}="edd_id --export $devnode" ENV{DEVTYPE}=="disk", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}" ENV{DEVTYPE}=="partition", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}-part%n" diff --git a/extras/mtd_probe/75-probe_mtd.rules b/extras/mtd_probe/75-probe_mtd.rules index 6b0c1c2..c0e0839 100644 --- a/extras/mtd_probe/75-probe_mtd.rules +++ b/extras/mtd_probe/75-probe_mtd.rules @@ -2,7 +2,7 @@ ACTION!="add", GOTO="mtd_probe_end" -KERNEL=="mtd*ro", IMPORT{program}="mtd_probe $tempnode" +KERNEL=="mtd*ro", IMPORT{program}="mtd_probe $devnode" KERNEL=="mtd*ro", ENV{MTD_FTL}=="smartmedia", IMPORT{builtin}="kmod load sm_ftl" LABEL="mtd_probe_end" diff --git a/extras/v4l_id/60-persistent-v4l.rules b/extras/v4l_id/60-persistent-v4l.rules index edfd844..93c5ee8 100644 --- a/extras/v4l_id/60-persistent-v4l.rules +++ b/extras/v4l_id/60-persistent-v4l.rules @@ -4,7 +4,7 @@ ACTION=="remove", GOTO="persistent_v4l_end" SUBSYSTEM!="video4linux", GOTO="persistent_v4l_end" ENV{MAJOR}=="", GOTO="persistent_v4l_end" -IMPORT{program}="v4l_id $tempnode" +IMPORT{program}="v4l_id $devnode" SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id" KERNEL=="video*", ENV{ID_SERIAL}=="?*", SYMLINK+="v4l/by-id/$env{ID_BUS}-$env{ID_SERIAL}-video-index$attr{index}" diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c index b78b6c9..0864919 100644 --- a/libudev/libudev-device-private.c +++ b/libudev/libudev-device-private.c @@ -78,7 +78,6 @@ int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old, static bool device_has_info(struct udev_device *udev_device) { - struct udev *udev = udev_device_get_udev(udev_device); struct udev_list_entry *list_entry; if (udev_device_get_devlinks_list_entry(udev_device) != NULL) @@ -90,12 +89,6 @@ static bool device_has_info(struct udev_device *udev_device) return true; if (udev_device_get_tags_list_entry(udev_device) != NULL) return true; - if (udev_device_get_devnode(udev_device) != NULL && udev_device_get_knodename(udev_device) != NULL) { - size_t devlen = strlen(udev_get_dev_path(udev))+1; - - if (strcmp(&udev_device_get_devnode(udev_device)[devlen], udev_device_get_knodename(udev_device)) != 0) - return true; - } if (udev_device_get_watch_handle(udev_device) >= 0) return true; return false; @@ -142,20 +135,22 @@ int udev_device_update_db(struct udev_device *udev_device) fchmod(fileno(f), 01644); if (has_info) { - size_t devlen = strlen(udev_get_dev_path(udev))+1; struct udev_list_entry *list_entry; - if (udev_device_get_devnode(udev_device) != NULL) { - fprintf(f, "N:%s\n", &udev_device_get_devnode(udev_device)[devlen]); + if (major(udev_device_get_devnum(udev_device)) > 0) { + size_t devlen = strlen(udev_get_dev_path(udev))+1; + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device)) fprintf(f, "S:%s\n", &udev_list_entry_get_name(list_entry)[devlen]); + if (udev_device_get_devlink_priority(udev_device) != 0) + fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); + if (udev_device_get_watch_handle(udev_device) >= 0) + fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device)); } - if (udev_device_get_devlink_priority(udev_device) != 0) - fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); - if (udev_device_get_watch_handle(udev_device) >= 0) - fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device)); + if (udev_device_get_usec_initialized(udev_device) > 0) fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device)); + udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) { if (!udev_list_entry_get_num(list_entry)) continue; @@ -163,6 +158,7 @@ int udev_device_update_db(struct udev_device *udev_device) udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); } + udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device)) fprintf(f, "G:%s\n", udev_list_entry_get_name(list_entry)); } diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c index 28df7a2..e5950bb 100644 --- a/libudev/libudev-device.c +++ b/libudev/libudev-device.c @@ -57,7 +57,6 @@ struct udev_device { char *driver; char *action; char *devpath_old; - char *knodename; char *id_filename; char **envp; char *monitor_buf; @@ -161,23 +160,6 @@ static int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum) return 0; } -const char *udev_device_get_knodename(struct udev_device *udev_device) -{ - return udev_device->knodename; -} - -static int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename) -{ - free(udev_device->knodename); - udev_device->knodename = strdup(knodename); - if (udev_device->knodename == NULL) - return -ENOMEM; - /* do not overwrite the udev property with the kernel property */ - if (udev_device->devnode == NULL) - udev_device_add_property(udev_device, "DEVNAME", udev_device->knodename); - return 0; -} - const char *udev_device_get_devpath_old(struct udev_device *udev_device) { return udev_device->devpath_old; @@ -381,10 +363,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, } else if (strncmp(property, "DEVTYPE=", 8) == 0) { udev_device_set_devtype(udev_device, &property[8]); } else if (strncmp(property, "DEVNAME=", 8) == 0) { - if (property[8] == '/') - udev_device_set_devnode(udev_device, &property[8]); - else - udev_device_set_knodename(udev_device, &property[8]); + udev_device_set_devnode(udev_device, &property[8]); } else if (strncmp(property, "DEVLINKS=", 9) == 0) { char devlinks[UTIL_PATH_SIZE]; char *slink; @@ -516,10 +495,6 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) line[len-1] = '\0'; val = &line[2]; switch(line[0]) { - case 'N': - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL); - udev_device_set_devnode(udev_device, filename); - break; case 'S': util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL); udev_device_add_devlink(udev_device, filename, 0); @@ -582,7 +557,7 @@ int udev_device_read_uevent_file(struct udev_device *udev_device) else if (strncmp(line, "IFINDEX=", 8) == 0) udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10)); else if (strncmp(line, "DEVNAME=", 8) == 0) - udev_device_set_knodename(udev_device, &line[8]); + udev_device_set_devnode(udev_device, &line[8]); else if (strncmp(line, "DEVMODE=", 8) == 0) udev_device->devnode_mode = strtoul(&line[8], NULL, 8); @@ -1073,7 +1048,6 @@ UDEV_EXPORT void udev_device_unref(struct udev_device *udev_device) free(udev_device->action); free(udev_device->driver); free(udev_device->devpath_old); - free(udev_device->knodename); free(udev_device->id_filename); free(udev_device->envp); free(udev_device->monitor_buf); @@ -1152,21 +1126,10 @@ UDEV_EXPORT const char *udev_device_get_devnode(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; - if (!udev_device->info_loaded) { - udev_device_read_uevent_file(udev_device); - udev_device_read_db(udev_device, NULL); - } - - /* we might get called before we handled an event and have a db, use the kernel-provided name */ - if (udev_device->devnode == NULL && udev_device_get_knodename(udev_device) != NULL) { - char filename[UTIL_NAME_SIZE]; - - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", - udev_device_get_knodename(udev_device), NULL); - udev_device_set_devnode(udev_device, filename); + if (udev_device->devnode != NULL) return udev_device->devnode; - } - + if (!udev_device->info_loaded) + udev_device_read_uevent_file(udev_device); return udev_device->devnode; } @@ -1522,7 +1485,12 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode) { free(udev_device->devnode); - udev_device->devnode = strdup(devnode); + if (devnode[0] != '/') { + if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0) + udev_device->devnode = NULL; + } else { + udev_device->devnode = strdup(devnode); + } if (udev_device->devnode == NULL) return -ENOMEM; udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode); diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h index b86f6a8..8397669 100644 --- a/libudev/libudev-private.h +++ b/libudev/libudev-private.h @@ -83,7 +83,6 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile); int udev_device_read_uevent_file(struct udev_device *udev_device); int udev_device_set_action(struct udev_device *udev_device, const char *action); const char *udev_device_get_devpath_old(struct udev_device *udev_device); -const char *udev_device_get_knodename(struct udev_device *udev_device); const char *udev_device_get_id_filename(struct udev_device *udev_device); void udev_device_set_is_initialized(struct udev_device *udev_device); int udev_device_add_tag(struct udev_device *udev_device, const char *tag); @@ -187,7 +186,6 @@ uint64_t util_string_bloom64(const char *str); int util_create_path(struct udev *udev, const char *path); int util_create_path_selinux(struct udev *udev, const char *path); int util_delete_path(struct udev *udev, const char *path); -int util_unlink_secure(struct udev *udev, const char *filename); uid_t util_lookup_user(struct udev *udev, const char *user); gid_t util_lookup_group(struct udev *udev, const char *group); int util_resolve_subsys_kernel(struct udev *udev, const char *string, diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c index 2d7f8dc..015e6d5 100644 --- a/libudev/libudev-util-private.c +++ b/libudev/libudev-util-private.c @@ -113,23 +113,6 @@ int util_delete_path(struct udev *udev, const char *path) return err; } -/* Reset permissions on the device node, before unlinking it to make sure, - * that permissions of possible hard links will be removed too. - */ -int util_unlink_secure(struct udev *udev, const char *filename) -{ - int err; - - chown(filename, 0, 0); - chmod(filename, 0000); - err = unlink(filename); - if (errno == ENOENT) - err = 0; - if (err) - err(udev, "unlink(%s) failed: %m\n", filename); - return err; -} - uid_t util_lookup_user(struct udev *udev, const char *user) { char *endptr; diff --git a/libudev/libudev.c b/libudev/libudev.c index 93f2d8f..ca2ac5d 100644 --- a/libudev/libudev.c +++ b/libudev/libudev.c @@ -223,6 +223,10 @@ UDEV_EXPORT struct udev *udev_new(void) set_value(&udev->run_path, val); continue; } + if (strcmp(key, "udev_sys") == 0) { + set_value(&udev->sys_path, val); + continue; + } if (strcmp(key, "udev_rules") == 0) { set_value(&udev->rules_path[0], val); udev->rules_path_count = 1; @@ -237,18 +241,6 @@ UDEV_EXPORT struct udev *udev_new(void) if (env != NULL) udev_set_log_priority(udev, util_log_priority(env)); - env = getenv("UDEV_ROOT"); - if (env != NULL) { - set_value(&udev->dev_path, env); - udev_add_property(udev, "UDEV_ROOT", udev->dev_path); - } - - env = getenv("SYSFS_PATH"); - if (env != NULL) { - set_value(&udev->sys_path, env); - udev_add_property(udev, "SYSFS_PATH", udev->sys_path); - } - /* set defaults */ if (udev->dev_path == NULL) if (set_value(&udev->dev_path, "/dev") == NULL) @@ -401,8 +393,8 @@ int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *st * @udev: udev library context * * Retrieve the sysfs mount point. The default is "/sys". For - * testing purposes, it can be overridden with the environment - * variable SYSFS_PATH. + * testing purposes, it can be overridden with udev_sys= + * in the udev configuration file. * * Returns: the sys mount point **/ diff --git a/rules/rules.d/60-persistent-storage-tape.rules b/rules/rules.d/60-persistent-storage-tape.rules index b1a64ce..f2eabd9 100644 --- a/rules/rules.d/60-persistent-storage-tape.rules +++ b/rules/rules.d/60-persistent-storage-tape.rules @@ -5,7 +5,7 @@ ACTION=="remove", GOTO="persistent_storage_tape_end" # type 8 devices are "Medium Changers" -SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --sg-version=3 --export --whitelisted -d $tempnode", \ +SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --sg-version=3 --export --whitelisted -d $devnode", \ SYMLINK+="tape/by-id/scsi-$env{ID_SERIAL}" SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end" diff --git a/rules/rules.d/60-persistent-storage.rules b/rules/rules.d/60-persistent-storage.rules index 9b34033..b7da8b8 100644 --- a/rules/rules.d/60-persistent-storage.rules +++ b/rules/rules.d/60-persistent-storage.rules @@ -27,20 +27,20 @@ KERNEL=="vd*[!0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLIN KERNEL=="vd*[0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/virtio-$env{ID_SERIAL}-part%n" # ATA devices with their own "ata" kernel subsystem -KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="ata", IMPORT{program}="ata_id --export $tempnode" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="ata", IMPORT{program}="ata_id --export $devnode" # ATA devices using the "scsi" subsystem -KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $tempnode" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $devnode" # ATA/ATAPI devices (SPC-3 or later) using the "scsi" subsystem -KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $tempnode" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $devnode" # Run ata_id on non-removable USB Mass Storage (SATA/PATA disks in enclosures) -KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", ATTR{removable}=="0", SUBSYSTEMS=="usb", IMPORT{program}="ata_id --export $tempnode" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", ATTR{removable}=="0", SUBSYSTEMS=="usb", IMPORT{program}="ata_id --export $devnode" # Otherwise fall back to using usb_id for USB devices KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id" # scsi devices -KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="scsi" -KERNEL=="cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="cciss" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $devnode", ENV{ID_BUS}="scsi" +KERNEL=="cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $devnode", ENV{ID_BUS}="cciss" KERNEL=="sd*|sr*|cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" KERNEL=="sd*|cciss*", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n" @@ -49,7 +49,7 @@ KERNEL=="sd*[!0-9]|sr*", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394 KERNEL=="sd*[0-9]", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}-part%n" # scsi compat links for ATA devices -KERNEL=="sd*[!0-9]", ENV{ID_BUS}=="ata", PROGRAM="scsi_id --whitelisted --replace-whitespace -p0x80 -d$tempnode", RESULT=="?*", ENV{ID_SCSI_COMPAT}="$result", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT}" +KERNEL=="sd*[!0-9]", ENV{ID_BUS}=="ata", PROGRAM="scsi_id --whitelisted --replace-whitespace -p0x80 -d $devnode", RESULT=="?*", ENV{ID_SCSI_COMPAT}="$result", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT}" KERNEL=="sd*[0-9]", ENV{ID_SCSI_COMPAT}=="?*", SYMLINK+="disk/by-id/scsi-$env{ID_SCSI_COMPAT}-part%n" KERNEL=="mmcblk[0-9]", SUBSYSTEMS=="mmc", ATTRS{name}=="?*", ATTRS{serial}=="?*", ENV{ID_NAME}="$attr{name}", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/mmc-$env{ID_NAME}_$env{ID_SERIAL}" diff --git a/test/sys/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0/uevent b/test/sys/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0/uevent index e6caaab..22f0302 100644 --- a/test/sys/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0/uevent +++ b/test/sys/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0/uevent @@ -1,3 +1,3 @@ -DEVNAME=ttyACM0 MAJOR=166 MINOR=0 +DEVNAME=ttyACM0 diff --git a/test/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5/uevent b/test/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5/uevent index 8a871ce..ab7569d 100644 --- a/test/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5/uevent +++ b/test/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5/uevent @@ -1,3 +1,4 @@ MAJOR=8 MINOR=5 DEVTYPE=partition +DEVNAME=sda5 diff --git a/test/sys/devices/virtual/block/fake!blockdev0/uevent b/test/sys/devices/virtual/block/fake!blockdev0/uevent index 70997d3..6c472ca 100644 --- a/test/sys/devices/virtual/block/fake!blockdev0/uevent +++ b/test/sys/devices/virtual/block/fake!blockdev0/uevent @@ -1,3 +1,4 @@ MAJOR=7 MINOR=0 DEVTYPE=disk +DEVNAME=fake/blockdev0 diff --git a/test/sys/devices/virtual/misc/misc-fake1/uevent b/test/sys/devices/virtual/misc/misc-fake1/uevent index 79caac1..67faa81 100644 --- a/test/sys/devices/virtual/misc/misc-fake1/uevent +++ b/test/sys/devices/virtual/misc/misc-fake1/uevent @@ -1,2 +1,4 @@ MAJOR=4095 MINOR=1 +DEVNAME=misc-fake1 + diff --git a/test/sys/devices/virtual/misc/misc-fake89999/uevent b/test/sys/devices/virtual/misc/misc-fake89999/uevent index 10915df..53bb34a 100644 --- a/test/sys/devices/virtual/misc/misc-fake89999/uevent +++ b/test/sys/devices/virtual/misc/misc-fake89999/uevent @@ -1,2 +1,3 @@ MAJOR=4095 MINOR=89999 +DEVNAME=misc-fake89999 diff --git a/test/sys/devices/virtual/tty/console/uevent b/test/sys/devices/virtual/tty/console/uevent index 0eaf8b9..71aad75 100644 --- a/test/sys/devices/virtual/tty/console/uevent +++ b/test/sys/devices/virtual/tty/console/uevent @@ -1,2 +1,3 @@ MAJOR=5 MINOR=1 +DEVNAME=console diff --git a/test/sys/devices/virtual/tty/tty0/uevent b/test/sys/devices/virtual/tty/tty0/uevent index 11692de..f338919 100644 --- a/test/sys/devices/virtual/tty/tty0/uevent +++ b/test/sys/devices/virtual/tty/tty0/uevent @@ -1,2 +1,3 @@ MAJOR=4 MINOR=0 +DEVNAME=tty0 diff --git a/test/sys/devices/virtual/tty/tty33/uevent b/test/sys/devices/virtual/tty/tty33/uevent index 70a8268..737826b 100644 --- a/test/sys/devices/virtual/tty/tty33/uevent +++ b/test/sys/devices/virtual/tty/tty33/uevent @@ -1,2 +1,3 @@ MAJOR=4 MINOR=33 +DEVNAME=tty33 diff --git a/test/udev-test.pl.in b/test/udev-test.pl.in index 0befc7b..0505501 100755 --- a/test/udev-test.pl.in +++ b/test/udev-test.pl.in @@ -25,14 +25,13 @@ my $sysfs = "test/sys/"; my $udev_bin = "udev/test-udev"; my $valgrind = 0; my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; -my $udev_root = "udev-root/"; +my $udev_root = "udev-root"; my $udev_conf = "udev-test.conf"; my $udev_rules = "udev-test.rules"; my @tests = ( { desc => "no rules", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "sda" , exp_rem_error => "yes", @@ -42,7 +41,6 @@ EOF }, { desc => "label test of scsi disc", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "boot_disk" , rules => < "label test of scsi disc", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "boot_disk" , rules => < "label test of scsi disc", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "boot_disk" , rules => < "label test of scsi partition", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "boot_disk1" , rules => < "label test of pattern match", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "boot_disk1" , rules => < "label test of multiple sysfs files", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "boot_disk1" , rules => < "label test of max sysfs files (skip invalid rule)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "boot_disk1" , rules => < "catch device by *", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem/0" , rules => < "catch device by * - take 2", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem/0" , rules => < "catch device by ?", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem/0" , rules => < "catch device by character class", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem/0" , rules => < "replace kernel name", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "Handle comment lines in config file (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "Handle comment lines in config file with whitespace (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "Handle whitespace only lines (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "whitespace" , rules => < "Handle empty lines in config file (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "Handle backslashed multi lines in config file (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "preserve backslashes, if they are not for a newline", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "aaa", rules => < "Handle stupid backslashed multi lines in config file (and replace kernel name)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "subdirectory handling", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "sub/direct/ory/modem" , rules => < "parent device name match of scsi partition", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "first_disk5" , rules => < "test substitution chars", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , rules => < "import of shell-value file", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "subdir/err/node" , rules => < "import of shell-value returned from program", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node12345678", rules => < "sustitution of sysfs value (%s{file})", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "disk-ATA-sda" , rules => < "program result substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "special-device-5" , not_exp_name => "not" , @@ -319,7 +292,6 @@ EOF }, { desc => "program result substitution (newline removal)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "newline_removed" , rules => < "program result substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "test-0:0:0:0" , rules => < "program with lots of arguments", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "foo9" , rules => < "program with subshell", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "bar9" , rules => < "program arguments combined with apostrophes", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "foo7" , rules => < "characters before the %c{N} substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "my-foo9" , rules => < "substitute the second to last argument", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "my-foo8" , rules => < "test substitution by variable name", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", rules => < "test substitution by variable name 2", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0", rules => < "test substitution by variable name 3", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "850:0:0:05" , rules => < "test substitution by variable name 4", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "855" , rules => < "test substitution by variable name 5", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "8550:0:0:0" , rules => < "non matching SUBSYSTEMS for device with no parent", - subsys => "tty", devpath => "/devices/virtual/tty/console", exp_name => "TTY", rules => < "non matching SUBSYSTEMS", - subsys => "tty", devpath => "/devices/virtual/tty/console", exp_name => "TTY" , rules => < "ATTRS match", - subsys => "tty", devpath => "/devices/virtual/tty/console", exp_name => "foo" , rules => < "ATTR (empty file)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "empty" , rules => < "ATTR (non-existent file)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "non-existent" , rules => < "program and bus type match", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "scsi-0:0:0:0" , rules => < "sysfs parent hierarchy", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem" , rules => < "name test with ! in the name", - subsys => "block", devpath => "/devices/virtual/block/fake!blockdev0", exp_name => "is/a/fake/blockdev0" , rules => < "name test with ! in the name, but no matching rule", - subsys => "block", devpath => "/devices/virtual/block/fake!blockdev0", exp_name => "fake/blockdev0" , exp_rem_error => "yes", @@ -524,7 +476,6 @@ EOF }, { desc => "KERNELS rule", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "scsi-0:0:0:0", rules => < "KERNELS wildcard all", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "scsi-0:0:0:0", rules => < "KERNELS wildcard partial", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "scsi-0:0:0:0", rules => < "KERNELS wildcard partial 2", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "scsi-0:0:0:0", rules => < "substitute attr with link target value (first match)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "driver-is-sd", rules => < "substitute attr with link target value (currently selected device)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "driver-is-ahci", rules => < "ignore ATTRS attribute whitespace", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "ignored", rules => < "do not ignore ATTRS attribute whitespace", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "matched-with-space", rules => < "permissions USER=bad GROUP=name", - subsys => "tty", devpath => "/devices/virtual/tty/tty33", exp_name => "tty33", exp_perms => "0:0:0600", @@ -617,7 +560,6 @@ EOF }, { desc => "permissions OWNER=5000", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => "5000::0600", @@ -627,7 +569,6 @@ EOF }, { desc => "permissions GROUP=100", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => ":100:0660", @@ -637,7 +578,6 @@ EOF }, { desc => "textual user id", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => "nobody::0600", @@ -647,7 +587,6 @@ EOF }, { desc => "textual group id", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => ":daemon:0660", @@ -657,7 +596,6 @@ EOF }, { desc => "textual user/group id", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => "root:mail:0660", @@ -667,7 +605,6 @@ EOF }, { desc => "permissions MODE=0777", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => "::0777", @@ -677,7 +614,6 @@ EOF }, { desc => "permissions OWNER=5000 GROUP=100 MODE=0777", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_perms => "5000:100:0777", @@ -687,7 +623,6 @@ EOF }, { desc => "permissions OWNER to 5000", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "5000::", @@ -697,7 +632,6 @@ EOF }, { desc => "permissions GROUP to 100", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => ":100:0660", @@ -707,7 +641,6 @@ EOF }, { desc => "permissions MODE to 0060", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "::0060", @@ -717,7 +650,6 @@ EOF }, { desc => "permissions OWNER, GROUP, MODE", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "5000:100:0777", @@ -727,7 +659,6 @@ EOF }, { desc => "permissions only rule", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "5000:100:0777", @@ -739,7 +670,6 @@ EOF }, { desc => "multiple permissions only rule", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "3000:4000:0777", @@ -753,7 +683,6 @@ EOF }, { desc => "permissions only rule with override at SYMLINK+ rule", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "ttyACM0", exp_perms => "3000:8000:0777", @@ -767,7 +696,6 @@ EOF }, { desc => "major/minor number test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", exp_majorminor => "8:0", @@ -777,7 +705,6 @@ EOF }, { desc => "big major number test", - subsys => "misc", devpath => "/devices/virtual/misc/misc-fake1", exp_name => "node", exp_majorminor => "4095:1", @@ -787,7 +714,6 @@ EOF }, { desc => "big major and big minor number test", - subsys => "misc", devpath => "/devices/virtual/misc/misc-fake89999", exp_name => "node", exp_majorminor => "4095:89999", @@ -797,7 +723,6 @@ EOF }, { desc => "multiple symlinks with format char", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "symlink2-ttyACM0", rules => < "multiple symlinks with a lot of s p a c e s", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "one", not_exp_name => " ", @@ -816,7 +740,6 @@ EOF }, { desc => "symlink creation (same directory)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "modem0", rules => < "symlink creation (relative link forward)", - subsys => "block", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", - exp_name => "1/2/symlink" , - exp_target => "a/b/node", - exp_rem_error => "yes", - rules => < "symlink creation (relative link back and forward)", - subsys => "block", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", - exp_name => "1/2/c/d/symlink" , - exp_target => "../../a/b/node", - exp_rem_error => "yes", - rules => < "multiple symlinks", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "second-0" , rules => < "symlink name '.'", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => ".", exp_add_error => "yes", @@ -867,7 +766,6 @@ EOF }, { desc => "symlink node to itself", - subsys => "tty", devpath => "/devices/virtual/tty/tty0", exp_name => "link", exp_add_error => "yes", @@ -879,7 +777,6 @@ EOF }, { desc => "symlink %n substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "symlink0", rules => < "symlink %k substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "symlink-ttyACM0", rules => < "symlink %M:%m substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "major-166:0", rules => < "symlink %b substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "symlink-0:0:0:0", - exp_target => "node", rules => < "symlink %c substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "test", rules => < "symlink %c{N} substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "test", rules => < "symlink %c{N+} substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "this", rules => < "symlink only rule with %c{N+}", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "test", rules => < "symlink %s{filename} substitution", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "166:0", rules => < "program result substitution (numbered part of)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "link1", rules => < "program result substitution (numbered part of+)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", exp_name => "link4", rules => < "SUBSYSTEM match test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", rules => < "DRIVERS match test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", rules => < "temporary node creation test", - subsys => "block", + desc => "devnode substitution test", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node", rules => < "parent node name substitution test sequence 1/2 (keep)", - subsys => "block", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "main_device", - option => "keep", - exp_rem_error => "yes", - rules => < "parent node name substitution test sequence 2/2 (clean)", - subsys => "block", + desc => "parent node name substitution test", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "main_device-part-1", - option => "clean", + exp_name => "sda-part-1", rules => < "udev_root substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "start-udev-root-end", rules => < "last_rule option", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "last", rules => < "negation KERNEL!=", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "match", rules => < "negation SUBSYSTEM!=", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "not-anything", rules => < "negation PROGRAM!= exit code", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "nonzero-program", rules => < "test for whitespace between the operator", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "true", rules => < "ENV{} test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "true", rules => < "ENV{} test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "true", rules => < "ENV{} test (assign)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "true", rules => < "ENV{} test (assign 2 times)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "true", rules => < "ENV{} test (assign2)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "part", rules => < "untrusted string sanitize", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "sane", rules => < "untrusted string sanitize (don't replace utf8)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "uber", rules => < "untrusted string sanitize (replace invalid utf8)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "replaced", rules => < "read sysfs value from parent device", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "serial-354172020305000", rules => < "match against empty key string", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "ok", rules => < "check ACTION value", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "ok", rules => < "test RUN key remove", - subsys => "block", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "testsymlink2", - exp_target => "ok2", - rules => < "final assignment", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "ok", exp_perms => "root:tty:0640", @@ -1234,7 +1075,6 @@ EOF }, { desc => "final assignment 2", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "ok", exp_perms => "root:tty:0640", @@ -1246,7 +1086,6 @@ EOF }, { desc => "env substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "node-add-me", rules => < "reset list to current value", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "three", not_exp_name => "two", @@ -1267,7 +1105,6 @@ EOF }, { desc => "test empty SYMLINK+ (empty override)", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "right", not_exp_name => "wrong", @@ -1279,7 +1116,6 @@ EOF }, { desc => "test multi matches", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "right", rules => < "test multi matches 2", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "right", rules => < "test multi matches 3", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "right", rules => < "test multi matches 4", - subsys => "tty", devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", exp_name => "right", rules => < "IMPORT parent test sequence 1/2 (keep)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "parent", option => "keep", @@ -1336,7 +1168,6 @@ EOF }, { desc => "IMPORT parent test sequence 2/2 (keep)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "parentenv-parent_right", option => "clean", @@ -1346,7 +1177,6 @@ EOF }, { desc => "GOTO test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "right", rules => < "GOTO label does not exist", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "right", rules => < "SYMLINK+ compare test", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "right", not_exp_name => "wrong", @@ -1384,7 +1212,6 @@ EOF }, { desc => "invalid key operation", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "yes", rules => < "operator chars in attribute", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "yes", rules => < "overlong comment line", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", exp_name => "yes", rules => < "magic subsys/kernel lookup", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "00:16:41:e2:8d:ff", rules => < "TEST absolute path", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "there", rules => < "TEST subsys/kernel lookup", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "yes", rules => < "TEST relative path", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "relative", rules => < "TEST wildcard substitution (find queue/nr_requests)", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "found-subdir", rules => < "TEST MODE=0000", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "sda", exp_perms => "0:0:0000", @@ -1472,7 +1291,6 @@ EOF }, { desc => "TEST PROGRAM feeds OWNER, GROUP, MODE", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "sda", exp_perms => "5000:100:0400", @@ -1484,7 +1302,6 @@ EOF }, { desc => "TEST PROGRAM feeds MODE with overflow", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "sda", exp_perms => "0:0:0440", @@ -1496,7 +1313,6 @@ EOF }, { desc => "magic [subsys/sysname] attribute substitution", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "sda-8741C4G-end", exp_perms => "0:0:0600", @@ -1508,7 +1324,6 @@ EOF }, { desc => "builtin path_id", - subsys => "block", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0", rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; print CONF $$rules; close CONF; - $ENV{ACTION} = $action; - $ENV{SUBSYSTEM} = $subsys; if ($valgrind > 0) { - system("$udev_bin_valgrind"); + system("$udev_bin_valgrind $action $devpath"); } else { - system("$udev_bin"); + system("$udev_bin $action $devpath"); } } @@ -1606,39 +1416,6 @@ sub major_minor_test { } } -sub symlink_test { - my ($rules) = @_; - - my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`; - - if ($output =~ m/(.*)-> (.*)/) { - if ($2 eq $rules->{exp_target}) { - print "symlink: ok\n"; - } else { - print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; - print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n"; - print "symlink: error"; - if ($rules->{exp_add_error}) { - print " as expected\n"; - } else { - print "\n"; - $error++; - sleep(1); - } - } - } else { - print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; - print "symlink: not created"; - if ($rules->{exp_add_error}) { - print " as expected\n"; - } else { - print "\n"; - $error++; - sleep(1); - } - } -} - sub make_udev_root { system("rm -rf $udev_root"); mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; @@ -1652,29 +1429,23 @@ sub run_test { my ($rules, $number) = @_; print "TEST $number: $rules->{desc}\n"; + print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n"; - if ($rules->{exp_target}) { - print "device \'$rules->{devpath}\' expecting link '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n"; - } else { - print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n"; - } - - - udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); + udev("add", $rules->{devpath}, \$rules->{rules}); if (defined($rules->{not_exp_name})) { - if ((-e "$PWD/$udev_root$rules->{not_exp_name}") || - (-l "$PWD/$udev_root$rules->{not_exp_name}")) { + if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || + (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; $error++; sleep(1); } } - if ((-e "$PWD/$udev_root$rules->{exp_name}") || - (-l "$PWD/$udev_root$rules->{exp_name}")) { + if ((-e "$PWD/$udev_root/$rules->{exp_name}") || + (-l "$PWD/$udev_root/$rules->{exp_name}")) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}"); + $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); if (defined($rules->{exp_perms})) { permissions_test($rules, $uid, $gid, $mode); @@ -1682,9 +1453,6 @@ sub run_test { if (defined($rules->{exp_majorminor})) { major_minor_test($rules, $rdev); } - if (defined($rules->{exp_target})) { - symlink_test($rules); - } print "add: ok\n"; } else { print "add: error"; @@ -1704,9 +1472,9 @@ sub run_test { return; } - udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); - if ((-e "$PWD/$udev_root$rules->{exp_name}") || - (-l "$PWD/$udev_root$rules->{exp_name}")) { + udev("remove", $rules->{devpath}, \$rules->{rules}); + if ((-e "$PWD/$udev_root/$rules->{exp_name}") || + (-l "$PWD/$udev_root/$rules->{exp_name}")) { print "remove: error"; if ($rules->{exp_rem_error}) { print " as expected\n"; @@ -1743,6 +1511,7 @@ make_udev_root(); open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; print CONF "udev_root=\"$udev_root\"\n"; print CONF "udev_run=\"$udev_root/.udev\"\n"; +print CONF "udev_sys=\"$sysfs\"\n"; print CONF "udev_rules=\"$PWD\"\n"; print CONF "udev_log=\"err\"\n"; close CONF; diff --git a/udev/test-udev.c b/udev/test-udev.c index 8039459..8d5baf7 100644 --- a/udev/test-udev.c +++ b/udev/test-udev.c @@ -43,7 +43,6 @@ int main(int argc, char *argv[]) char syspath[UTIL_PATH_SIZE]; const char *devpath; const char *action; - const char *subsystem; sigset_t mask, sigmask_orig; int err = -EINVAL; @@ -55,12 +54,15 @@ int main(int argc, char *argv[]) sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); - action = getenv("ACTION"); - devpath = getenv("DEVPATH"); - subsystem = getenv("SUBSYSTEM"); + action = argv[1]; + if (action == NULL) { + err(udev, "action missing\n"); + goto out; + } - if (action == NULL || subsystem == NULL || devpath == NULL) { - err(udev, "action, subsystem or devpath missing\n"); + devpath = argv[2]; + if (devpath == NULL) { + err(udev, "devpath missing\n"); goto out; } @@ -73,10 +75,6 @@ int main(int argc, char *argv[]) goto out; } - /* skip reading of db, but read kernel parameters */ - udev_device_set_info_loaded(dev); - udev_device_read_uevent_file(dev); - udev_device_set_action(dev, action); event = udev_event_new(dev); @@ -88,6 +86,24 @@ int main(int argc, char *argv[]) goto out; } + /* do what devtmpfs usually provides us */ + if (udev_device_get_devnode(dev) != NULL) { + mode_t mode; + + if (strcmp(udev_device_get_subsystem(dev), "block") == 0) + mode |= S_IFBLK; + else + mode |= S_IFCHR; + + if (strcmp(action, "remove") != 0) { + util_create_path(udev, udev_device_get_devnode(dev)); + mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); + } else { + unlink(udev_device_get_devnode(dev)); + util_delete_path(udev, udev_device_get_devnode(dev)); + } + } + err = udev_event_execute_rules(event, rules, &sigmask_orig); if (err == 0) udev_event_execute_run(event, NULL); diff --git a/udev/udev-event.c b/udev/udev-event.c index e10d48e..3801f23 100644 --- a/udev/udev-event.c +++ b/udev/udev-event.c @@ -59,7 +59,6 @@ void udev_event_unref(struct udev_event *event) if (event == NULL) return; udev_list_cleanup(&event->run_list); - free(event->tmp_node); free(event->program_result); free(event->name); dbg(event->udev, "free event %p\n", event); @@ -71,7 +70,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char * struct udev_device *dev = event->dev; enum subst_type { SUBST_UNKNOWN, - SUBST_TEMP_NODE, + SUBST_DEVNODE, SUBST_ATTR, SUBST_ENV, SUBST_KERNEL, @@ -93,7 +92,8 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char * char fmt; enum subst_type type; } map[] = { - { .name = "tempnode", .fmt = 'N', .type = SUBST_TEMP_NODE }, + { .name = "devnode", .fmt = 'N', .type = SUBST_DEVNODE }, + { .name = "tempnode", .fmt = 'N', .type = SUBST_DEVNODE }, { .name = "attr", .fmt = 's', .type = SUBST_ATTR }, { .name = "sysfs", .fmt = 's', .type = SUBST_ATTR }, { .name = "env", .fmt = 'E', .type = SUBST_ENV }, @@ -332,7 +332,7 @@ subst: dev_parent = udev_device_get_parent(event->dev); if (dev_parent == NULL) break; - devnode = udev_device_get_devnode(dev_parent); + devnode = udev_device_get_devnode(dev_parent); if (devnode != NULL) { size_t devlen = strlen(udev_get_dev_path(event->udev))+1; @@ -342,56 +342,10 @@ subst: } break; } - case SUBST_TEMP_NODE: { - dev_t devnum; - struct stat statbuf; - char filename[UTIL_PATH_SIZE]; - const char *devtype; - - if (event->tmp_node != NULL) { - l = util_strpcpy(&s, l, event->tmp_node); - dbg(event->udev, "tempnode: return earlier created one\n"); - break; - } - devnum = udev_device_get_devnum(dev); - if (major(devnum) == 0) - break; - /* lookup kernel provided node */ - if (udev_device_get_knodename(dev) != NULL) { - util_strscpyl(filename, sizeof(filename), - udev_get_dev_path(event->udev), "/", udev_device_get_knodename(dev), NULL); - if (stat(filename, &statbuf) == 0 && statbuf.st_rdev == devnum) { - l = util_strpcpy(&s, l, filename); - dbg(event->udev, "tempnode: return kernel node\n"); - break; - } - } - /* lookup /dev/{char,block}/: */ - if (strcmp(udev_device_get_subsystem(dev), "block") == 0) - devtype = "block"; - else - devtype = "char"; - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(event->udev), devtype, - major(udev_device_get_devnum(dev)), - minor(udev_device_get_devnum(dev))); - if (stat(filename, &statbuf) == 0 && statbuf.st_rdev == devnum) { - l = util_strpcpy(&s, l, filename); - dbg(event->udev, "tempnode: return maj:min node\n"); - break; - } - /* create temporary node */ - dbg(event->udev, "tempnode: create temp node\n"); - asprintf(&event->tmp_node, "%s/.tmp-%s-%u:%u", - udev_get_dev_path(event->udev), devtype, - major(udev_device_get_devnum(dev)), - minor(udev_device_get_devnum(dev))); - if (event->tmp_node == NULL) - break; - udev_node_mknod(dev, event->tmp_node, 0600, 0, 0); - l = util_strpcpy(&s, l, event->tmp_node); + case SUBST_DEVNODE: + if (udev_device_get_devnode(dev) != NULL) + l = util_strpcpy(&s, l, udev_device_get_devnode(dev)); break; - } case SUBST_NAME: if (event->name != NULL) { l = util_strpcpy(&s, l, event->name); @@ -975,44 +929,6 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, } if (major(udev_device_get_devnum(dev)) != 0) { - char filename[UTIL_PATH_SIZE]; - - if (event->tmp_node != NULL) { - info(event->udev, "cleanup temporary device node\n"); - util_unlink_secure(event->udev, event->tmp_node); - free(event->tmp_node); - event->tmp_node = NULL; - } - - /* no rule, use kernel provided name */ - if (event->name == NULL) { - if (udev_device_get_knodename(dev) != NULL) { - event->name = strdup(udev_device_get_knodename(dev)); - info(event->udev, "no node name set, will use kernel supplied name '%s'\n", event->name); - } else { - event->name = strdup(udev_device_get_sysname(event->dev)); - info(event->udev, "no node name set, will use device name '%s'\n", event->name); - } - } - - if (event->name == NULL || event->name[0] == '\0') { - udev_device_delete_db(dev); - udev_device_tag_index(dev, NULL, false); - udev_device_unref(event->dev_db); - err = -ENOMEM; - err(event->udev, "no node name, something went wrong, ignoring\n"); - goto out; - } - - if (udev_device_get_knodename(dev) != NULL && strcmp(udev_device_get_knodename(dev), event->name) != 0) - err(event->udev, "kernel-provided name '%s' and NAME= '%s' disagree, " - "please use SYMLINK+= or change the kernel to provide the proper name\n", - udev_device_get_knodename(dev), event->name); - - /* set device node name */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", event->name, NULL); - udev_device_set_devnode(dev, filename); - /* remove/update possible left-over symlinks from old database entry */ if (event->dev_db != NULL) udev_node_update_old_links(dev, event->dev_db); @@ -1030,10 +946,6 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, } } - /* set sticky bit, so we do not remove the node on module unload */ - if (event->static_node) - event->mode |= 01000; - err = udev_node_add(dev, event->mode, event->uid, event->gid); } diff --git a/udev/udev-node.c b/udev/udev-node.c index 44d3686..31046bd 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -33,90 +33,6 @@ #define TMP_FILE_EXT ".udev-tmp" -int udev_node_mknod(struct udev_device *dev, const char *file, mode_t mode, uid_t uid, gid_t gid) -{ - struct udev *udev = udev_device_get_udev(dev); - dev_t devnum = udev_device_get_devnum(dev); - struct stat stats; - int err = 0; - - - if (strcmp(udev_device_get_subsystem(dev), "block") == 0) - mode |= S_IFBLK; - else - mode |= S_IFCHR; - - if (file == NULL) - file = udev_device_get_devnode(dev); - - if (lstat(file, &stats) == 0) { - if (((stats.st_mode & S_IFMT) == (mode & S_IFMT)) && (stats.st_rdev == devnum)) { - info(udev, "preserve file '%s', because it has correct dev_t\n", file); - if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) { - /* preserve 'sticky' bit, if already set */ - mode |= stats.st_mode & 01000; - info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid); - chmod(file, mode); - chown(file, uid, gid); - } else { - info(udev, "preserve permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid); - } - /* - * Set initial selinux file context only on add events. - * We set the proper context on bootup (triger) or for newly - * added devices, but we don't change it later, in case - * something else has set a custom context in the meantime. - */ - if (strcmp(udev_device_get_action(dev), "add") == 0) - udev_selinux_lsetfilecon(udev, file, mode); - /* always update timestamp when we re-use the node, like on media change events */ - utimensat(AT_FDCWD, file, NULL, 0); - } else { - char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)]; - - info(udev, "atomically replace existing file '%s'\n", file); - util_strscpyl(file_tmp, sizeof(file_tmp), file, TMP_FILE_EXT, NULL); - unlink(file_tmp); - udev_selinux_setfscreatecon(udev, file_tmp, mode); - err = mknod(file_tmp, mode, devnum); - udev_selinux_resetfscreatecon(udev); - if (err != 0) { - err(udev, "mknod '%s' %u:%u %#o failed: %m\n", - file_tmp, major(devnum), minor(devnum), mode); - goto exit; - } - err = rename(file_tmp, file); - if (err != 0) { - err(udev, "rename '%s' '%s' failed: %m\n", file_tmp, file); - unlink(file_tmp); - goto exit; - } - info(udev, "set permissions '%s' %#o uid=%u gid=%u\n", file, mode, uid, gid); - chmod(file, mode); - chown(file, uid, gid); - } - } else { - info(udev, "mknod '%s' %u:%u %#o\n", file, major(devnum), minor(devnum), mode); - do { - err = util_create_path_selinux(udev, file); - if (err != 0 && err != -ENOENT) - break; - udev_selinux_setfscreatecon(udev, file, mode); - err = mknod(file, mode, devnum); - if (err != 0) - err = -errno; - udev_selinux_resetfscreatecon(udev); - } while (err == -ENOENT); - if (err != 0 && err != -EEXIST) - err(udev, "mknod '%s' %u:%u %#o' failed: %m\n", file, major(devnum), minor(devnum), mode); - info(udev, "set permissions '%s' %#o uid=%u gid=%u\n", file, mode, uid, gid); - chmod(file, mode); - chown(file, uid, gid); - } -exit: - return err; -} - static int node_symlink(struct udev *udev, const char *node, const char *slink) { struct stat stats; @@ -362,6 +278,55 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev } } +static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) +{ + struct udev *udev = udev_device_get_udev(dev); + const char *devnode = udev_device_get_devnode(dev); + dev_t devnum = udev_device_get_devnum(dev); + struct stat stats; + int err = 0; + + if (strcmp(udev_device_get_subsystem(dev), "block") == 0) + mode |= S_IFBLK; + else + mode |= S_IFCHR; + + if (lstat(devnode, &stats) != 0) { + err = -errno; + info(udev, "can not stat() node '%s' (%m)\n", devnode); + goto out; + } + + if (((stats.st_mode & S_IFMT) != (mode & S_IFMT)) || (stats.st_rdev != devnum)) { + err = -EEXIST; + info(udev, "found node '%s' with non-matching devnum %s, skip handling\n", + udev_device_get_devnode(dev), udev_device_get_id_filename(dev)); + goto out; + } + + if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) { + info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid); + chmod(devnode, mode); + chown(devnode, uid, gid); + } else { + info(udev, "preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid); + } + + /* + * Set initial selinux file context only on add events. + * We set the proper context on bootup (triger) or for newly + * added devices, but we don't change it later, in case + * something else has set a custom context in the meantime. + */ + if (strcmp(udev_device_get_action(dev), "add") == 0) + udev_selinux_lsetfilecon(udev, devnode, mode); + + /* always update timestamp when we re-use the node, like on media change events */ + utimensat(AT_FDCWD, devnode, NULL, 0); +out: + return err; +} + int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) { struct udev *udev = udev_device_get_udev(dev); @@ -369,15 +334,12 @@ int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) struct udev_list_entry *list_entry; int err = 0; - info(udev, "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n", - udev_device_get_devnode(dev), - major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)), - mode, uid, gid); + info(udev, "handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n", + udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid); - if (udev_node_mknod(dev, NULL, mode, uid, gid) != 0) { - err = -1; + err = node_fixup(dev, mode, uid, gid); + if (err < 0) goto exit; - } /* always add /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "%s/%s/%u:%u", @@ -412,38 +374,6 @@ int udev_node_remove(struct udev_device *dev) udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) link_update(dev, udev_list_entry_get_name(list_entry), 0); - devnode = udev_device_get_devnode(dev); - if (devnode == NULL) - goto out; - - if (stat(devnode, &stats) == 0) { - if (stats.st_rdev != udev_device_get_devnum(dev)) { - info(udev, "device node '%s' points to a different device, skip removal\n", devnode); - err = -1; - goto out; - } - - if (stats.st_mode & 01000) { - info(udev, "device node '%s' has sticky bit set, skip removal\n", devnode); - goto out; - } - } else { - info(udev, "device node '%s' not found\n", devnode); - } - - dev_check = udev_device_new_from_syspath(udev, udev_device_get_syspath(dev)); - if (dev_check != NULL) { - /* do not remove device node if the same sys-device is re-created in the meantime */ - info(udev, "keeping device node of existing device'%s'\n", devnode); - udev_device_unref(dev_check); - goto out; - } - - info(udev, "removing device node '%s'\n", devnode); - err = util_unlink_secure(udev, devnode); - if (err == 0) - util_delete_path(udev, devnode); - /* remove /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "%s/%s/%u:%u", udev_get_dev_path(udev), diff --git a/udev/udev-rules.c b/udev/udev-rules.c index 411b9d8..7e79545 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -2504,9 +2504,6 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event &rules->buf[rule->rule.filename_off], rule->rule.filename_line); break; - case TK_A_STATIC_NODE: - event->static_node = true; - break; case TK_A_ENV: { const char *name = &rules->buf[cur->key.attr_off]; char *value = &rules->buf[cur->key.value_off]; @@ -2729,8 +2726,6 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) else mode = 0600; } - /* set sticky bit, so we do not remove the node on module unload */ - mode |= 01000; if (mode != (stats.st_mode & 01777)) { chmod(filename, mode); info(rules->udev, "chmod '%s' %#o\n", filename, mode); diff --git a/udev/udev.h b/udev/udev.h index 4f2886c..56b1652 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -32,7 +32,6 @@ struct udev_event { struct udev_device *dev_parent; struct udev_device *dev_db; char *name; - char *tmp_node; char *program_result; mode_t mode; uid_t uid; @@ -51,7 +50,6 @@ struct udev_event { bool owner_final; bool mode_set; bool mode_final; - bool static_node; bool name_final; bool devlink_final; bool run_final; @@ -91,7 +89,6 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev); struct udev_device *udev_watch_lookup(struct udev *udev, int wd); /* udev-node.c */ -int udev_node_mknod(struct udev_device *dev, const char *file, mode_t mode, uid_t uid, gid_t gid); int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid); int udev_node_remove(struct udev_device *dev); void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old); diff --git a/udev/udev.xml b/udev/udev.xml index 7b31173..fca0dad 100644 --- a/udev/udev.xml +++ b/udev/udev.xml @@ -167,9 +167,8 @@ - Match the name of the node or network interface. It can - be used once the NAME key has been set in one of the preceding - rules. + Match the name of a network interface. It can be used once the + NAME key has been set in one of the preceding rules. @@ -319,17 +318,8 @@ - What a network interface should be named. - Also, as a temporary workaround, this is what a device node - should be named; usually the kernel provides the defined node name or creates - and removes the node before udev even receives any event. Changing - the node name from the kernel's default creates inconsistencies - and is not supported. If the kernel and NAME specify different names, - an error is logged. udev is only expected to handle device node - permissions and to create additional symlinks, not to change - kernel-provided device node names. Instead of renaming a device node, - SYMLINK should be used. However, symlink names must never conflict with - device node names, as that would result in unpredictable behavior. + The name to use for a network interface. The name of a device node + can not be changed by udev, only additional symlinks can be created. @@ -637,7 +627,7 @@ - The current name of the device node. If not changed by a rule, it is the + The current name of the device. If not changed by a rule, it is the name of the kernel device. @@ -665,10 +655,9 @@ - , + , - The name of a temporary device node created to provide access to - the device from a external program before the real node is created. + The name of the device node. diff --git a/udev/udevd.c b/udev/udevd.c index 63b4fd7..6b56197 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -863,11 +863,10 @@ static void static_dev_create_from_modules(struct udev *udev) if (sscanf(devno, "%c%u:%u", &type, &maj, &min) != 3) continue; - /* set sticky bit, so we do not remove the node on module unload */ if (type == 'c') - mode = 01600|S_IFCHR; + mode = S_IFCHR; else if (type == 'b') - mode = 01600|S_IFBLK; + mode = S_IFBLK; else continue;