diff options
-rw-r--r-- | instance.c | 14 | ||||
-rw-r--r-- | instance.h | 1 | ||||
-rw-r--r-- | service.c | 22 |
3 files changed, 31 insertions, 6 deletions
@@ -173,6 +173,7 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr blobmsg_list_move(&in->env, &in_src->env); blobmsg_list_move(&in->data, &in_src->data); in->command = in_src->command; + in->name = in_src->name; } bool @@ -202,6 +203,7 @@ instance_free(struct service_instance *in) void instance_init(struct service_instance *in, struct blob_attr *config) { + in->name = blobmsg_name(config); in->config = config; in->timeout.cb = instance_timeout; in->proc.cb = instance_exit; @@ -210,3 +212,15 @@ instance_init(struct service_instance *in, struct blob_attr *config) blobmsg_list_simple_init(&in->data); in->valid = instance_config_parse(in); } + +void instance_dump(struct blob_buf *b, struct service_instance *in) +{ + void *i; + + i = blobmsg_open_table(b, in->name); + blobmsg_add_u8(b, "running", in->proc.pending); + if (in->proc.pending) + blobmsg_add_u32(b, "pid", in->proc.pid); + blobmsg_add_blob(b, in->command); + blobmsg_close_table(b, i); +} @@ -25,5 +25,6 @@ void instance_stop(struct service_instance *in, bool restart); bool instance_update(struct service_instance *in, struct service_instance *in_new); void instance_init(struct service_instance *in, struct blob_attr *config); void instance_free(struct service_instance *in); +void instance_dump(struct blob_buf *b, struct service_instance *in); #endif @@ -148,6 +148,20 @@ free: return ret; } +static void +service_dump(struct service *s) +{ + struct service_instance *in; + void *c, *i; + + c = blobmsg_open_table(&b, s->name); + i = blobmsg_open_table(&b, "instances"); + vlist_for_each_element(&s->instances, in, node) + instance_dump(&b, in); + blobmsg_close_table(&b, i); + blobmsg_close_table(&b, c); +} + static int service_handle_list(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -156,12 +170,8 @@ service_handle_list(struct ubus_context *ctx, struct ubus_object *obj, struct service *s; blob_buf_init(&b, 0); - avl_for_each_element(&services, s, avl) { - void *c; - - c = blobmsg_open_table(&b, s->name); - blobmsg_close_table(&b, c); - } + avl_for_each_element(&services, s, avl) + service_dump(s); ubus_send_reply(ctx, req, b.head); |