X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=namedev.c;h=a3ae1d36b3f9786ca04d6c9abde4e97e8110c310;hp=8f781a66e26c60fd7e76cbf0d295b8eb72f91ed0;hb=bbbe503ec1a5623a5a8abd003f46fdd8c3581054;hpb=c81b35c08bbd7789883993ea280e0d3772cce440 diff --git a/namedev.c b/namedev.c index 8f781a66e..a3ae1d36b 100644 --- a/namedev.c +++ b/namedev.c @@ -32,6 +32,9 @@ #include #include #include +#ifndef __KLIBC__ +#include +#endif #include "libsysfs/sysfs/libsysfs.h" #include "list.h" @@ -454,7 +457,7 @@ static int execute_program(char *path, char *value, int len) retval = -1; } - if (i > 0 && value[i] == '\n') + if (i > 0 && value[i-1] == '\n') i--; value[i] = '\0'; dbg("result is '%s'", value); @@ -619,8 +622,8 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de * possibly have a whitelist for these devices here... */ class_dev_parent = sysfs_get_classdev_parent(class_dev); - if (class_dev_parent) - dbg("Really a partition"); + if (class_dev_parent != NULL) + dbg("given class device has a parent, use this instead"); tspec.tv_sec = 0; tspec.tv_nsec = 10000000; /* sleep 10 millisec */ @@ -628,24 +631,21 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de while (loop--) { if (udev_sleep) nanosleep(&tspec, NULL); + if (class_dev_parent) sysfs_device = sysfs_get_classdev_device(class_dev_parent); else sysfs_device = sysfs_get_classdev_device(class_dev); - if (sysfs_device != NULL) goto device_found; } dbg("timed out waiting for device symlink, continuing on anyway..."); - + device_found: /* We have another issue with just the wait above - the sysfs part of * the kernel may not be quick enough to have created the link to the * device under the "bus" subsystem. Due to this, the sysfs_device->bus * will not contain the actual bus name :( - * - * Libsysfs now provides a new API sysfs_get_device_bus(), so use it - * if needed */ if (sysfs_device) { if (sysfs_device->bus[0] != '\0') @@ -779,6 +779,7 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud struct sysfs_device *sysfs_device = NULL; struct config_device *dev; struct perm_device *perm; + struct sysinfo info; char *pos; udev->mode = 0; @@ -816,14 +817,23 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud } if (dev->symlink[0] != '\0') { + char temp[NAME_SIZE]; + info("configured rule in '%s' at line %i applied, added symlink '%s'", dev->config_file, dev->config_line, dev->symlink); + strfieldcpy(temp, dev->symlink); + apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device); if (udev->symlink[0] != '\0') strfieldcat(udev->symlink, " "); - strfieldcat(udev->symlink, dev->symlink); + strfieldcat(udev->symlink, temp); } if (dev->name[0] != '\0') { + /* apply all_partitions flag only at a main block device */ + if (dev->partitions > 0 && + (udev->type != 'b' || udev->kernel_number[0] != '\0')) + continue; + info("configured rule in '%s' at line %i applied, '%s' becomes '%s'", dev->config_file, dev->config_line, udev->kernel_name, dev->name); strfieldcpy(udev->name, dev->name); @@ -831,22 +841,29 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud } } } - /* no rule was found so we use the kernel name */ strfieldcpy(udev->name, udev->kernel_name); - goto done; + if (udev->type == 'n') + goto done; + else + goto perms; found: apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device); - apply_format(udev, udev->symlink, sizeof(udev->symlink), class_dev, sysfs_device); + + if (udev->type == 'n') + goto done; + udev->partitions = dev->partitions; + strfieldcpy(udev->config_file, dev->config_file); + udev->config_line = dev->config_line; -done: /* get permissions given in rule */ set_empty_perms(udev, dev->mode, dev->owner, dev->group); +perms: /* get permissions given in config file or set defaults */ perm = find_perm(udev->name); if (perm != NULL) { @@ -862,6 +879,11 @@ done: dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o", udev->name, udev->owner, udev->group, udev->mode); +done: + /* store time of action */ + sysinfo(&info); + udev->config_uptime = info.uptime; + return 0; }