X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fconf.c;h=50af2289d11f0d83fd636cb136e504b3887c9be3;hb=d6a07e7da56c327a0c22c9113a0a9fa7bf8197c6;hp=00991b08195319f58f3d5489ff10ed679204f8aa;hpb=27089920577ab0b7e237c4ec6ef2d8bdcea4a5ed;p=lttng-tools.git diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c index 00991b081..50af2289d 100644 --- a/src/bin/lttng/conf.c +++ b/src/bin/lttng/conf.c @@ -2,9 +2,8 @@ * Copyright (c) 2011 David Goulet * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * as published by the Free Software Foundation; only version 2 - * of the License. + * it under the terms of the GNU General Public License, version 2 only, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -155,14 +154,51 @@ 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 *