summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2012-06-24 21:32:39 +0200
committerFelix Fietkau <nbd@openwrt.org>2012-06-24 21:32:39 +0200
commit2c6b282d4b4a22e511e8cced48263fd0bc9cc6da (patch)
tree8676f387bde84ac09326bc8960e537428349f714
parentb17d66a55a8ed4124d98f8c80e7a3b7122650c5a (diff)
downloadunitd-2c6b282d4b4a22e511e8cced48263fd0bc9cc6da.tar
unitd-2c6b282d4b4a22e511e8cced48263fd0bc9cc6da.zip
dump status info
-rw-r--r--instance.c14
-rw-r--r--instance.h1
-rw-r--r--service.c22
3 files changed, 31 insertions, 6 deletions
diff --git a/instance.c b/instance.c
index c788f9d..41b9419 100644
--- a/instance.c
+++ b/instance.c
@@ -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);
+}
diff --git a/instance.h b/instance.h
index ebe4d20..7adaca6 100644
--- a/instance.h
+++ b/instance.h
@@ -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
diff --git a/service.c b/service.c
index 46f846d..1f1b1a8 100644
--- a/service.c
+++ b/service.c
@@ -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);