*
* 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.
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "lttngerr.h"
/*
- * get_config_file_path
+ * config_get_file_path
*
* Return the path with '/CONFIG_FILENAME' added to it.
*/
-static char *get_config_file_path(char *path)
+char *config_get_file_path(char *path)
{
int ret;
char *file_path;
FILE *fp = NULL;
char *file_path;
- file_path = get_config_file_path(path);
+ file_path = config_get_file_path(path);
if (file_path == NULL) {
goto 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
*
/*
* config_get_default_path
*
- * Return the HOME directory path. The output is dup so the user MUST
- * free(3) the returned string.
+ * Return the HOME directory path. Caller MUST NOT free(3) the return pointer.
*/
char *config_get_default_path(void)
{
- return strdup(getenv("HOME"));
+ return getenv("HOME");
}
/*
int ret;
char *config_path;
- config_path = get_config_file_path(path);
+ config_path = config_get_file_path(path);
+ if (config_path == NULL) {
+ return;
+ }
ret = remove(config_path);
if (ret < 0) {
fp = open_config(path, "r");
if (fp == NULL) {
- ERR("Can't find valid lttng config in %s", path);
+ ERR("Can't find valid lttng config %s/.lttngrc", path);
goto 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 config_init(char *session_name)
{
int ret;
+ char *path;
- /* Create config directory (.lttng) */
- ret = create_config_dir(path);
- if (ret < 0) {
+ path = config_get_default_path();
+ if (path == NULL) {
+ ret = -1;
goto error;
}
goto error;
}
+ ret = config_add_session_name(path, session_name);
+ if (ret < 0) {
+ goto error;
+ }
+
DBG("Init config session in %s", path);
error: