+}
+
+/**************** report state of runner *********************/
+
+/*
+ * Creates a json object that describes the state of 'runner'.
+ *
+ * Returns the created object or NULL in case of error.
+ */
+static json_object *mkstate(struct apprun *runner)
+{
+ const char *state;
+ struct json_object *result, *obj, *pids;
+ int rc;
+
+ /* the structure */
+ result = json_object_new_object();
+ if (result == NULL)
+ goto error;
+
+ /* the runid */
+ if (!j_add_integer(result, "runid", runner->runid))
+ goto error2;
+
+ /* the pids */
+ if (is_alive(runner)) {
+ pids = j_add_new_array(result, "pids");
+ if (!pids)
+ goto error2;
+ if (!j_add_integer(pids, NULL, runner->pids[0]))
+ goto error2;
+ if (runner->pids[1] && !j_add_integer(pids, NULL, runner->pids[1]))
+ goto error2;
+ }
+
+ /* the state */
+ switch(runner->state) {
+ case as_starting:
+ case as_running:
+ state = "running";
+ break;
+ case as_paused:
+ state = "paused";
+ break;
+ default:
+ state = "terminated";
+ break;
+ }
+ if (!j_add_string(result, "state", state))
+ goto error2;
+
+ /* the application id */
+ rc = json_object_object_get_ex(runner->appli, "public", &obj);
+ assert(rc);
+ rc = json_object_object_get_ex(obj, "id", &obj);
+ assert(rc);
+ if (!j_add(result, "id", obj))
+ goto error2;
+ json_object_get(obj);
+
+ /* done */
+ return result;
+
+error2:
+ json_object_put(result);
+error:
+ errno = ENOMEM;
+ return NULL;
+}