-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 12-01-31 03:15 PM, Thibault, Daniel wrote:
> From 21f0eb1a7db1704645554d2f273bf80235be8240 Tue, 31 Jan 2012 15:13:29 -0500
> From: Daniel U. Thibault <[email protected]>
> 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 <[email protected]>
> 
> 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;

Actually, at this point, opt_channels *can not* be empty. There is a check
before calling this function.

So, if ret is cmd_success by default, only warn==1 will be enough after this
loop. Am I missing something ?

Thanks
David

>       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/>
> 
> _______________________________________________
> lttng-dev mailing list
> [email protected]
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJPKX4KAAoJEELoaioR9I02Z4AH/j8GbViEb5IbJWJrKZ5M64wk
2SWk1IuFH+zAWJpwF063OcoauDSU+/ltQ/9relC2jPvlqO5YbYHIOcyWJTXBLh3M
KUMBvzMWesqATqRH41YB/Q0V4GBhO8oNRyipCBA7aJSNmomjGT+OcOGkgQFO82dC
7o8S8z7cxFZlE4Mpc3+4tt1Zok1oWT7eE/bRgwLP3hRAdNpfzxGf47WuYQlGx6d1
DGaKoUrvwiT1rp4BWmYZdm9y760ILiFp6l0yXJHuVd50Zdt/GOEmOKbx10A8JfNV
4QBVUVQ8apT7YqOFTnE/ifOriKuiIa08YU6SmgV9Zr7vvOhUGKBK2tjoeeKFuKU=
=tpAp
-----END PGP SIGNATURE-----

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

Reply via email to