X-Git-Url: http://git.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto-shell.c;h=3b5311ce17a228f55e4ef90eb415f9e40a823e7e;hp=eb60fc15037a5e1c895589f387cd79c1ef48b036;hb=268149290fcd8a52f377b21226990d3bf0e9c226;hpb=33a44b9c7d5e8c87303b8126fe9e01f8979f48e5 diff --git a/proto-shell.c b/proto-shell.c index eb60fc1..3b5311c 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -242,6 +242,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) { struct interface_ip_settings *ip; struct blob_attr *cur; + int dev_create = 1; bool addr_ext = false; bool up; @@ -254,6 +255,12 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) return 0; } + if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) { + addr_ext = blobmsg_get_bool(cur); + if (addr_ext) + dev_create = 2; + } + if (!tb[NOTIFY_IFNAME]) { if (!state->proto.iface->main_dev.dev) return UBUS_STATUS_INVALID_ARGUMENT; @@ -262,7 +269,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) device_remove_user(&state->l3_dev); device_add_user(&state->l3_dev, - device_get(blobmsg_data(tb[NOTIFY_IFNAME]), true)); + device_get(blobmsg_data(tb[NOTIFY_IFNAME]), dev_create)); state->proto.iface->l3_dev = &state->l3_dev; device_claim(&state->l3_dev); } @@ -270,9 +277,6 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) ip = &state->proto.iface->proto_ip; interface_update_start(state->proto.iface); - if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) - addr_ext = blobmsg_get_bool(cur); - if ((cur = tb[NOTIFY_IPADDR]) != NULL) proto_shell_parse_addr_list(ip, cur, false, addr_ext); @@ -328,8 +332,8 @@ out: static int proto_shell_run_command(struct proto_shell_state *state, struct blob_attr **tb) { - char *argv[64]; - char *env[32]; + static char *argv[64]; + static char *env[32]; if (!tb[NOTIFY_COMMAND]) goto error; @@ -391,7 +395,7 @@ proto_shell_notify(struct interface_proto_state *proto, struct blob_attr *attr) } } -struct interface_proto_state * +static struct interface_proto_state * proto_shell_attach(const struct proto_handler *h, struct interface *iface, struct blob_attr *attr) { @@ -551,9 +555,9 @@ static void proto_shell_add_script(const char *name) struct json_tokener *tok = NULL; json_object *obj; static char buf[512]; - char *start, *end, *cmd; + char *start, *cmd; FILE *f; - int buflen, len; + int len; #define DUMP_SUFFIX " '' dump" @@ -565,33 +569,25 @@ static void proto_shell_add_script(const char *name) return; do { - buflen = fread(buf, 1, sizeof(buf) - 1, f); - if (buflen <= 0) + start = fgets(buf, sizeof(buf), f); + if (!start) continue; - start = buf; - len = buflen; - do { - end = memchr(start, '\n', len); - if (end) - len = end - start; - - if (!tok) - tok = json_tokener_new(); - - obj = json_tokener_parse_ex(tok, start, len); - if (!is_error(obj)) { - proto_shell_add_handler(name, obj); - json_object_put(obj); - json_tokener_free(tok); - tok = NULL; - } - - if (end) { - start = end + 1; - len = buflen - (start - buf); - } - } while (len > 0); + len = strlen(start); + + if (!tok) + tok = json_tokener_new(); + + obj = json_tokener_parse_ex(tok, start, len); + if (!is_error(obj)) { + proto_shell_add_handler(name, obj); + json_object_put(obj); + json_tokener_free(tok); + tok = NULL; + } else if (start[len - 1] == '\n') { + json_tokener_free(tok); + tok = NULL; + } } while (!feof(f) && !ferror(f)); if (tok) @@ -600,7 +596,7 @@ static void proto_shell_add_script(const char *name) pclose(f); } -void __init proto_shell_init(void) +static void __init proto_shell_init(void) { glob_t g; int main_fd;