From: Felix Fietkau Date: Sun, 24 Jun 2012 21:58:37 +0000 (+0200) Subject: fix env var handling, add support for filling blobmsg_list from arrays X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=4bff1b5ebcffc1488649199b88d3602184edf7f3;p=project%2Fprocd.git fix env var handling, add support for filling blobmsg_list from arrays --- 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);