Improve delete of configuration
authorFrancis Giraldeau <francis.giraldeau@gmail.com>
Wed, 30 May 2012 23:50:04 +0000 (01:50 +0200)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 31 May 2012 16:47:47 +0000 (12:47 -0400)
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@gmail.com>
src/bin/lttng/conf.c
src/bin/lttng/conf.h

index 6f290b7e5f1df78b34f4d88cf87d500a1c72b1fa..50af2289d11f0d83fd636cb136e504b3887c9be3 100644 (file)
@@ -154,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
  *
index 1c471dae3c0990eff7cc2ececbbb81a474cb830c..2cb04b0c7f2c23b0cb6305c869137e9e60d1b404 100644 (file)
@@ -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);
This page took 0.026262 seconds and 4 git commands to generate.