summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2014-07-30 14:40:22 +0200
committerFelix Fietkau <nbd@openwrt.org>2014-07-30 14:40:22 +0200
commit35e01a9601292b2f609e65c2ddb3990cba8f378e (patch)
treea78fc99d45fb033d54cc58c6b525dda419c00204
parent7a460b86fb6515ea84a53fe8ba091f20cbe07d02 (diff)
downloadunitd-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.c49
1 files changed, 39 insertions, 10 deletions
diff --git a/system.c b/system.c
index 2dbed51..4b3b82c 100644
--- a/system.c
+++ b/system.c
@@ -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);