X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=namedev.c;h=212d6bb68d93d5774b95ef38cf3806a8dd5a690f;hp=633a7bf0dad1f7b892aa68575f7c241a1c4911ab;hb=666269480900dd8d099b9e188c16acc9f7f31ee5;hpb=5d4754f19521568b775ba7a31465d3af192ce382 diff --git a/namedev.c b/namedev.c index 633a7bf0d..212d6bb68 100644 --- a/namedev.c +++ b/namedev.c @@ -200,15 +200,30 @@ static void build_kernel_number(struct sysfs_class_device *class_dev, struct ude static void apply_format(struct udevice *udev, unsigned char *string) { char name[NAME_SIZE]; + char temp[NAME_SIZE]; + char *tail; char *pos; + char *pos2; + char *pos3; + int num; while (1) { + num = 0; pos = strchr(string, '%'); if (pos) { - strfieldcpy(name, pos+2); - *pos = 0x00; - switch (pos[1]) { + *pos = '\0'; + tail = pos+1; + if (isdigit(tail[0])) { + num = (int) strtoul(&pos[1], &tail, 10); + if (tail == NULL) { + dbg("format parsing error '%s'", pos+1); + break; + } + } + strfieldcpy(name, tail+1); + + switch (tail[0]) { case 'b': if (strlen(udev->bus_id) == 0) break; @@ -241,8 +256,24 @@ static void apply_format(struct udevice *udev, unsigned char *string) case 'c': if (strlen(udev->callout_value) == 0) break; - strcat(pos, udev->callout_value); - dbg("substitute callout output '%s'", udev->callout_value); + if (num) { + /* get part of return string */ + strncpy(temp, udev->callout_value, sizeof(temp)); + pos2 = temp; + while (num) { + num--; + pos3 = strsep(&pos2, " "); + if (pos3 == NULL) { + dbg("requested part of callout string not found"); + break; + } + } + strcat(pos, pos3); + dbg("substitute partial callout output '%s'", pos3); + } else { + strcat(pos, udev->callout_value); + dbg("substitute callout output '%s'", udev->callout_value); + } break; default: dbg("unknown substitution type '%%%c'", pos[1]); @@ -264,7 +295,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; @@ -286,9 +317,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; } @@ -324,9 +355,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) {