X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng%2Fconf.c;h=526988468aa93ac6a576f92f3a1c27416e1c5822;hp=9e3a626ba34d5112fa83d15e6ca24585a37b8dd9;hb=ed52805d21fb7a55ad066d4591f6a5f02c2108ba;hpb=beb8c75afd91bc32f2e7a9c124c9a21ecffd1486 diff --git a/lttng/conf.c b/lttng/conf.c index 9e3a626ba..526988468 100644 --- a/lttng/conf.c +++ b/lttng/conf.c @@ -3,8 +3,8 @@ * * 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 @@ -29,11 +29,11 @@ #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; @@ -56,7 +56,7 @@ static FILE *open_config(char *path, const char *mode) 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; } @@ -97,32 +97,6 @@ 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 * @@ -148,19 +122,11 @@ error: /* * config_get_default_path * - * Return the default path to config directory which is the current working - * directory. User must free() the returned allocated string. + * Return the HOME directory path. Caller MUST NOT free(3) the return pointer. */ char *config_get_default_path(void) { - char *alloc_path; - - alloc_path = getcwd(NULL, 0); - if (alloc_path == NULL) { - perror("getcwd"); - } - - return alloc_path; + return getenv("HOME"); } /* @@ -173,18 +139,16 @@ void config_destroy(char *path) 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) { perror("remove config file"); } - ret = rmdir(path); - if (ret < 0) { - perror("rmdir config dir"); - } - free(config_path); } @@ -201,7 +165,7 @@ char *config_read_session_name(char *path) 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; } @@ -253,38 +217,19 @@ 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; } @@ -294,6 +239,11 @@ int config_init(char *path) goto error; } + ret = config_add_session_name(path, session_name); + if (ret < 0) { + goto error; + } + DBG("Init config session in %s", path); error: