From 4bff1b5ebcffc1488649199b88d3602184edf7f3 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 24 Jun 2012 23:58:37 +0200 Subject: [PATCH] fix env var handling, add support for filling blobmsg_list from arrays --- instance.c | 6 +++--- utils.c | 7 +++++-- utils.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/instance.c b/instance.c index cc839d7..c70fff6 100644 --- a/instance.c +++ b/instance.c @@ -30,7 +30,7 @@ instance_run(struct service_instance *in) argc++; blobmsg_list_for_each(&in->env, var) - putenv(blobmsg_data(var->data)); + setenv(blobmsg_name(var->data), blobmsg_data(var->data), 1); argv = alloca(sizeof(char *) * argc); argc = 0; @@ -149,13 +149,13 @@ instance_config_parse(struct service_instance *in) if ((cur = tb[INSTANCE_ATTR_ENV])) { if (!blobmsg_check_attr_list(cur, BLOBMSG_TYPE_STRING)) return false; - blobmsg_list_fill(&in->env, blobmsg_data(cur), blobmsg_data_len(cur)); + blobmsg_list_fill(&in->env, blobmsg_data(cur), blobmsg_data_len(cur), false); } if ((cur = tb[INSTANCE_ATTR_DATA])) { if (!blobmsg_check_attr_list(cur, BLOBMSG_TYPE_STRING)) return false; - blobmsg_list_fill(&in->data, blobmsg_data(cur), blobmsg_data_len(cur)); + blobmsg_list_fill(&in->data, blobmsg_data(cur), blobmsg_data_len(cur), false); } return true; diff --git a/utils.c b/utils.c index 88ed8c1..0f9ce74 100644 --- a/utils.c +++ b/utils.c @@ -11,7 +11,7 @@ __blobmsg_list_init(struct blobmsg_list *list, int offset, int len) } int -blobmsg_list_fill(struct blobmsg_list *list, void *data, int len) +blobmsg_list_fill(struct blobmsg_list *list, void *data, int len, bool array) { struct avl_tree *tree = &list->avl; struct blobmsg_list_node *node; @@ -29,7 +29,10 @@ blobmsg_list_fill(struct blobmsg_list *list, void *data, int len) return -1; node = (void *) ((char *)ptr + list->node_offset); - node->avl.key = blobmsg_name(cur); + if (array) + node->avl.key = blobmsg_data(cur); + else + node->avl.key = blobmsg_name(cur); node->data = cur; if (avl_insert(tree, &node->avl)) { free(ptr); diff --git a/utils.h b/utils.h index 7ee65a0..e20169a 100644 --- a/utils.h +++ b/utils.h @@ -26,7 +26,7 @@ struct blobmsg_list_node { avl_for_each_element(&(list)->avl, element, avl) void __blobmsg_list_init(struct blobmsg_list *list, int offset, int len); -int blobmsg_list_fill(struct blobmsg_list *list, void *data, int len); +int blobmsg_list_fill(struct blobmsg_list *list, void *data, int len, bool array); void blobmsg_list_free(struct blobmsg_list *list); bool blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2); void blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src); -- 2.30.2