From: Daniel.Thibault@drdc-rddc.gc.ca (Thibault, Daniel)
Subject: [lttng-dev] [PATCH] disable_channels.c improvements and fixes
Date: Tue, 31 Jan 2012 15:15:44 -0500 [thread overview]
Message-ID: <3CA1A65C03C1A34C81BBC6272782E696808AAB@valcartierex01.valcartier.drdc-rddc.gc.ca> (raw)
In-Reply-To: <mailman.1.1328029202.19563.lttng-dev@lists.lttng.org>
From 21f0eb1a7db1704645554d2f273bf80235be8240 Tue, 31 Jan 2012 15:13:29 -0500
From: Daniel U. Thibault <daniel.thibault@drdc-rddc.gc.ca>
Date: Tue, 31 Jan 2012 15:13:19 -0500
Subject: [PATCH] disable_channels.c improvements and fixes * Improve usage() printout * Document and enforce return values * Send --help to stdout * Issue CMD_WARNING for bad channel name(s) or an empty list of channel names * Fix a memory leak
Signed-off-by: Daniel U. Thibault <daniel.thibault at drdc-rddc.gc.ca>
diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c
index bdbb657..4202963 100644
--- a/src/bin/lttng/commands/disable_channels.c
+++ b/src/bin/lttng/commands/disable_channels.c
@@ -70,25 +70,29 @@
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 on session name\n");
- fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
+ fprintf(ofp, " -s, --session Apply to session name\n");
+ fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n");
#if 0
- fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
+ 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, " (--kernel preempts --userspace)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
- fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
+ fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
+ fprintf(ofp, " (--kernel preempts --userspace)\n");
#endif
fprintf(ofp, "\n");
}
/*
- * Disabling channel using the lttng API.
+ * Disabling channel(s) using the lttng API.
+ * session_name must not be NULL.
+ * Returns one of the CMD_* result values.
*/
static int disable_channels(char *session_name)
{
- int ret = CMD_SUCCESS;
+ int warn = 0, ret;
char *channel_name;
struct lttng_domain dom;
@@ -105,19 +109,25 @@
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
- ret = -1;
+ ret = CMD_ERROR;
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);
ret = lttng_disable_channel(handle, channel_name);
if (ret < 0) {
- goto error;
+ warn = 1;
+ ERR("%s channel %s unrecognised for session %s",
+ opt_kernel ? "Kernel" : "UST", channel_name,
+ session_name);
} else {
+ ret = CMD_SUCCESS;
MSG("%s channel %s disabled for session %s",
opt_kernel ? "Kernel" : "UST", channel_name,
session_name);
@@ -125,6 +135,13 @@
/* Next channel */
channel_name = strtok(NULL, ",");
+ }
+ if (ret == CMD_WARNING) {
+ ERR("No %s channel specified for session %s",
+ opt_kernel ? "kernel" : "UST", session_name);
+ }
+ if (warn) {
+ ret = CMD_WARNING;
}
error:
@@ -134,13 +151,13 @@
}
/*
- * cmd_disable_channels
- *
- * Disable channel to trace session
+ * Disable channel(s) of a trace session.
+ * Bad channel names or an empty list of channels will yield a warning.
+ * Returns a CMD_* result value.
*/
int cmd_disable_channels(int argc, const char **argv)
{
- int opt, ret;
+ int opt, ret = CMD_SUCCESS;
static poptContext pc;
char *session_name = NULL;
@@ -150,15 +167,13 @@
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stderr);
- ret = CMD_SUCCESS;
+ 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);
@@ -171,22 +186,23 @@
if (opt_channels == NULL) {
ERR("Missing channel 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;
- 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 cleanup;
}
ret = disable_channels(session_name);
+cleanup:
+ if (opt_session_name == NULL) {
+ free(session_name);
+ }
+
end:
return ret;
}
------------------------------
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/>
next prev parent reply other threads:[~2012-01-31 20:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1.1328029202.19563.lttng-dev@lists.lttng.org>
2012-01-31 17:31 ` [lttng-dev] [PATCH] Harmonise lttng.h and lttng-ctl.c documentation Thibault, Daniel
2012-01-31 19:04 ` [lttng-dev] [PATCH] add_context.c : Document return values, simplify session_name assignment in cmd_add_context() Thibault, Daniel
2012-01-31 19:32 ` [lttng-dev] [PATCH] create.c : Fix memory leak Thibault, Daniel
2012-01-31 20:15 ` Thibault, Daniel [this message]
2012-01-31 21:41 ` [lttng-dev] [PATCH] disable_channels.c and enable_channels.c Thibault, Daniel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3CA1A65C03C1A34C81BBC6272782E696808AAB@valcartierex01.valcartier.drdc-rddc.gc.ca \
--to=daniel.thibault@drdc-rddc.gc.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox