>From 6429ddf6047b50fb5d917d451fd6612ad57a5ed6 Thu, 2 Feb 2012 15:37:36 -0500 From: Daniel U. Thibault <[email protected]> Date: Thu, 2 Feb 2012 15:37:24 -0500 Subject: [PATCH] disable_channels.c : Document and enforce return values, enforce exactly one domain flag, adjust usage() output accordingly, handle channel list errors
Signed-off-by: Daniel U. Thibault <[email protected]> diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index ccd5446..7dc3b39 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -67,6 +67,7 @@ static void usage(FILE *ofp) { fprintf(ofp, "usage: lttng disable-channel 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"); @@ -75,7 +76,7 @@ #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"); @@ -85,6 +86,7 @@ /* * Disabling channel using the lttng API. + * Returns a CMD_* result value. */ static int disable_channels(char *session_name) { @@ -93,24 +95,24 @@ struct lttng_domain dom; /* Create lttng domain */ + /* cmd_disable_channels() 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 */ } handle = lttng_create_handle(session_name, &dom); if (handle == NULL) { - ret = -1; + ret = CMD_FATAL; goto error; } /* Strip channel list */ channel_name = strtok(opt_channels, ","); + /* Default to a warning in case opt_channels is empty */ + ret = CMD_WARNING; while (channel_name != NULL) { DBG("Disabling channel %s", channel_name); @@ -123,12 +125,15 @@ MSG("%s channel %s disabled for session %s", opt_kernel ? "Kernel" : "UST", channel_name, session_name); } + ret = CMD_SUCCESS; /* Next channel */ channel_name = strtok(NULL, ","); } - - ret = CMD_SUCCESS; + if (ret == CMD_WARNING) { + ERR("No channels specified for %s session %s", + (opt_kernel ? "kernel" : "UST"), session_name); + } error: if (warn) { @@ -141,9 +146,8 @@ } /* - * cmd_disable_channels - * - * Disable channel to trace session + * Disable channels of trace session + * Returns a CMD_* result value. */ int cmd_disable_channels(int argc, const char **argv) { @@ -172,6 +176,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_channels = (char*) poptGetArg(pc); if (opt_channels == NULL) { ERR("Missing channel name(s).\n"); @@ -180,14 +196,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_channels(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
