Fix missing strncmp return value comparison
[lttng-tools.git] / src / bin / lttng / commands / list.c
index 743b79ff2431f826ec2d623fe1957c834bff0a0d..da287f5caf9c4a7658b30f4419cf1be7aebb66bb 100644 (file)
@@ -70,22 +70,22 @@ static struct poptOption long_options[] = {
  */
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "usage: lttng list [[-k] [-u] [-p PID] [SESSION [<options>]]]\n");
+       fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [<OPTIONS>]]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "With no arguments, list available tracing session(s)\n");
        fprintf(ofp, "\n");
-       fprintf(ofp, "With -k alone, list available kernel events\n");
-       fprintf(ofp, "With -u alone, list available userspace events\n");
+       fprintf(ofp, "Without a session, -k lists available kernel events\n");
+       fprintf(ofp, "Without a session, -u lists available userspace events\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help              Show this help\n");
-       fprintf(ofp, "      --list-options       Simple listing of options\n");
+       fprintf(ofp, "      --list-options      Simple listing of options\n");
        fprintf(ofp, "  -k, --kernel            Select kernel domain\n");
        fprintf(ofp, "  -u, --userspace         Select user-space domain.\n");
 #if 0
        fprintf(ofp, "  -p, --pid PID           List user-space events by PID\n");
 #endif
        fprintf(ofp, "\n");
-       fprintf(ofp, "Options:\n");
+       fprintf(ofp, "Session Options:\n");
        fprintf(ofp, "  -c, --channel NAME      List details of a channel\n");
        fprintf(ofp, "  -d, --domain            List available domain(s)\n");
        fprintf(ofp, "\n");
@@ -145,9 +145,9 @@ const char *enabled_string(int value)
 }
 
 static
