X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=namedev.c;h=025a14aea4a5ae832c6d9de1987562a859b8112b;hb=0a5417a0ebe92f96fb103399c9aacdf39c719271;hp=a9142374f4c1400e6737974795b083fe99633ec9;hpb=35b38379bac87ebf4d0cc6884feff588ee859d5f;p=elogind.git diff --git a/namedev.c b/namedev.c index a9142374f..025a14aea 100644 --- a/namedev.c +++ b/namedev.c @@ -190,6 +190,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 +245,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 +256,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 { @@ -811,16 +815,11 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud } if (dev->symlink[0] != '\0') { - char temp[NAME_MAX]; - 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); - strfieldcat(udev->symlink, temp); - strfieldcat(udev->symlink, " "); + if (udev->symlink[0] != '\0') + strfieldcat(udev->symlink, " "); + strfieldcat(udev->symlink, dev->symlink); } if (dev->name[0] != '\0') { @@ -837,8 +836,8 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud 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); + apply_format(udev, udev->symlink, sizeof(udev->symlink), class_dev, sysfs_device); udev->partitions = dev->partitions; done: