X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=namedev.c;h=74a411799b9c96db4d8ad619b306c0e5413327da;hb=2052464275b50f27cc563aaee24aadd791a9d8ca;hp=1faa253c1e9b8685da16c5413d585b202383c8b0;hpb=83be97ba211c4f69e7fd9f16f57ca7210a116a7d;p=elogind.git diff --git a/namedev.c b/namedev.c index 1faa253c1..74a411799 100644 --- a/namedev.c +++ b/namedev.c @@ -121,6 +121,7 @@ int add_config_dev(struct config_device *new_dev) copy_string(dev, new_dev, place); copy_string(dev, new_dev, kernel_name); copy_string(dev, new_dev, exec_program); + copy_string(dev, new_dev, symlink); return 0; } @@ -222,7 +223,7 @@ static void apply_format(struct udevice *udev, unsigned char *string) break; case 'D': if (strlen(udev->kernel_number) == 0) { - strcat(pos, "disk"); + strcat(pos, "disc"); break; } strcat(pos, "part"); @@ -263,7 +264,7 @@ static int exec_callout(struct config_device *dev, char *value, int len) pid_t pid; int value_set = 0; char buffer[256]; - char *arg; + char *pos; char *args[CALLOUT_MAXARG]; int i; @@ -285,9 +286,9 @@ static int exec_callout(struct config_device *dev, char *value, int len) dup(fds[1]); /* dup write side of pipe to STDOUT */ if (strchr(dev->exec_program, ' ')) { /* callout with arguments */ - arg = dev->exec_program; + pos = dev->exec_program; for (i=0; i < CALLOUT_MAXARG-1; i++) { - args[i] = strsep(&arg, " "); + args[i] = strsep(&pos, " "); if (args[i] == NULL) break; } @@ -323,9 +324,12 @@ static int exec_callout(struct config_device *dev, char *value, int len) } else { value_set = 1; strncpy(value, buffer, len); + pos = value + strlen(value)-1; + if (pos[0] == '\n') + pos[0] = '\0'; + dbg("callout returned '%s'", value); } } - dbg("callout returned '%s'", value); close(fds[0]); res = wait(&status); if (res < 0) { @@ -366,6 +370,7 @@ static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev if (strcmp_pattern(dev->id, udev->callout_value) != 0) continue; strfieldcpy(udev->name, dev->name); + strfieldcpy(udev->symlink, dev->symlink); dbg("callout returned matching value '%s', '%s' becomes '%s'", dev->id, class_dev->name, udev->name); return 0; @@ -416,6 +421,7 @@ label_found: continue; strfieldcpy(udev->name, dev->name); + strfieldcpy(udev->symlink, dev->symlink); dbg("found matching attribute '%s', '%s' becomes '%s' ", dev->sysfs_file, class_dev->name, udev->name); @@ -461,6 +467,7 @@ static int do_number(struct sysfs_class_device *class_dev, struct udevice *udev, if (!found) continue; strfieldcpy(udev->name, dev->name); + strfieldcpy(udev->symlink, dev->symlink); dbg("found matching id '%s', '%s' becomes '%s'", dev->id, class_dev->name, udev->name); return 0; @@ -506,6 +513,7 @@ static int do_topology(struct sysfs_class_device *class_dev, struct udevice *ude continue; strfieldcpy(udev->name, dev->name); + strfieldcpy(udev->symlink, dev->symlink); dbg("found matching place '%s', '%s' becomes '%s'", dev->place, class_dev->name, udev->name); return 0; @@ -528,6 +536,7 @@ static int do_replace(struct sysfs_class_device *class_dev, struct udevice *udev continue; strfieldcpy(udev->name, dev->name); + strfieldcpy(udev->symlink, dev->symlink); dbg("found name, '%s' becomes '%s'", dev->kernel_name, udev->name); return 0; @@ -546,37 +555,29 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud struct sysfs_device *sysfs_device = NULL; struct sysfs_class_device *class_dev_parent = NULL; int retval = 0; - char *temp = NULL; struct perm_device *perm; udev->mode = 0; /* find the sysfs_device for this class device */ /* Wouldn't it really be nice if libsysfs could do this for us? */ - if (class_dev->sysdevice) { - sysfs_device = class_dev->sysdevice; - } else { + sysfs_device = sysfs_get_classdev_device(class_dev); + if (sysfs_device == NULL) { /* bah, let's go backwards up a level to see if the device is there, * as block partitions don't point to the physical device. Need to fix that * up in the kernel... */ - if (strstr(class_dev->path, "block")) { + if (strcmp(class_dev->classname, SYSFS_BLOCK_NAME) == 0) { dbg("looking at block device"); if (isdigit(class_dev->path[strlen(class_dev->path)-1])) { - char path[SYSFS_PATH_MAX]; - dbg("really is a partition"); - strfieldcpy(path, class_dev->path); - temp = strrchr(path, '/'); - *temp = 0x00; - dbg("looking for a class device at '%s'", path); - class_dev_parent = sysfs_open_class_device(path); + class_dev_parent = sysfs_get_classdev_parent + (class_dev); if (class_dev_parent == NULL) { - dbg("sysfs_open_class_device at '%s' failed", path); + dbg("sysfs_get_classdev_parent for class device '%s' failed", class_dev->name); } else { dbg("class_dev_parent->name='%s'", class_dev_parent->name); - if (class_dev_parent->sysdevice) - sysfs_device = class_dev_parent->sysdevice; + sysfs_device = sysfs_get_classdev_device(class_dev_parent); } } } @@ -618,8 +619,9 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud goto done; found: - /* substitute placeholder in NAME */ + /* substitute placeholder */ apply_format(udev, udev->name); + apply_format(udev, udev->symlink); done: perm = find_perm(udev->name); @@ -636,9 +638,6 @@ done: dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o", udev->name, udev->owner, udev->group, udev->mode); - if (class_dev_parent) - sysfs_close_class_device(class_dev_parent); - return 0; }