Fix return value and mem leak for all commands
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index 0fa3e916c835b48e2d9228ac8c86ee1e0e4a5dcf..49bae56b23872013abda97ffe665acfc014d72da 100644 (file)
@@ -341,7 +341,7 @@ static int enable_events(char *session_name)
                                goto error;
                        }
 
-                       if (opt_loglevel[0] != '\0') {
+                       if (opt_loglevel) {
                                MSG("Kernel loglevels are not supported.");
                                ret = CMD_UNDEFINED;
                                goto error;
@@ -381,8 +381,12 @@ static int enable_events(char *session_name)
                        }
 
                        ev.loglevel_type = opt_loglevel_type;
-                       strncpy(ev.loglevel, opt_loglevel, LTTNG_SYMBOL_NAME_LEN);
-                       ev.loglevel[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+                       if (opt_loglevel) {
+                               strncpy(ev.loglevel, opt_loglevel, LTTNG_SYMBOL_NAME_LEN);
+                               ev.loglevel[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+                       } else {
+                               ev.loglevel[0] = '\0';
+                       }
                } else {
                        ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
                        goto error;
@@ -413,7 +417,7 @@ error:
  */
 int cmd_enable_events(int argc, const char **argv)
 {
-       int opt, ret;
+       int opt, ret = CMD_SUCCESS;
        static poptContext pc;
        char *session_name = NULL;
 
@@ -426,8 +430,7 @@ int cmd_enable_events(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stderr);
-                       ret = CMD_SUCCESS;
+                       usage(stdout);
                        goto end;
                case OPT_TRACEPOINT:
                        opt_event_type = LTTNG_EVENT_TRACEPOINT;
@@ -457,7 +460,6 @@ int cmd_enable_events(int argc, const char **argv)
                        break;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
-                       ret = CMD_SUCCESS;
                        goto end;
                default:
                        usage(stderr);
@@ -470,14 +472,14 @@ int cmd_enable_events(int argc, const char **argv)
        if (opt_event_list == NULL && opt_enable_all == 0) {
                ERR("Missing event name(s).\n");
                usage(stderr);
-               ret = CMD_SUCCESS;
+               ret = CMD_ERROR;
                goto end;
        }
 
        if (!opt_session_name) {
                session_name = get_session_name();
                if (session_name == NULL) {
-                       ret = -1;
+                       ret = CMD_ERROR;
                        goto end;
                }
        } else {
@@ -491,5 +493,6 @@ end:
                free(session_name);
        }
 
+       poptFreeContext(pc);
        return ret;
 }
This page took 0.026231 seconds and 4 git commands to generate.