Use compiler-agnostic defines to silence warning
[lttng-tools.git] / src / bin / lttng / commands / add_context.cpp
index cc5e487df3b8b0d8398c32a7c229af07f061f4c9..497a12065b26de4225bc9ebb0ce7cc28c75acf45 100644 (file)
@@ -29,6 +29,7 @@ static int opt_kernel;
 static int opt_userspace;
 static int opt_jul;
 static int opt_log4j;
 static int opt_userspace;
 static int opt_jul;
 static int opt_log4j;
+static int opt_log4j2;
 static char *opt_type;
 
 #ifdef LTTNG_EMBED_HELP
 static char *opt_type;
 
 #ifdef LTTNG_EMBED_HELP
@@ -43,6 +44,7 @@ enum {
        OPT_USERSPACE,
        OPT_JUL,
        OPT_LOG4J,
        OPT_USERSPACE,
        OPT_JUL,
        OPT_LOG4J,
+       OPT_LOG4J2,
        OPT_LIST_OPTIONS,
        OPT_LIST,
 };
        OPT_LIST_OPTIONS,
        OPT_LIST,
 };
@@ -175,6 +177,7 @@ static struct poptOption long_options[] = {
        { "userspace", 'u', POPT_ARG_NONE, nullptr, OPT_USERSPACE, nullptr, nullptr },
        { "jul", 'j', POPT_ARG_NONE, nullptr, OPT_JUL, nullptr, nullptr },
        { "log4j", 'l', POPT_ARG_NONE, nullptr, OPT_LOG4J, nullptr, nullptr },
        { "userspace", 'u', POPT_ARG_NONE, nullptr, OPT_USERSPACE, nullptr, nullptr },
        { "jul", 'j', POPT_ARG_NONE, nullptr, OPT_JUL, nullptr, nullptr },
        { "log4j", 'l', POPT_ARG_NONE, nullptr, OPT_LOG4J, nullptr, nullptr },
+       { "log4j2", 0, POPT_ARG_NONE, nullptr, OPT_LOG4J2, nullptr, nullptr },
        { "type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, nullptr, nullptr },
        { "list", 0, POPT_ARG_NONE, nullptr, OPT_LIST, nullptr, nullptr },
        { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
        { "type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, nullptr, nullptr },
        { "list", 0, POPT_ARG_NONE, nullptr, OPT_LIST, nullptr, nullptr },
        { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
@@ -514,6 +517,8 @@ static enum lttng_domain_type get_domain()
                return LTTNG_DOMAIN_JUL;
        } else if (opt_log4j) {
                return LTTNG_DOMAIN_LOG4J;
                return LTTNG_DOMAIN_JUL;
        } else if (opt_log4j) {
                return LTTNG_DOMAIN_LOG4J;
+       } else if (opt_log4j2) {
+               return LTTNG_DOMAIN_LOG4J2;
        } else {
                abort();
        }
        } else {
                abort();
        }
@@ -812,9 +817,16 @@ static void destroy_ctx_type(struct ctx_type *type)
        if (!type) {
                return;
        }
        if (!type) {
                return;
        }
+
        if (type->opt) {
                free(type->opt->symbol);
        if (type->opt) {
                free(type->opt->symbol);
+
+               if (type->opt->ctx_type == CONTEXT_APP_CONTEXT) {
+                       free(type->opt->u.app_ctx.ctx_name);
+                       free(type->opt->u.app_ctx.provider_name);
+               }
        }
        }
+
        delete type->opt;
        free(type);
 }
        delete type->opt;
        free(type);
 }
@@ -976,7 +988,7 @@ static struct ctx_type *get_context_type(const char *ctx)
        }
 
        /* String starts with $app. */
        }
 
        /* String starts with $app. */
-       if (strncmp(ctx, app_ctx_prefix, sizeof(app_ctx_prefix) - 1)) {
+       if (strncmp(ctx, app_ctx_prefix, sizeof(app_ctx_prefix) - 1) != 0) {
                goto not_found;
        }
 
                goto not_found;
        }
 
@@ -1074,6 +1086,9 @@ int cmd_add_context(int argc, const char **argv)
                case OPT_LOG4J:
                        opt_log4j = 1;
                        break;
                case OPT_LOG4J:
                        opt_log4j = 1;
                        break;
+               case OPT_LOG4J2:
+                       opt_log4j2 = 1;
+                       break;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
                        goto end;
@@ -1090,8 +1105,8 @@ int cmd_add_context(int argc, const char **argv)
                goto end;
        }
 
                goto end;
        }
 
-       ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + opt_jul + opt_log4j,
-                                               true);
+       ret = print_missing_or_multiple_domains(
+               opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_log4j2, true);
        if (ret) {
                ret = CMD_ERROR;
                goto end;
        if (ret) {
                ret = CMD_ERROR;
                goto end;
This page took 0.025845 seconds and 4 git commands to generate.