afb-config: Add traceses for tracing sessions
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 26 Feb 2018 12:35:43 +0000 (13:35 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 26 Feb 2018 12:46:38 +0000 (13:46 +0100)
Change-Id: I9d36eb9eb4991066f94b1340262ad27467fc591e
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-config.c
src/afb-config.h
src/main.c

index fc3f5d7..6c77c1d 100644 (file)
@@ -97,6 +97,7 @@
 #define SET_QUIET          'q'
 #define SET_RNDTOKEN       'r'
 #define SET_TRACESVC       'S'
+#define SET_TRACESES       's'
 #define SET_TRACEREQ       'T'
 #define SET_AUTH_TOKEN     't'
 #define SET_UPLOAD_DIR     'u'
 #define SET_WORK_DIR       'w'
 
 const char shortopts[] =
-       "c:D:E:ehn:p:qrT:t:u:Vvw:"
+       "c:D:E:ehn:p:qrS:s:T:t:u:Vvw:"
 #if defined(WITH_MONITORING_OPTION)
        "M"
 #endif
@@ -169,6 +170,7 @@ static AFB_options cliOptions[] = {
        {SET_TRACEDITF,     1, "traceditf",   "Log the requests: no, common, extra, all"},
        {SET_TRACESVC,      1, "tracesvc",    "Log the requests: no, all"},
        {SET_TRACEEVT,      1, "traceevt",    "Log the requests: no, common, extra, all"},
+       {SET_TRACESES,      1, "traceses",    "Log the sessions: no, all"},
 
        {ADD_CALL,          1, "call",        "call at start format of val: API/VERB:json-args"},
 
@@ -219,6 +221,13 @@ static struct enumdesc traceevt_desc[] = {
        { NULL, 0 }
 };
 
+static struct enumdesc traceses_desc[] = {
+       { "no",     0 },
+       { "common", afb_hook_flags_session_common },
+       { "all",    afb_hook_flags_session_all },
+       { NULL, 0 }
+};
+
 static struct enumdesc mode_desc[] = {
        { "local",  AFB_MODE_LOCAL },
        { "remote", AFB_MODE_REMOTE },
@@ -588,6 +597,10 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config)
                        config->traceevt = argvalenum(optc, traceevt_desc);
                        break;
 
+               case SET_TRACESES:
+                       config->traceses = argvalenum(optc, traceses_desc);
+                       break;
+
                case SET_NO_HTTPD:
                        noarg(optc);
                        config->noHttpd = 1;
@@ -734,6 +747,7 @@ void afb_config_dump(struct afb_config *config)
        E(traceditf,traceditf_desc)
        E(tracesvc,tracesvc_desc)
        E(traceevt,traceevt_desc)
+       E(traceses,traceses_desc)
 
        B(no_ldpaths)
        B(noHttpd)
@@ -787,6 +801,7 @@ static void parse_environment(struct afb_config *config)
        on_environment_enum(&config->traceditf, "AFB_TRACEDITF", traceditf_desc);
        on_environment_enum(&config->tracesvc, "AFB_TRACESVC", tracesvc_desc);
        on_environment_enum(&config->traceevt, "AFB_TRACEEVT", traceevt_desc);
+       on_environment_enum(&config->traceses, "AFB_TRACESES", traceses_desc);
        on_environment_list(&config->ldpaths, "AFB_LDPATHS");
 }
 
@@ -864,6 +879,7 @@ struct json_object *afb_config_json(struct afb_config *config)
        E(traceditf,traceditf_desc)
        E(tracesvc,tracesvc_desc)
        E(traceevt,traceevt_desc)
+       E(traceses,traceses_desc)
 
        B(no_ldpaths)
        B(noHttpd)
index 9f87651..c46cd5a 100644 (file)
@@ -64,6 +64,7 @@ struct afb_config {
        int traceditf;
        int tracesvc;
        int traceevt;
+       int traceses;
 
        /* booleans */
        unsigned no_ldpaths: 1;         /* disable default ldpaths */
index e3f4251..c735ecb 100644 (file)
@@ -585,6 +585,8 @@ static void start(int signum, void *arg)
                afb_hook_create_svc(NULL, main_config->tracesvc, NULL, NULL);
        if (main_config->traceevt)
                afb_hook_create_evt(NULL, main_config->traceevt, NULL, NULL);
+       if (main_config->traceses)
+               afb_hook_create_session(NULL, main_config->traceses, NULL, NULL);
 
        /* load bindings */
        afb_debug("start-load");