X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=namedev.c;h=7b70f8bcdfd40dea8f19dd23e23fe01a655d8666;hp=a9142374f4c1400e6737974795b083fe99633ec9;hb=0bcdc8498cdeaaef37444d38f39a19ff9557914d;hpb=35b38379bac87ebf4d0cc6884feff588ee859d5f diff --git a/namedev.c b/namedev.c index a9142374f..7b70f8bcd 100644 --- a/namedev.c +++ b/namedev.c @@ -36,6 +36,7 @@ #include "libsysfs/sysfs/libsysfs.h" #include "list.h" #include "udev.h" +#include "udev_lib.h" #include "udev_version.h" #include "logging.h" #include "namedev.h" @@ -190,6 +191,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, int i; char c; char *spos; + char *rest; int slen; struct sysfs_attribute *tmpattr; @@ -244,7 +246,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, /* get part part of the result string */ i = 0; if (attr != NULL) - i = atoi(attr); + i = strtoul(attr, &rest, 10); if (i > 0) { foreach_strpart(udev->program_result, " \n\r", spos, slen) { i--; @@ -255,7 +257,10 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, dbg("requested part of result string not found"); break; } - strfieldcpymax(temp2, spos, slen+1); + if (rest[0] == '+') + strfieldcpy(temp2, spos); + else + strfieldcpymax(temp2, spos, slen+1); strfieldcatmax(string, temp2, maxsize); dbg("substitute part of result string '%s'", temp2); } else { @@ -614,8 +619,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 */ @@ -623,24 +628,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') @@ -811,19 +813,23 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud } if (dev->symlink[0] != '\0') { - char temp[NAME_MAX]; + char temp[NAME_SIZE]; info("configured rule in '%s' at line %i applied, added symlink '%s'", dev->config_file, dev->config_line, dev->symlink); - /* do not clobber dev */ strfieldcpy(temp, dev->symlink); - apply_format(udev, temp, sizeof(temp), - class_dev, sysfs_device); + apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device); + if (udev->symlink[0] != '\0') + strfieldcat(udev->symlink, " "); strfieldcat(udev->symlink, temp); - strfieldcat(udev->symlink, " "); } 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); @@ -832,21 +838,32 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud } } + /* no rule was found for the net device */ + if (udev->type == 'n') { + dbg("no name for net device '%s' configured", udev->kernel_name); + return -1; + } + /* no rule was found so we use the kernel name */ strfieldcpy(udev->name, udev->kernel_name); goto done; found: - apply_format(udev, udev->name, sizeof(udev->name), - class_dev, sysfs_device); + apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device); + + if (udev->type == 'n') + return 0; + 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); +done: /* get permissions given in config file or set defaults */ perm = find_perm(udev->name); if (perm != NULL) { @@ -862,6 +879,9 @@ done: dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o", udev->name, udev->owner, udev->group, udev->mode); + /* store time of action */ + udev->config_time = time(NULL); + return 0; }