>From a40c0bda2e4849befbfc51cbcd3f92729e0443ce Thu, 2 Feb 2012 15:29:38 -0500
From: Daniel U. Thibault <[email protected]>
Date: Thu, 2 Feb 2012 15:29:27 -0500
Subject: [PATCH] disable_events.c : Document and enforce return values, enforce 
exactly one domain flag, adjust usage() output accordingly, handle event list 
errors

Signed-off-by: Daniel U. Thibault <[email protected]>

diff --git a/src/bin/lttng/commands/disable_events.c 
b/src/bin/lttng/commands/disable_events.c
index b30ec1f..062a784 100644
--- a/src/bin/lttng/commands/disable_events.c
+++ b/src/bin/lttng/commands/disable_events.c
@@ -71,17 +71,18 @@
 static void usage(FILE *ofp)
 {
        fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
+       fprintf(ofp, "Exactly one domain (-k/--kernel or -u/--userspace) must 
be specified.\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
        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-events         Disable all tracepoints\n");
-       fprintf(ofp, "  -k, --kernel             Apply for the kernel 
tracer\n");
+       fprintf(ofp, "  -k, --kernel             Apply to the kernel tracer\n");
 #if 0
        fprintf(ofp, "  -u, --userspace [CMD]    Apply to the user-space 
tracer\n");
        fprintf(ofp, "                           If no CMD, the domain used is 
UST global\n");
-       fprintf(ofp, "                           or else the domain is UST 
EXEC_NAME\n");
+       fprintf(ofp, "                           otherwise the domain is UST 
EXEC_NAME\n");
        fprintf(ofp, "  -p, --pid PID            If -u, apply to specific PID 
(domain: UST PID)\n");
 #else
        fprintf(ofp, "  -u, --userspace          Apply to the user-space 
tracer\n");
@@ -90,9 +91,8 @@
 }
 
 /*
- *  disable_events
- *
  *  Disabling event using the lttng API.
+ *  Returns a CMD_* result value.
  */
 static int disable_events(char *session_name)
 {
@@ -101,14 +101,12 @@
        struct lttng_domain dom;
 
        /* Create lttng domain */
+       /* cmd_disable_events() enforces the existence of just one domain flag 
*/
        if (opt_kernel) {
                dom.type = LTTNG_DOMAIN_KERNEL;
-       } else if (opt_userspace) {
+       } else { /* if (opt_userspace) { */
                dom.type = LTTNG_DOMAIN_UST;
-       } else {
-               ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_ERROR;
-               goto error;
+       /* TODO As LTTNG_DOMAIN_* values are added, capture them here */
        }
 
        /* Get channel name */
@@ -124,17 +122,19 @@
 
        handle = lttng_create_handle(session_name, &dom);
        if (handle == NULL) {
-               ret = -1;
+               ret = CMD_FATAL;
                goto error;
        }
 
        if (opt_disable_all) {
                ret = lttng_disable_event(handle, NULL, channel_name);
                if (ret < 0) {
-                       /* Don't set ret so lttng can interpret the sessiond 
error. */
+                       ERR("Event %s: %s (channel %s, session %s)", "<all>",
+                                       lttng_strerror(ret), channel_name, 
session_name);
+                       ret = CMD_ERROR;
                        goto error;
                }
-
+               ret = CMD_SUCCESS;
                MSG("All %s events are disabled in channel %s",
                                opt_kernel ? "kernel" : "UST", channel_name);
                goto end;
@@ -142,6 +142,8 @@
 
        /* Strip event list */
        event_name = strtok(opt_event_list, ",");
+       /* Default to a warning in case opt_event_list is empty */
+       ret = CMD_WARNING;
        while (event_name != NULL) {
                DBG("Disabling event %s", event_name);
 
@@ -155,12 +157,15 @@
                                        opt_kernel ? "kernel" : "UST", 
event_name, channel_name,
                                        session_name);
                }
+               ret = CMD_SUCCESS;
 
                /* Next event */
                event_name = strtok(NULL, ",");
        }
-
-       ret = CMD_SUCCESS;
+       if (ret == CMD_WARNING) {
+               ERR("No event specified for %s channel %s, session %s",
+                               (opt_kernel ? "kernel" : "UST"), channel_name, 
session_name);
+       }
 
 end:
 error:
@@ -176,9 +181,8 @@
 }
 
 /*
- *  cmd_disable_events
- *
- *  Disable event to trace session
+ *  Disable events of trace session
+ *  Returns a CMD_* result value.
  */
 int cmd_disable_events(int argc, const char **argv)
 {
@@ -207,6 +211,18 @@
                }
        }
 
+       /* Enforce requirement for exactly one domain */
+       /* Five LTTNG_DOMAIN_* values are currently planned */
+       if (!opt_userspace && !opt_kernel) {
+               ERR("No domain specified: Use one of -k/--kernel or 
-u/--userspace");
+               ret = CMD_ERROR;
+               goto end;
+       } else if (opt_userspace && opt_kernel) {
+               ERR("More than one domain specified");
+               ret = CMD_ERROR;
+               goto end;
+       }
+
        opt_event_list = (char*) poptGetArg(pc);
        if (opt_event_list == NULL && opt_disable_all == 0) {
                ERR("Missing event name(s).\n");
@@ -215,14 +231,10 @@
                goto end;
        }
 
-       if (!opt_session_name) {
-               session_name = get_session_name();
-               if (session_name == NULL) {
-                       ret = CMD_ERROR;
-                       goto end;
-               }
-       } else {
-               session_name = opt_session_name;
+       session_name = opt_session_name ? opt_session_name : get_session_name();
+       if (session_name == NULL) {
+               ret = CMD_ERROR;
+               goto end;
        }
 
        ret = disable_events(session_name);
------------------------------

Daniel U. Thibault
R & D pour la défense Canada - Valcartier (RDDC Valcartier) / Defence R&D 
Canada - Valcartier (DRDC Valcartier)
Système de systèmes (SdS) / System of Systems (SoS)
Solutions informatiques et expérimentations (SIE) / Computing Solutions and 
Experimentations (CSE)
2459 Boul. Pie XI Nord
Québec, QC  G3J 1X5
CANADA
Vox : (418) 844-4000 x4245
Fax : (418) 844-4538
NAC: 918V QSDJ
Gouvernement du Canada / Government of Canada
<http://www.valcartier.drdc-rddc.gc.ca/>

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to