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.
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.
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"
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"
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"
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}"
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)
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;
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;
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));
}
char *driver;
char *action;
char *devpath_old;
- char *knodename;
char *id_filename;
char **envp;
char *monitor_buf;
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;
} 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;
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);
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);
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);
{
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;
}
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);
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);
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,
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;
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;
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)
* @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
**/
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"
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"
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}"
-DEVNAME=ttyACM0
MAJOR=166
MINOR=0
+DEVNAME=ttyACM0
MAJOR=8
MINOR=5
DEVTYPE=partition
+DEVNAME=sda5
MAJOR=7
MINOR=0
DEVTYPE=disk
+DEVNAME=fake/blockdev0
MAJOR=4095
MINOR=1
+DEVNAME=misc-fake1
+
MAJOR=4095
MINOR=89999
+DEVNAME=misc-fake89999
MAJOR=5
MINOR=1
+DEVNAME=console
MAJOR=4
MINOR=0
+DEVNAME=tty0
MAJOR=4
MINOR=33
+DEVNAME=tty33
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",
},
{
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 => <<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 => <<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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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" ,
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "non matching SUBSYSTEMS for device with no parent",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "TTY",
rules => <<EOF
},
{
desc => "non matching SUBSYSTEMS",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "TTY" ,
rules => <<EOF
},
{
desc => "ATTRS match",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "foo" ,
rules => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "name test with ! in the name",
- subsys => "block",
devpath => "/devices/virtual/block/fake!blockdev0",
exp_name => "is/a/fake/blockdev0" ,
rules => <<EOF
},
{
desc => "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",
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "permissions USER=bad GROUP=name",
- subsys => "tty",
devpath => "/devices/virtual/tty/tty33",
exp_name => "tty33",
exp_perms => "0:0:0600",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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::",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
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",
},
{
desc => "big major number test",
- subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake1",
exp_name => "node",
exp_majorminor => "4095:1",
},
{
desc => "big major and big minor number test",
- subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake89999",
exp_name => "node",
exp_majorminor => "4095:89999",
},
{
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 => <<EOF
},
{
desc => "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 => " ",
},
{
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 => <<EOF
EOF
},
{
- desc => "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 => <<EOF
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/symlink"
-EOF
- },
- {
- desc => "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 => <<EOF
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/c/d/symlink"
-EOF
- },
- {
desc => "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 => <<EOF
},
{
desc => "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",
},
{
desc => "symlink node to itself",
- subsys => "tty",
devpath => "/devices/virtual/tty/tty0",
exp_name => "link",
exp_add_error => "yes",
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b"
+SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
EOF
},
{
- desc => "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 => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr@rootprefix@/bin/test -b %N" SYMLINK+="node"
-EOF
- },
- {
- desc => "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 => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="main_device"
+SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
EOF
},
{
- desc => "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 => <<EOF
SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
EOF
},
{
- desc => "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 => <<EOF
-KERNEL=="sda", NAME="ok2", RUN+="@rootprefix@/bin/ln -s ok2 %r/testsymlink2"
-KERNEL=="sda", ACTION=="remove", RUN+="@rootprefix@/bin/rm -f %r/testsymlink2"
-EOF
- },
- {
desc => "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",
},
{
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",
},
{
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 => <<EOF
},
{
desc => "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",
},
{
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",
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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",
},
{
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",
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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",
},
{
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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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 => <<EOF
},
{
desc => "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",
},
{
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",
},
{
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",
},
{
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",
},
{
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 => <<EOF
);
# set env
-$ENV{SYSFS_PATH} = $sysfs;
$ENV{UDEV_CONFIG_FILE} = $udev_conf;
sub udev {
- my ($action, $subsys, $devpath, $rules) = @_;
-
- $ENV{DEVPATH} = $devpath;
+ my ($action, $devpath, $rules) = @_;
# create temporary rules
open CONF, ">$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");
}
}
}
}
-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";
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);
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";
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";
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;
char syspath[UTIL_PATH_SIZE];
const char *devpath;
const char *action;
- const char *subsystem;
sigset_t mask, sigmask_orig;
int err = -EINVAL;
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;
}
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);
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);
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);
struct udev_device *dev = event->dev;
enum subst_type {
SUBST_UNKNOWN,
- SUBST_TEMP_NODE,
+ SUBST_DEVNODE,
SUBST_ATTR,
SUBST_ENV,
SUBST_KERNEL,
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 },
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;
}
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}/<maj>:<min> */
- 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);
}
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);
}
}
- /* 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);
}
#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;
}
}
+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);
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",
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),
&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];
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);
struct udev_device *dev_parent;
struct udev_device *dev_db;
char *name;
- char *tmp_node;
char *program_result;
mode_t mode;
uid_t uid;
bool owner_final;
bool mode_set;
bool mode_final;
- bool static_node;
bool name_final;
bool devlink_final;
bool run_final;
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);
<varlistentry>
<term><option>NAME</option></term>
<listitem>
- <para>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.</para>
+ <para>Match the name of a network interface. It can be used once the
+ NAME key has been set in one of the preceding rules.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>NAME</option></term>
<listitem>
- <para>What a network interface should be named.</para>
- <para>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.</para>
+ <para>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.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>$name</option></term>
<listitem>
- <para>The current name of the device node. If not changed by a rule, it is the
+ <para>The current name of the device. If not changed by a rule, it is the
name of the kernel device.</para>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
- <term><option>$tempnode</option>, <option>%N</option></term>
+ <term><option>$devnode</option>, <option>%N</option></term>
<listitem>
- <para>The name of a temporary device node created to provide access to
- the device from a external program before the real node is created.</para>
+ <para>The name of the device node.</para>
</listitem>
</varlistentry>
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;