[lttng-dev] [PATCH 1/4] Improve delete of configuration

David Goulet david.goulet at polymtl.ca
Thu May 31 12:55:50 EDT 2012


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

Merge thanks!

Neat feature :)

Cheers!
David

On 30/05/12 07:50 PM, Francis Giraldeau wrote:
> Adding functions to encapsulate the configuration delete. Test if path to 
> configuration exists before attempting to remove it.
> 
> * fixed braces and goto name
> 
> Signed-off-by: Francis Giraldeau <francis.giraldeau at gmail.com> --- 
> src/bin/lttng/conf.c |   39 ++++++++++++++++++++++++++++++++++++++- 
> src/bin/lttng/conf.h |    2 ++ 2 files changed, 40 insertions(+), 1
> deletion(-)
> 
> diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c index
> 6f290b7..50af228 100644 --- a/src/bin/lttng/conf.c +++
> b/src/bin/lttng/conf.c @@ -154,15 +154,52 @@ void config_destroy(char
> *path) return; }
> 
> +	if (!config_exists(config_path)) { +		goto end; +	} + +	DBG("Removing
> %s\n", config_path); ret = remove(config_path); if (ret < 0) { 
> perror("remove config file"); } - +end: free(config_path); }
> 
> /* + *  config_destroy_default + * + *  Destroys the default config + */ + 
> +void config_destroy_default(void) +{ +	char *path =
> config_get_default_path(); +	if (path == NULL) { +		return; +	} +
> config_destroy(path); +} + +/* + *  config_exists + * + *  Returns 1 if
> config exists, 0 otherwise + */ +int config_exists(const char *path) +{ +
> int ret; +	struct stat info; + +	ret = stat(path, &info); +	if (ret < 0) { 
> +		return 0; +	} +	return S_ISREG(info.st_mode) || S_ISDIR(info.st_mode); 
> +} + +/* *  config_read_session_name * *  Returns the session name from the
> config file. diff --git a/src/bin/lttng/conf.h b/src/bin/lttng/conf.h index
> 1c471da..2cb04b0 100644 --- a/src/bin/lttng/conf.h +++
> b/src/bin/lttng/conf.h @@ -21,6 +21,8 @@ #define CONFIG_FILENAME
> ".lttngrc"
> 
> void config_destroy(char *path); +void config_destroy_default(void); +int
> config_exists(const char *path); int config_init(char *path); int
> config_add_session_name(char *path, char *name); char
> *config_get_default_path(void);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQEcBAEBAgAGBQJPx6KTAAoJEELoaioR9I02WnwH/3vZiMcGoiBNgEZ9D0zdVPsD
ro2G5Sv9e+fHV8r0PNp5IojB0o99SERqi2rvyznKEhh8KrPu56KjcgS05MqtDjnP
9Q7jTtKSE8OXpQSUeCxHcLdgMoaDIX1Lh7FMeiFpxaPJTY3RkBA7vQJjvMTS2PlB
QV94+qc6ZfS89keBt+IxWix5Wmgu9TX7YoMPDmb2cv+I2Sc01eyrdxSz68GhMSp7
bgEYNn54HhvF7SM0rTMrLrQo8NlEoi32U+ZkYyZjcdb0JFnIajmw/AaSb6Vv2Vnw
xvi7nRamjGjDOBmjcK3iZn4Xi0op7DK8h/W09FvXD95b687wfmwrv3Q7q9lzJLE=
=tV7S
-----END PGP SIGNATURE-----



More information about the lttng-dev mailing list