diff options
author | John Crispin <blogic@openwrt.org> | 2014-06-05 15:02:29 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2014-06-06 10:47:41 +0200 |
commit | 53c1ea6b9ade10eff3cec07519db862b365a4233 (patch) | |
tree | eb66af52ae9160192ee24299397ea3c2a0424773 | |
parent | 45ca87272954f46eb6d55365d5a2fbe3520d66ce (diff) | |
download | unitd-53c1ea6b9ade10eff3cec07519db862b365a4233.tar unitd-53c1ea6b9ade10eff3cec07519db862b365a4233.zip |
allow instances to report errors. if an error is set, the instance wont be started
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r-- | service/instance.c | 24 | ||||
-rw-r--r-- | service/instance.h | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/service/instance.c b/service/instance.c index e410bc4..a01a35a 100644 --- a/service/instance.c +++ b/service/instance.c @@ -39,6 +39,7 @@ enum { INSTANCE_ATTR_NICE, INSTANCE_ATTR_LIMITS, INSTANCE_ATTR_WATCH, + INSTANCE_ATTR_ERROR, __INSTANCE_ATTR_MAX }; @@ -53,6 +54,7 @@ static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = { [INSTANCE_ATTR_NICE] = { "nice", BLOBMSG_TYPE_INT32 }, [INSTANCE_ATTR_LIMITS] = { "limits", BLOBMSG_TYPE_TABLE }, [INSTANCE_ATTR_WATCH] = { "watch", BLOBMSG_TYPE_ARRAY }, + [INSTANCE_ATTR_ERROR] = { "error", BLOBMSG_TYPE_ARRAY }, }; struct instance_netdev { @@ -165,6 +167,11 @@ instance_start(struct service_instance *in) { int pid; + if (!avl_is_empty(&in->errors.avl)) { + LOG("Not starting instance %s::%s, an error was indicated\n", in->srv->name, in->name); + return; + } + if (in->proc.pending) return; @@ -287,6 +294,9 @@ instance_config_changed(struct service_instance *in, struct service_instance *in if (!blobmsg_list_equal(&in->limits, &in_new->limits)) return true; + if (!blobmsg_list_equal(&in->errors, &in_new->errors)) + return true; + return false; } @@ -448,6 +458,9 @@ instance_config_parse(struct service_instance *in) if (!instance_fill_array(&in->limits, tb[INSTANCE_ATTR_LIMITS], NULL, false)) return false; + if (!instance_fill_array(&in->errors, tb[INSTANCE_ATTR_ERROR], NULL, true)) + return false; + return true; } @@ -459,6 +472,7 @@ instance_config_cleanup(struct service_instance *in) blobmsg_list_free(&in->netdev); blobmsg_list_free(&in->file); blobmsg_list_free(&in->limits); + blobmsg_list_free(&in->errors); } static void @@ -470,6 +484,7 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr blobmsg_list_move(&in->netdev, &in_src->netdev); blobmsg_list_move(&in->file, &in_src->file); blobmsg_list_move(&in->limits, &in_src->limits); + blobmsg_list_move(&in->errors, &in_src->errors); in->trigger = in_src->trigger; in->command = in_src->command; in->name = in_src->name; @@ -529,6 +544,7 @@ instance_init(struct service_instance *in, struct service *s, struct blob_attr * blobmsg_list_simple_init(&in->env); blobmsg_list_simple_init(&in->data); blobmsg_list_simple_init(&in->limits); + blobmsg_list_simple_init(&in->errors); in->valid = instance_config_parse(in); } @@ -542,6 +558,14 @@ void instance_dump(struct blob_buf *b, struct service_instance *in, int verbose) blobmsg_add_u32(b, "pid", in->proc.pid); blobmsg_add_blob(b, in->command); + if (!avl_is_empty(&in->errors.avl)) { + struct blobmsg_list_node *var; + void *e = blobmsg_open_array(b, "errors"); + blobmsg_list_for_each(&in->errors, var) + blobmsg_add_string(b, NULL, blobmsg_data(var->data)); + blobmsg_close_table(b, e); + } + if (!avl_is_empty(&in->env.avl)) { struct blobmsg_list_node *var; void *e = blobmsg_open_table(b, "env"); diff --git a/service/instance.h b/service/instance.h index e7416ab..a492f38 100644 --- a/service/instance.h +++ b/service/instance.h @@ -50,6 +50,7 @@ struct service_instance { struct blobmsg_list netdev; struct blobmsg_list file; struct blobmsg_list limits; + struct blobmsg_list errors; }; void instance_start(struct service_instance *in); |