X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=handler.c;h=f81a7c581510fe6b4dd7613388cafa8dcdbbd3e3;hp=f4e27e12c3b1d342b8e879a34e07b5a434151247;hb=2d09cca0e90127d33eed43b8790f5778ba3b943f;hpb=f80b9e4acc47cf454768b44142495fdb8a68a39f diff --git a/handler.c b/handler.c index f4e27e1..f81a7c5 100644 --- a/handler.c +++ b/handler.c @@ -27,14 +27,14 @@ netifd_dir_push(int fd) int prev_fd = open(".", O_RDONLY | O_DIRECTORY); system_fd_set_cloexec(prev_fd); if (fd >= 0) - fchdir(fd); + if (fchdir(fd)) {} return prev_fd; } static void netifd_dir_pop(int prev_fd) { - fchdir(prev_fd); + if (fchdir(prev_fd)) {} close(prev_fd); } @@ -139,6 +139,7 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj { struct blobmsg_policy *attrs; char *str_buf, *str_cur; + char const **validate; int str_len = 0; int i; @@ -147,7 +148,12 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj if (!attrs) return NULL; + validate = calloc(1, sizeof(char*) * config->n_params); + if (!validate) + goto error; + config->params = attrs; + config->validate = validate; for (i = 0; i < config->n_params; i++) { json_object *cur, *name, *type; @@ -178,15 +184,25 @@ netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj str_cur = str_buf; for (i = 0; i < config->n_params; i++) { const char *name = attrs[i].name; + char *delim; attrs[i].name = str_cur; str_cur += sprintf(str_cur, "%s", name) + 1; + delim = strchr(attrs[i].name, ':'); + if (delim) { + *delim = '\0'; + validate[i] = ++delim; + } else { + validate[i] = NULL; + } } return str_buf; error: free(attrs); + if (validate) + free(validate); config->n_params = 0; return NULL; }