Fix: lttng UI exit value and error message
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index bc520b3f6986a1e290ff1b7a2948f18435d0d30a..860472fa9c370e8a1d934065d9c2cde54ca0975a 100644 (file)
@@ -1,19 +1,18 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _GNU_SOURCE
@@ -28,6 +27,7 @@
 #include <ctype.h>
 
 #include "../command.h"
+#include <src/common/sessiond-comm/sessiond-comm.h>
 
 static char *opt_event_list;
 static int opt_event_type;
@@ -104,7 +104,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply to session name\n");
        fprintf(ofp, "  -c, --channel            Apply to this channel\n");
-       fprintf(ofp, "  -a, --all                Enable all tracepoints\n");
+       fprintf(ofp, "  -a, --all                Enable all tracepoints and syscalls\n");
        fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
 #if 0
        fprintf(ofp, "  -u, --userspace [CMD]    Apply to the user-space tracer\n");
@@ -346,14 +346,29 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       goto error;
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel events already enabled (channel %s, session %s)",
+                                               channel_name, session_name);
+                               goto end;
+                       default:
+                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
                }
 
                switch (opt_event_type) {
                case LTTNG_EVENT_TRACEPOINT:
-                       MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
-                               opt_kernel ? "kernel" : "UST", channel_name,
-                               opt_loglevel ? : "<all>");
+                       if (opt_loglevel) {
+                               MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
+                                       opt_kernel ? "kernel" : "UST", channel_name,
+                                       opt_loglevel);
+                       } else {
+                               MSG("All %s tracepoints are enabled in channel %s",
+                                       opt_kernel ? "kernel" : "UST", channel_name);
+
+                       }
                        break;
                case LTTNG_EVENT_SYSCALL:
                        if (opt_kernel) {
@@ -362,9 +377,14 @@ static int enable_events(char *session_name)
                        }
                        break;
                case LTTNG_EVENT_ALL:
-                       MSG("All %s events are enabled in channel %s for loglevel %s",
-                               opt_kernel ? "kernel" : "UST", channel_name,
-                               opt_loglevel ? : "<all>");
+                       if (opt_loglevel) {
+                               MSG("All %s events are enabled in channel %s for loglevel %s",
+                                       opt_kernel ? "kernel" : "UST", channel_name,
+                                       opt_loglevel);
+                       } else {
+                               MSG("All %s events are enabled in channel %s",
+                                       opt_kernel ? "kernel" : "UST", channel_name);
+                       }
                        break;
                default:
                        /*
@@ -482,8 +502,17 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       ERR("Event %s: %s (channel %s, session %s)", event_name,
-                                       lttng_strerror(ret), channel_name, session_name);
+                       /* Turn ret to positive value to handle the positive error code */
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel event %s already enabled (channel %s, session %s)",
+                                               event_name, channel_name, session_name);
+                               break;
+                       default:
+                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
                        warn = 1;
                } else {
                        MSG("%s event %s created in channel %s",
This page took 0.028215 seconds and 4 git commands to generate.