};
static int
-service_update(struct service *s, struct blob_attr *config, struct blob_attr **tb, bool add)
+service_update(struct service *s, struct blob_attr **tb, bool add)
{
struct blob_attr *cur;
int rem;
service_validate_del(s);
if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) {
- s->trigger = malloc(blob_pad_len(tb[SERVICE_SET_TRIGGER]));
+ s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]);
if (!s->trigger)
return -1;
- memcpy(s->trigger, tb[SERVICE_SET_TRIGGER], blob_pad_len(tb[SERVICE_SET_TRIGGER]));
trigger_add(s->trigger, s);
}
struct blob_attr *tb[__SERVICE_SET_MAX], *cur;
struct service *s = NULL;
const char *name;
- int ret = UBUS_STATUS_INVALID_ARGUMENT;
bool add = !strcmp(method, "add");
+ int ret;
blobmsg_parse(service_set_attrs, __SERVICE_SET_MAX, tb, blob_data(msg), blob_len(msg));
cur = tb[SERVICE_ATTR_NAME];
if (!cur)
- goto free;
+ return UBUS_STATUS_INVALID_ARGUMENT;
name = blobmsg_data(cur);
s = avl_find_element(&services, name, s, avl);
if (s) {
DEBUG(2, "Update service %s\n", name);
- return service_update(s, msg, tb, add);
+ return service_update(s, tb, add);
}
DEBUG(2, "Create service %s\n", name);
if (!s)
return UBUS_STATUS_UNKNOWN_ERROR;
- ret = service_update(s, msg, tb, add);
+ ret = service_update(s, tb, add);
if (ret)
- goto free;
+ return ret;
avl_insert(&services, &s->avl);
return 0;
-
-free:
- free(msg);
- return ret;
}
static void