diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-07-30 14:40:22 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-07-30 14:40:22 +0200 |
commit | 35e01a9601292b2f609e65c2ddb3990cba8f378e (patch) | |
tree | a78fc99d45fb033d54cc58c6b525dda419c00204 | |
parent | 7a460b86fb6515ea84a53fe8ba091f20cbe07d02 (diff) | |
download | unitd-35e01a9601292b2f609e65c2ddb3990cba8f378e.tar unitd-35e01a9601292b2f609e65c2ddb3990cba8f378e.zip |
system.c: parse quoted version info from /etc/openwrt_release
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | system.c | 49 |
1 files changed, 39 insertions, 10 deletions
@@ -38,7 +38,7 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj, { void *c; char line[256]; - char *key, *val; + char *key, *val, *next; struct utsname utsname; FILE *f; @@ -111,24 +111,53 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj, while (fgets(line, sizeof(line), f)) { - key = strtok(line, "=\""); - val = strtok(NULL, "\"\n"); + char *dest; + char ch; - if (!key || !val) + key = line; + val = strchr(line, '='); + if (!val) continue; + *(val++) = 0; + if (!strcasecmp(key, "DISTRIB_ID")) - blobmsg_add_string(&b, "distribution", val); + key = "distribution"; else if (!strcasecmp(key, "DISTRIB_RELEASE")) - blobmsg_add_string(&b, "version", val); + key = "version"; else if (!strcasecmp(key, "DISTRIB_REVISION")) - blobmsg_add_string(&b, "revision", val); + key = "revision"; else if (!strcasecmp(key, "DISTRIB_CODENAME")) - blobmsg_add_string(&b, "codename", val); + key = "codename"; else if (!strcasecmp(key, "DISTRIB_TARGET")) - blobmsg_add_string(&b, "target", val); + key = "target"; else if (!strcasecmp(key, "DISTRIB_DESCRIPTION")) - blobmsg_add_string(&b, "description", val); + key = "description"; + else + continue; + + dest = blobmsg_alloc_string_buffer(&b, key, strlen(val)); + while (val && (ch = *(val++)) != 0) { + switch (ch) { + case '\'': + case '"': + next = strchr(val, ch); + if (next) + *next = 0; + + strcpy(dest, val); + + if (next) + val = next + 1; + + dest += strlen(dest); + break; + case '\\': + *(dest++) = *(val++); + break; + } + } + blobmsg_add_string_buffer(&b); } blobmsg_close_array(&b, c); |