[lttng-dev] [PATCH] For all commands/*.c, add poptFreeContext(), send --help to stdout, default ret to CMD_SUCCESS

David Goulet david.goulet at polymtl.ca
Wed Feb 1 15:19:36 EST 2012


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

Merged thanks!

Good catch for the memleak.

David

On 12-02-01 01:59 PM, Thibault, Daniel wrote:
> From 6278f0a825f498faa349bc7c35e1fa8311e07491 Wed, 1 Feb 2012 13:56:43 -0500
> From: Daniel U. Thibault <daniel.thibault at drdc-rddc.gc.ca>
> Date: Wed, 1 Feb 2012 13:56:14 -0500
> Subject: [PATCH] For all commands/*.c, add poptFreeContext(), send --help to stdout, default ret to CMD_SUCCESS
> 
> Also fix some return values for list.c
> 
> Signed-off-by: Daniel U. Thibault <daniel.thibault at drdc-rddc.gc.ca>
> 
> diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c
> index ce65024..a1d776d 100644
> --- a/src/bin/lttng/commands/add_context.c
> +++ b/src/bin/lttng/commands/add_context.c
> @@ -466,7 +466,6 @@
>  		switch (opt) {
>  		case OPT_HELP:
>  			usage(stdout);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		case OPT_TYPE:
>  			/*
> @@ -505,7 +504,6 @@
>  			break;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -532,5 +530,6 @@
>  		free(type);
>  	}
>  
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c
> index a60cadf..547b349 100644
> --- a/src/bin/lttng/commands/calibrate.c
> +++ b/src/bin/lttng/commands/calibrate.c
> @@ -187,7 +187,7 @@
>   */
>  int cmd_calibrate(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  
>  	pc = poptGetContext(NULL, argc, argv, long_options, 0);
> @@ -200,7 +200,6 @@
>  		switch (opt) {
>  		case OPT_HELP:
>  			usage(stdout);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		case OPT_TRACEPOINT:
>  			ret = CMD_UNDEFINED;
> @@ -225,7 +224,6 @@
>  			break;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -237,5 +235,6 @@
>  	ret = calibrate_lttng();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c
> index 99e5daa..8fa23e3 100644
> --- a/src/bin/lttng/commands/create.c
> +++ b/src/bin/lttng/commands/create.c
> @@ -175,5 +175,6 @@
>  	ret = create_session();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.c
> index 39b4e9a..b0262ea 100644
> --- a/src/bin/lttng/commands/destroy.c
> +++ b/src/bin/lttng/commands/destroy.c
> @@ -117,11 +117,10 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> +			usage(stdout);
>  			goto end;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -135,5 +134,6 @@
>  	ret = destroy_session();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c
> index bdbb657..05ee0e6 100644
> --- a/src/bin/lttng/commands/disable_channels.c
> +++ b/src/bin/lttng/commands/disable_channels.c
> @@ -140,7 +140,7 @@
>   */
>  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 +150,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,14 +169,14 @@
>  	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;
> +			ret = CMD_ERROR;
>  			goto end;
>  		}
>  	} else {
> @@ -188,5 +186,6 @@
>  	ret = disable_channels(session_name);
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c
> index 7f7b50c..4ddcf54 100644
> --- a/src/bin/lttng/commands/disable_events.c
> +++ b/src/bin/lttng/commands/disable_events.c
> @@ -198,7 +198,7 @@
>   */
>  int cmd_disable_events(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  	char *session_name = NULL;
>  
> @@ -208,15 +208,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);
> @@ -229,14 +227,14 @@
>  	if (opt_event_list == NULL && opt_disable_all == 0) {
>  		ERR("Missing event 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;
> +			ret = CMD_ERROR;
>  			goto end;
>  		}
>  	} else {
> @@ -246,5 +244,6 @@
>  	ret = disable_events(session_name);
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c
> index 03de524..19b6b26 100644
> --- a/src/bin/lttng/commands/enable_channels.c
> +++ b/src/bin/lttng/commands/enable_channels.c
> @@ -219,7 +219,7 @@
>   */
>  int cmd_enable_channels(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  	char *session_name = NULL;
>  
> @@ -231,8 +231,7 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_DISCARD:
>  			chan.attr.overwrite = 0;
> @@ -243,18 +242,22 @@
>  			DBG("Channel set to overwrite");
>  			break;
>  		case OPT_SUBBUF_SIZE:
> +			/* TODO Replace atol with strtol and check for errors */
>  			chan.attr.subbuf_size = atol(poptGetOptArg(pc));
>  			DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size);
>  			break;
>  		case OPT_NUM_SUBBUF:
> +			/* TODO Replace atoi with strtol and check for errors */
>  			chan.attr.num_subbuf = atoi(poptGetOptArg(pc));
>  			DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf);
>  			break;
>  		case OPT_SWITCH_TIMER:
> +			/* TODO Replace atoi with strtol and check for errors */
>  			chan.attr.switch_timer_interval = atoi(poptGetOptArg(pc));
>  			DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval);
>  			break;
>  		case OPT_READ_TIMER:
> +			/* TODO Replace atoi with strtol and check for errors */
>  			chan.attr.read_timer_interval = atoi(poptGetOptArg(pc));
>  			DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval);
>  			break;
> @@ -263,7 +266,6 @@
>  			break;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -276,14 +278,14 @@
>  	if (opt_channels == NULL) {
>  		ERR("Missing channel name.\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;
> +			ret = CMD_ERROR;
>  			goto end;
>  		}
>  	} else {
> @@ -293,5 +295,6 @@
>  	ret = enable_channel(session_name);
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c
> index 0fa3e91..f5012d4 100644
> --- a/src/bin/lttng/commands/enable_events.c
> +++ b/src/bin/lttng/commands/enable_events.c
> @@ -413,7 +413,7 @@
>   */
>  int cmd_enable_events(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  	char *session_name = NULL;
>  
> @@ -426,8 +426,7 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_TRACEPOINT:
>  			opt_event_type = LTTNG_EVENT_TRACEPOINT;
> @@ -457,7 +456,6 @@
>  			break;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -470,14 +468,14 @@
>  	if (opt_event_list == NULL && opt_enable_all == 0) {
>  		ERR("Missing event 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;
> +			ret = CMD_ERROR;
>  			goto end;
>  		}
>  	} else {
> @@ -491,5 +489,6 @@
>  		free(session_name);
>  	}
>  
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c
> index 4b8a07c..d84fd2b 100644
> --- a/src/bin/lttng/commands/list.c
> +++ b/src/bin/lttng/commands/list.c
> @@ -541,6 +541,7 @@
>  
>  	if (argc < 1) {
>  		usage(stderr);
> +		ret = CMD_ERROR;
>  		goto end;
>  	}
>  
> @@ -550,14 +551,13 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> +			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);
> @@ -579,6 +579,7 @@
>  
>  	handle = lttng_create_handle(session_name, &domain);
>  	if (handle == NULL) {
> +		ret = CMD_FATAL;
>  		goto end;
>  	}
>  
> @@ -586,18 +587,21 @@
>  		if (!opt_kernel && !opt_userspace) {
>  			ret = list_sessions(NULL);
>  			if (ret < 0) {
> +				ret = CMD_ERROR;
>  				goto end;
>  			}
>  		}
>  		if (opt_kernel) {
>  			ret = list_kernel_events();
>  			if (ret < 0) {
> +				ret = CMD_ERROR;
>  				goto end;
>  			}
>  		}
>  		if (opt_userspace) {
>  			ret = list_ust_events();
>  			if (ret < 0) {
> +				ret = CMD_ERROR;
>  				goto end;
>  			}
>  		}
> @@ -605,12 +609,16 @@
>  		/* List session attributes */
>  		ret = list_sessions(session_name);
>  		if (ret < 0) {
> +			ret = CMD_ERROR;
>  			goto end;
>  		}
>  
>  		/* Domain listing */
>  		if (opt_domain) {
>  			ret = list_domains(session_name);
> +			if (ret < 0) {
> +				ret = CMD_ERROR;
> +			}
>  			goto end;
>  		}
>  
> @@ -618,13 +626,14 @@
>  			/* Channel listing */
>  			ret = list_channels(opt_channel);
>  			if (ret < 0) {
> +				ret = CMD_ERROR;
>  				goto end;
>  			}
>  		} else {
>  			/* We want all domain(s) */
>  			nb_domain = lttng_list_domains(session_name, &domains);
>  			if (nb_domain < 0) {
> -				ret = nb_domain;
> +				ret = CMD_ERROR;
>  				goto end;
>  			}
>  
> @@ -646,11 +655,13 @@
>  
>  				handle = lttng_create_handle(session_name, &domains[i]);
>  				if (handle == NULL) {
> +					ret = CMD_FATAL;
>  					goto end;
>  				}
>  
>  				ret = list_channels(opt_channel);
>  				if (ret < 0) {
> +					ret = CMD_ERROR;
>  					goto end;
>  				}
>  			}
> @@ -663,5 +674,6 @@
>  	}
>  	lttng_destroy_handle(handle);
>  
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c
> index f91935e..fdeeaaf 100644
> --- a/src/bin/lttng/commands/set_session.c
> +++ b/src/bin/lttng/commands/set_session.c
> @@ -89,12 +89,10 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -107,11 +105,13 @@
>  	if (opt_session_name == NULL) {
>  		ERR("Missing session name");
>  		usage(stderr);
> +		ret = CMD_ERROR;
>  		goto end;
>  	}
>  
>  	ret = set_session();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c
> index b2a4980..1db0a31 100644
> --- a/src/bin/lttng/commands/start.c
> +++ b/src/bin/lttng/commands/start.c
> @@ -100,7 +100,7 @@
>   */
>  int cmd_start(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  
>  	pc = poptGetContext(NULL, argc, argv, long_options, 0);
> @@ -109,12 +109,10 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -128,5 +126,6 @@
>  	ret = start_tracing();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.c
> index 82c9b4e..689fe1b 100644
> --- a/src/bin/lttng/commands/stop.c
> +++ b/src/bin/lttng/commands/stop.c
> @@ -97,7 +97,7 @@
>   */
>  int cmd_stop(int argc, const char **argv)
>  {
> -	int opt, ret;
> +	int opt, ret = CMD_SUCCESS;
>  	static poptContext pc;
>  
>  	pc = poptGetContext(NULL, argc, argv, long_options, 0);
> @@ -106,12 +106,10 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -125,5 +123,6 @@
>  	ret = stop_tracing();
>  
>  end:
> +	poptFreeContext(pc);
>  	return ret;
>  }
> diff --git a/src/bin/lttng/commands/version.c b/src/bin/lttng/commands/version.c
> index f288ba4..030ccaa 100644
> --- a/src/bin/lttng/commands/version.c
> +++ b/src/bin/lttng/commands/version.c
> @@ -66,12 +66,10 @@
>  	while ((opt = poptGetNextOpt(pc)) != -1) {
>  		switch (opt) {
>  		case OPT_HELP:
> -			usage(stderr);
> -			ret = CMD_SUCCESS;
> +			usage(stdout);
>  			goto end;
>  		case OPT_LIST_OPTIONS:
>  			list_cmd_options(stdout, long_options);
> -			ret = CMD_SUCCESS;
>  			goto end;
>  		default:
>  			usage(stderr);
> @@ -85,5 +83,6 @@
>  	MSG("\nlttng is free software and under the GPL license.");
>  
>  end:
> +	poptFreeContext(pc);
>  	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
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJPKZ5YAAoJEELoaioR9I02Cq0H/Ao4FVydWOZlFbcWhYS9g+Vp
sWKXXnu1alGNLrhRzFR/HdmHyASp5JpJNFlzvXkCXX/+HwAYSKvUGKhhGCf6DhVx
LfqR2ocEgcVtqIol3icp/DykamIeipM1EUeo0YxAHE/BDbooDceho71KziS1appn
r9GHYKNgh5x4tLKNmyjtDIOggn9xfYgnyoWRJkAArmtInwvHdicnzozr5wcdtsOQ
Yl5KKdf6XBwVwTDaX6tCF3LteDeJAaAx411xPD0LXzFMbV4l5cLO0Me8+QE651a1
YP2k02vE3PiZ2dPpOVYqXhXF7ME+C4Vkm2pMi8Bb5YVO1mQJ1nGAZciPCnIAaCo=
=CxHv
-----END PGP SIGNATURE-----



More information about the lttng-dev mailing list