diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-06-18 00:36:06 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-07-10 23:59:54 +0200 |
commit | 81c7dd2c3248f0df563c21b444441ef92067167f (patch) | |
tree | 9da6ba813af1945eee7026dbefb68ab5e377226c /src/plugins/supervisor.c | |
parent | 5d0e551a25edeba7df7f64b1370bad7558b9b2f1 (diff) |
Improved trace verb to support list of pids
Change-Id: Ia6e650f2a7edf29d1f135fb47e5a513bcd83b3c8
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'src/plugins/supervisor.c')
-rw-r--r-- | src/plugins/supervisor.c | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/src/plugins/supervisor.c b/src/plugins/supervisor.c index e3c71c0..598ba68 100644 --- a/src/plugins/supervisor.c +++ b/src/plugins/supervisor.c @@ -123,6 +123,14 @@ static void decode_daemons_cb(void* closure, json_object* obj, const char* fName if (json_object_object_get_ex(j_response, "response", &j_config) && json_object_object_get_ex(j_config, "apis", &j_apis)) { // Don't forward monitor config details json_object_object_del(j_apis, "monitor"); + + // Only forward apis verb without all details + /* TODO + j_newApis = json_object_new_object(); + json_object_object_foreach(json_object_object_get(j_apis, "apis"), key, val) { + ... + } + */ daemon->apis = j_apis; } } @@ -171,34 +179,26 @@ int getDaemons(AFB_ApiT apiHandle, DAEMONS_T** daemons) #define XDS_TAG_EVENT "xds:trace/event" #define XDS_TRACE_NAME "xds-trace" -int trace_exchange(AFB_ApiT apiHandle, DAEMON_T* svr, DAEMON_T* cli, const char* level) +int trace_daemon(AFB_ApiT apiHandle, DAEMON_T* dm, const char* level) { int rc; json_object *j_response, *j_query, *j_tracereq, *j_traceevt; - if (svr == NULL || cli == NULL) { + if (dm == NULL) { return -1; } // First drop previous traces - // monitor/trace({ "drop": { "tag": "trace/request" } }) // Note: ignored error (expected 1st time/when no trace exist) - wrap_json_pack(&j_query, "{s:i s:{s:[s s]}}", "pid", svr->pid, - "drop", "tag", XDS_TAG_REQUEST, XDS_TAG_EVENT); - AFB_ServiceSync(apiHandle, SRV_SUPERVISOR_NAME, "trace", j_query, &j_response); - - wrap_json_pack(&j_query, "{s:i s:{s:[s s]}}", "pid", cli->pid, - "drop", "tag", XDS_TAG_REQUEST, XDS_TAG_EVENT); - AFB_ServiceSync(apiHandle, SRV_SUPERVISOR_NAME, "trace", j_query, &j_response); + trace_drop(apiHandle, dm->pid); j_tracereq = json_object_new_array(); if (level && !strncmp(level, "all", 3)) { json_object_array_add(j_tracereq, json_object_new_string("all")); } else { json_object_array_add(j_tracereq, json_object_new_string("life")); - json_object_array_add(j_tracereq, json_object_new_string("result")); + json_object_array_add(j_tracereq, json_object_new_string("reply")); } - json_object_get(j_tracereq); // because use 2 times to configure both server and client j_traceevt = json_object_new_array(); if (level && !strncmp(level, "all", 3)) { @@ -206,35 +206,31 @@ int trace_exchange(AFB_ApiT apiHandle, DAEMON_T* svr, DAEMON_T* cli, const char* } else { json_object_array_add(j_traceevt, json_object_new_string("common")); } - json_object_get(j_traceevt); // because use 2 times to configure both server and client - // Configure trace for server daemon + // Configure tracing of specified daemon // request: monitor/trace({ "add": { "tag": "xds:trace/request", "name": "trace", "request": "all" } }) wrap_json_pack(&j_query, "{s:i, s: [{s:s s:s s:o}, {s:s s:s s:o}] }", - "pid", svr->pid, "add", + "pid", dm->pid, "add", "tag", XDS_TAG_REQUEST, "name", XDS_TRACE_NAME, "request", j_tracereq, "tag", XDS_TAG_EVENT, "name", XDS_TRACE_NAME, "event", j_traceevt); if ((rc = AFB_ServiceSync(apiHandle, SRV_SUPERVISOR_NAME, "trace", j_query, &j_response)) < 0) { - AFB_ApiError(apiHandle, "ERROR trace %d result: %s", svr->pid, + AFB_ApiError(apiHandle, "ERROR tracing pid %d result: %s", dm->pid, json_object_to_json_string(j_response)); return rc; } - // Configure trace for client daemon(s) - // request: monitor/trace({ "pid": 1234, "add": { "event": "all" } }) - wrap_json_pack(&j_query, "{s:i, s: [{s:s s:s s:o}, {s:s s:s s:o}] }", - "pid", cli->pid, "add", - "tag", XDS_TAG_REQUEST, "name", XDS_TRACE_NAME, "request", j_tracereq, - "tag", XDS_TAG_EVENT, "name", XDS_TRACE_NAME, "event", j_traceevt); + return 0; +} - if ((rc = AFB_ServiceSync(apiHandle, SRV_SUPERVISOR_NAME, "trace", j_query, &j_response)) < 0) { - AFB_ApiError(apiHandle, "ERROR trace %d result: %s", cli->pid, - json_object_to_json_string(j_response)); - return rc; - } +// FIXME prototype must be int trace_drop(AFB_ApiT apiHandle, DAEMON_T* dm) +int trace_drop(AFB_ApiT apiHandle, int pid) +{ + json_object *j_response, *j_query; - return 0; + // monitor/trace({ "drop": { "tag": "trace/request" } }) + wrap_json_pack(&j_query, "{s:i s:{s:[s s]}}", "pid", pid, "drop", "tag", XDS_TAG_REQUEST, XDS_TAG_EVENT); + return AFB_ServiceSync(apiHandle, SRV_SUPERVISOR_NAME, "trace", j_query, &j_response); } int supervisor_init(void) |