Rename and add missing header file
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 27 Jun 2011 19:21:45 +0000 (15:21 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 27 Jun 2011 19:21:45 +0000 (15:21 -0400)
Rename config.c/.h to conf.* to avoid confusion with the autogenerated
config.h from autoconf.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
12 files changed:
lttng/Makefile.am
lttng/commands/add_channel.c
lttng/commands/create.c
lttng/commands/destroy.c
lttng/commands/enable_events.c
lttng/commands/start.c
lttng/commands/stop.c
lttng/conf.c [new file with mode: 0644]
lttng/conf.h [new file with mode: 0644]
lttng/config.c [deleted file]
lttng/lttng.c
lttng/utils.c

index de2f22cdc435f99fe4e5e28cbee4e09051efba96..fcea4668a15ba9b812a80b8450aca92d0d55d314 100644 (file)
@@ -2,7 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
 
 bin_PROGRAMS = lttng
 
-lttng_SOURCES = config.c commands/start.c commands/add_channel.c \
+lttng_SOURCES = conf.c commands/start.c commands/add_channel.c \
                                commands/list.c commands/create.c commands/destroy.c \
                                commands/stop.c commands/enable_events.c \
                                utils.c lttng.c
index 6b41e875affd59b68fa44af1b8f2d5481fd03fe6..ea7db820e0a1006ec754e6fd828cad7c9fa9e417 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_channel_name;
index 522ebc9c3aa3a6a3eff33015aa06d33dd3a95da6..941f72355426e792987442134061d7569e52cbb3 100644 (file)
@@ -27,7 +27,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 
 static char *opt_output_path;
 static char *opt_session_name;
index 9519403ad1c68e26a85a913e7714dd536a2f20fc..f08a99fd76e73a9ca0fe9daad29153da223f9295 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_session_name;
index f9b51b14d74704fc1fc5127d3748b1adf0faa820..cde0cc48c5ac2a3cf08fcf010ddf6734135a573b 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_event_list;
index 3a4febe4f86bf7099b9df6d98ae2f8cf1ba8729d..1a3e568ed6df10115f90313c6ce9b9ee894539ed 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_session_name;
index 0245296a444790a39c4a0e6a405b190397512739..56edc2d6de64010d6c701645d375d075bed645be 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_session_name;
diff --git a/lttng/conf.c b/lttng/conf.c
new file mode 100644 (file)
index 0000000..9e3a626
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "conf.h"
+#include "lttngerr.h"
+
+/*
+ *  get_config_file_path
+ *
+ *  Return the path with '/CONFIG_FILENAME' added to it.
+ */
+static char *get_config_file_path(char *path)
+{
+       int ret;
+       char *file_path;
+
+       ret = asprintf(&file_path, "%s/%s", path, CONFIG_FILENAME);
+       if (ret < 0) {
+               ERR("Fail allocating config file path");
+       }
+
+       return file_path;
+}
+
+/*
+ *  open_config
+ *
+ *  Return an open FILE pointer to the config file.
+ */
+static FILE *open_config(char *path, const char *mode)
+{
+       FILE *fp = NULL;
+       char *file_path;
+
+       file_path = get_config_file_path(path);
+       if (file_path == NULL) {
+               goto error;
+       }
+
+       fp = fopen(file_path, mode);
+       if (fp == NULL) {
+               perror("config file");
+               goto error;
+       }
+
+error:
+       if (file_path) {
+               free(file_path);
+       }
+       return fp;
+}
+
+/*
+ *  create_config_file
+ *
+ *  Create the empty config file a the path.
+ */
+static int create_config_file(char *path)
+{
+       int ret;
+       FILE *fp;
+
+       fp = open_config(path, "w+");
+       if (fp == NULL) {
+               ERR("Unable to create config file");
+               ret = -1;
+               goto error;
+       }
+
+       ret = fclose(fp);
+
+error:
+       return ret;
+}
+
+/*
+ *  create_config_dir
+ *
+ *  Create the empty config dir.
+ */
+static int create_config_dir(char *path)
+{
+       int ret;
+
+       /* Create session directory .lttng */
+       ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
+       if (ret < 0) {
+               if (errno == EEXIST) {
+                       ERR("Session already exist at %s", path);
+               } else  {
+                       perror("mkdir config");
+                       ERR("Couldn't init config directory at %s", path);
+               }
+               ret = -errno;
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
+/*
+ *  write_config
+ *
+ *  Append data to the config file in file_path
+ */
+static void write_config(char *file_path, size_t size, char *data)
+{
+       FILE *fp;
+
+       fp = open_config(file_path, "a");
+       if (fp == NULL) {
+               goto error;
+       }
+
+       /* Write session name into config file */
+       fwrite(data, size, 1, fp);
+       fclose(fp);
+
+error:
+       return;
+}
+
+/*
+ *  config_get_default_path
+ *
+ *  Return the default path to config directory which is the current working
+ *  directory. User must free() the returned allocated string.
+ */
+char *config_get_default_path(void)
+{
+       char *alloc_path;
+
+       alloc_path = getcwd(NULL, 0);
+       if (alloc_path == NULL) {
+               perror("getcwd");
+       }
+
+       return alloc_path;
+}
+
+/*
+ *  config_destroy
+ *
+ *  Destroy directory config and file config.
+ */
+void config_destroy(char *path)
+{
+       int ret;
+       char *config_path;
+
+       config_path = get_config_file_path(path);
+
+       ret = remove(config_path);
+       if (ret < 0) {
+               perror("remove config file");
+       }
+
+       ret = rmdir(path);
+       if (ret < 0) {
+               perror("rmdir config dir");
+       }
+
+       free(config_path);
+}
+
+/*
+ *  config_read_session_name
+ *
+ *  Return sesson name from the config file.
+ */
+char *config_read_session_name(char *path)
+{
+       int ret;
+       FILE *fp;
+       char var[NAME_MAX], *session_name;
+
+       fp = open_config(path, "r");
+       if (fp == NULL) {
+               ERR("Can't find valid lttng config in %s", path);
+               goto error;
+       }
+
+       session_name = malloc(NAME_MAX);
+       while (!feof(fp)) {
+               if ((ret = fscanf(fp, "%[^'=']=%s\n", var, session_name)) != 2) {
+                       if (ret == -1) {
+                               ERR("Missing session=NAME in config file.");
+                               goto error;
+                       }
+                       continue;
+               }
+
+               if (strcmp(var, "session") == 0) {
+                       goto found;
+               }
+       }
+
+       fclose(fp);
+
+error:
+       return NULL;
+
+found:
+       fclose(fp);
+       return session_name;
+
+}
+
+/*
+ *  config_add_session_name
+ *
+ *  Write session name option to the config file.
+ */
+int config_add_session_name(char *path, char *name)
+{
+       int ret;
+       char session_name[NAME_MAX];
+
+       ret = snprintf(session_name, NAME_MAX, "session=%s\n", name);
+       if (ret < 0) {
+               goto error;
+       }
+
+       write_config(path, ret, session_name);
+       ret = 0;
+
+error:
+       return ret;
+}
+
+/*
+ *  config_generate_dir_path
+ *
+ *  Return allocated path string to path/CONFIG_DIRNAME.
+ */
+char *config_generate_dir_path(char *path)
+{
+       int ret;
+       char *new_path;
+
+       ret = asprintf(&new_path, "%s/%s", path, CONFIG_DIRNAME);
+       if (ret < 0) {
+               perror("config path problem");
+               goto error;
+       }
+
+error:
+       return new_path;
+}
+
+/*
+ *  config_init
+ *
+ *  Init configuration directory and file.
+ */
+int config_init(char *path)
+{
+       int ret;
+
+       /* Create config directory (.lttng) */
+       ret = create_config_dir(path);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Create default config file */
+       ret = create_config_file(path);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG("Init config session in %s", path);
+
+error:
+       return ret;
+}
diff --git a/lttng/conf.h b/lttng/conf.h
new file mode 100644 (file)
index 0000000..b221d5a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef _LTTNG_CONFIG_H
+#define _LTTNG_CONFIG_H
+
+#define CONFIG_FILENAME "config"
+#define CONFIG_DIRNAME  ".lttng"
+
+void config_destroy(char *path);
+int config_init(char *path);
+int config_add_session_name(char *path, char *name);
+
+/* Must free() the return pointer */
+char *config_generate_dir_path(char *path);
+char *config_read_session_name(char *path);
+char *config_get_default_path(void);
+
+#endif /* _LTTNG_CONFIG_H */
diff --git a/lttng/config.c b/lttng/config.c
deleted file mode 100644 (file)
index 224bd1a..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#define _GNU_SOURCE
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "lttngerr.h"
-
-/*
- *  get_config_file_path
- *
- *  Return the path with '/CONFIG_FILENAME' added to it.
- */
-static char *get_config_file_path(char *path)
-{
-       int ret;
-       char *file_path;
-
-       ret = asprintf(&file_path, "%s/%s", path, CONFIG_FILENAME);
-       if (ret < 0) {
-               ERR("Fail allocating config file path");
-       }
-
-       return file_path;
-}
-
-/*
- *  open_config
- *
- *  Return an open FILE pointer to the config file.
- */
-static FILE *open_config(char *path, const char *mode)
-{
-       FILE *fp = NULL;
-       char *file_path;
-
-       file_path = get_config_file_path(path);
-       if (file_path == NULL) {
-               goto error;
-       }
-
-       fp = fopen(file_path, mode);
-       if (fp == NULL) {
-               perror("config file");
-               goto error;
-       }
-
-error:
-       if (file_path) {
-               free(file_path);
-       }
-       return fp;
-}
-
-/*
- *  create_config_file
- *
- *  Create the empty config file a the path.
- */
-static int create_config_file(char *path)
-{
-       int ret;
-       FILE *fp;
-
-       fp = open_config(path, "w+");
-       if (fp == NULL) {
-               ERR("Unable to create config file");
-               ret = -1;
-               goto error;
-       }
-
-       ret = fclose(fp);
-
-error:
-       return ret;
-}
-
-/*
- *  create_config_dir
- *
- *  Create the empty config dir.
- */
-static int create_config_dir(char *path)
-{
-       int ret;
-
-       /* Create session directory .lttng */
-       ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
-       if (ret < 0) {
-               if (errno == EEXIST) {
-                       ERR("Session already exist at %s", path);
-               } else  {
-                       perror("mkdir config");
-                       ERR("Couldn't init config directory at %s", path);
-               }
-               ret = -errno;
-               goto error;
-       }
-
-error:
-       return ret;
-}
-
-/*
- *  write_config
- *
- *  Append data to the config file in file_path
- */
-static void write_config(char *file_path, size_t size, char *data)
-{
-       FILE *fp;
-
-       fp = open_config(file_path, "a");
-       if (fp == NULL) {
-               goto error;
-       }
-
-       /* Write session name into config file */
-       fwrite(data, size, 1, fp);
-       fclose(fp);
-
-error:
-       return;
-}
-
-/*
- *  config_get_default_path
- *
- *  Return the default path to config directory which is the current working
- *  directory. User must free() the returned allocated string.
- */
-char *config_get_default_path(void)
-{
-       char *alloc_path;
-
-       alloc_path = getcwd(NULL, 0);
-       if (alloc_path == NULL) {
-               perror("getcwd");
-       }
-
-       return alloc_path;
-}
-
-/*
- *  config_destroy
- *
- *  Destroy directory config and file config.
- */
-void config_destroy(char *path)
-{
-       int ret;
-       char *config_path;
-
-       config_path = get_config_file_path(path);
-
-       ret = remove(config_path);
-       if (ret < 0) {
-               perror("remove config file");
-       }
-
-       ret = rmdir(path);
-       if (ret < 0) {
-               perror("rmdir config dir");
-       }
-
-       free(config_path);
-}
-
-/*
- *  config_read_session_name
- *
- *  Return sesson name from the config file.
- */
-char *config_read_session_name(char *path)
-{
-       int ret;
-       FILE *fp;
-       char var[NAME_MAX], *session_name;
-
-       fp = open_config(path, "r");
-       if (fp == NULL) {
-               ERR("Can't find valid lttng config in %s", path);
-               goto error;
-       }
-
-       session_name = malloc(NAME_MAX);
-       while (!feof(fp)) {
-               if ((ret = fscanf(fp, "%[^'=']=%s\n", var, session_name)) != 2) {
-                       if (ret == -1) {
-                               ERR("Missing session=NAME in config file.");
-                               goto error;
-                       }
-                       continue;
-               }
-
-               if (strcmp(var, "session") == 0) {
-                       goto found;
-               }
-       }
-
-       fclose(fp);
-
-error:
-       return NULL;
-
-found:
-       fclose(fp);
-       return session_name;
-
-}
-
-/*
- *  config_add_session_name
- *
- *  Write session name option to the config file.
- */
-int config_add_session_name(char *path, char *name)
-{
-       int ret;
-       char session_name[NAME_MAX];
-
-       ret = snprintf(session_name, NAME_MAX, "session=%s\n", name);
-       if (ret < 0) {
-               goto error;
-       }
-
-       write_config(path, ret, session_name);
-       ret = 0;
-
-error:
-       return ret;
-}
-
-/*
- *  config_generate_dir_path
- *
- *  Return allocated path string to path/CONFIG_DIRNAME.
- */
-char *config_generate_dir_path(char *path)
-{
-       int ret;
-       char *new_path;
-
-       ret = asprintf(&new_path, "%s/%s", path, CONFIG_DIRNAME);
-       if (ret < 0) {
-               perror("config path problem");
-               goto error;
-       }
-
-error:
-       return new_path;
-}
-
-/*
- *  config_init
- *
- *  Init configuration directory and file.
- */
-int config_init(char *path)
-{
-       int ret;
-
-       /* Create config directory (.lttng) */
-       ret = create_config_dir(path);
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Create default config file */
-       ret = create_config_file(path);
-       if (ret < 0) {
-               goto error;
-       }
-
-       DBG("Init config session in %s", path);
-
-error:
-       return ret;
-}
index 09e336803460b4c20c1c97f89056b2fa14174b47..5f0699119cc89614644a1cf1bc5ef176d4eeb3f7 100644 (file)
@@ -27,7 +27,7 @@
 #include <lttng/lttng.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "lttngerr.h"
 
 /* Variables */
index b05fd2283f43798c781da4635121356826d2a57a..f9edb173bb88271c39cdfea9a676003b743de1a2 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <lttng/lttng.h>
 
-#include "config.h"
+#include "conf.h"
 
 /*
  *  get_config_file_path
This page took 0.036764 seconds and 4 git commands to generate.