-const char *loglevel_string_pre(const char *loglevel)
+const char *loglevel_string_pre(int loglevel)
 {
-       if (loglevel[0] == '\0') {
+       if (loglevel == -1) {
                return "";
        } else {
                return " (loglevel: ";
@@ -155,15 +155,39 @@ const char *loglevel_string_pre(const char *loglevel)
 }
 
 static
-const char *loglevel_string_post(const char *loglevel)
+const char *loglevel_string_post(int loglevel)
 {
-       if (loglevel[0] == '\0') {
+       if (loglevel == -1) {
                return "";
        } else {
                return ")";
        }
 }
 
+static const char *loglevel_string(int value)
+{
+       switch (value) {
+       case -1: return "";
+       case 0: return "TRACE_EMERG";
+       case 1: return "TRACE_ALERT";
+       case 2: return "TRACE_CRIT";
+       case 3: return "TRACE_ERR";
+       case 4: return "TRACE_WARNING";
+       case 5: return "TRACE_NOTICE";
+       case 6: return "TRACE_INFO";
+       case 7: return "TRACE_SYSTEM";
+       case 8: return "TRACE_PROCESS";
+       case 9: return "TRACE_MODULE";
+       case 10: return "TRACE_UNIT";
+       case 11: return "TRACE_CLASS";
+       case 12: return "TRACE_OBJECT";
+       case 13: return "TRACE_FUNCTION";
+       case 14: return "TRACE_PRINTF";
+       case 15: return "TRACE_DEBUG";
+       default: return "<<UNKNOWN>>";
+       }
+}
+
 /*
  * Pretty print single event.
  */
@@ -172,21 +196,11 @@ static void print_events(struct lttng_event *event)
        switch (event->type) {
        case LTTNG_EVENT_TRACEPOINT:
        {
-               char ll_value[LTTNG_SYMBOL_NAME_LEN] = "";
-
-               if (event->loglevel[0] != '\0') {
-                       int ret;
-
-                       ret = snprintf(ll_value, LTTNG_SYMBOL_NAME_LEN,
-                               " (%lld)", (long long) event->loglevel_value);
-                       if (ret < 0)
-                               ERR("snprintf error");
-               }
-               MSG("%s%s%s%s%s%s (type: tracepoint)%s", indent6,
+               MSG("%s%s%s%s%d%s (type: tracepoint)%s", indent6,
                                event->name,
                                loglevel_string_pre(event->loglevel),
+                               loglevel_string(event->loglevel),
                                event->loglevel,
-                               ll_value,
                                loglevel_string_post(event->loglevel),
                                enabled_string(event->enabled));
                break;
@@ -215,11 +229,6 @@ static void print_events(struct lttng_event *event)
                MSG("%s (type: noop)%s", indent6,
                                enabled_string(event->enabled));
                break;
-       case LTTNG_EVENT_TRACEPOINT_LOGLEVEL:
-               MSG("%s%s (type: tracepoint loglevel)%s", indent6,
-                       event->name,
-                       enabled_string(event->enabled));
-               break;
        case LTTNG_EVENT_ALL:
                /* We should never have "all" events in list. */
                assert(0);
@@ -393,10 +402,10 @@ static int list_channels(const char *channel_name)
        count = lttng_list_channels(handle, &channels);
        if (count < 0) {
                ret = count;
-               goto error;
+               goto error_channels;
        } else if (count == 0) {
-               MSG("No channel found");
-               goto end;
+               ERR("Channel %s not found", channel_name);
+               goto error;
        }
 
        if (channel_name == NULL) {
@@ -425,14 +434,16 @@ static int list_channels(const char *channel_name)
        }
 
        if (!chan_found && channel_name != NULL) {
-               MSG("Channel %s not found", channel_name);
+               ERR("Channel %s not found", channel_name);
+               goto error;
        }
 
-end:
-       free(channels);
        ret = CMD_SUCCESS;
 
 error:
+       free(channels);
+
+error_channels:
        return ret;
 }
 
@@ -479,7 +490,7 @@ static int list_sessions(const char *session_name)
        free(sessions);
 
        if (!session_found && session_name != NULL) {
-               MSG("Session %s not found", session_name);
+               ERR("Session %s not found", session_name);
        }
 
        if (session_name == NULL) {
@@ -545,6 +556,7 @@ int cmd_list(int argc, const char **argv)
 
        if (argc < 1) {
                usage(stderr);
+               ret = CMD_ERROR;
                goto end;
        }
 
@@ -554,14 +566,13 @@ int cmd_list(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stderr);
+                       usage(stdout);
                        goto end;
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
-                       ret = CMD_SUCCESS;
                        goto end;
                default:
                        usage(stderr);
@@ -583,6 +594,7 @@ int cmd_list(int argc, const char **argv)
 
        handle = lttng_create_handle(session_name, &domain);
        if (handle == NULL) {
+               ret = CMD_FATAL;
                goto end;
        }
 
@@ -596,12 +608,14 @@ int cmd_list(int argc, const char **argv)
                if (opt_kernel) {
                        ret = list_kernel_events();
                        if (ret < 0) {
+                               ret = CMD_ERROR;
                                goto end;
                        }
                }
                if (opt_userspace) {
                        ret = list_ust_events();
                        if (ret < 0) {
+                               ret = CMD_ERROR;
                                goto end;
                        }
                }
@@ -615,6 +629,9 @@ int cmd_list(int argc, const char **argv)
                /* Domain listing */
                if (opt_domain) {
                        ret = list_domains(session_name);
+                       if (ret < 0) {
+                               ret = CMD_ERROR;
+                       }
                        goto end;
                }
 
@@ -622,13 +639,14 @@ int cmd_list(int argc, const char **argv)
                        /* Channel listing */
                        ret = list_channels(opt_channel);
                        if (ret < 0) {
+                               ret = CMD_ERROR;
                                goto end;
                        }
                } else {
                        /* We want all domain(s) */
                        nb_domain = lttng_list_domains(session_name, &domains);
                        if (nb_domain < 0) {
-                               ret = nb_domain;
+                               ret = CMD_ERROR;
                                goto end;
                        }
 
@@ -650,11 +668,13 @@ int cmd_list(int argc, const char **argv)
 
                                handle = lttng_create_handle(session_name, &domains[i]);
                                if (handle == NULL) {
+                                       ret = CMD_FATAL;
                                        goto end;
                                }
 
                                ret = list_channels(opt_channel);
                                if (ret < 0) {
+                                       ret = CMD_ERROR;
                                        goto end;
                                }
                        }
@@ -667,5 +687,6 @@ end:
        }
        lttng_destroy_handle(handle);
 
+       poptFreeContext(pc);
        return ret;
 }
This page took 0.037678 seconds and 4 git commands to generate.