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
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;
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);
+}
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
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,
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);