Cleanup: mark utils_get_home_dir as returning a const string
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 24 Aug 2019 22:14:11 +0000 (15:14 -0700)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 24 Aug 2019 22:14:15 +0000 (15:14 -0700)
utils_get_home_dir() returns a string obtained from getenv() that
should not be modified nor free'd. However, utils_get_user_home_dir()
returns the path as a copy.

The return parameter of utils_get_home_dir() is marked as const
to underline this difference and prevent mix-ups in the use of
those functions.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/health-relayd.c
src/bin/lttng-relayd/session.c
src/bin/lttng-relayd/utils.c
src/bin/lttng-sessiond/notification-thread.c
src/bin/lttng/conf.c
src/bin/lttng/utils.c
src/common/config/session-config.c
src/common/utils.c
src/common/utils.h

index 4a2dc65a6430bed4d1404a8b69ce4a76df937148..482be8eea92240beb047801eb291b99af3796067 100644 (file)
@@ -155,7 +155,8 @@ static
 int setup_health_path(void)
 {
        int is_root, ret = 0;
 int setup_health_path(void)
 {
        int is_root, ret = 0;
-       char *home_path = NULL, *rundir = NULL, *relayd_path = NULL;
+       const char *home_path = NULL;
+       char *rundir = NULL, *relayd_path = NULL;
 
        ret = parse_health_env();
        if (ret) {
 
        ret = parse_health_env();
        if (ret) {
index 1359e9f4b455833e58b74ace6be4e45f616dc48c..5eedffc94e657aa924fb90ab72bf24b6056c6080 100644 (file)
@@ -39,7 +39,7 @@ static int session_set_anonymous_chunk(struct relay_session *session)
        struct lttng_trace_chunk *chunk = NULL;
        enum lttng_trace_chunk_status status;
        struct lttng_directory_handle output_directory;
        struct lttng_trace_chunk *chunk = NULL;
        enum lttng_trace_chunk_status status;
        struct lttng_directory_handle output_directory;
-       char *base_path = opt_output_path;
+       const char *base_path = opt_output_path;
 
        if (base_path == NULL) {
                /* No output path defined */
 
        if (base_path == NULL) {
                /* No output path defined */
index 7ae0879e598674007cdee164cee4d2ff2c263c70..db124bc354515c22f5eef55e89a1527e6b55c9ce 100644 (file)
@@ -33,7 +33,7 @@ static char *create_output_path_auto(const char *path_name)
 {
        int ret;
        char *traces_path = NULL;
 {
        int ret;
        char *traces_path = NULL;
-       char *default_path;
+       const char *default_path;
 
        default_path = utils_get_home_dir();
        if (default_path == NULL) {
 
        default_path = utils_get_home_dir();
        if (default_path == NULL) {
index 8c2892bda85e9905f642f26d61c5c6eaf26dfeb7..3686d72f7015e9b728eb2d6ab246a1e5a4d14f9a 100644 (file)
@@ -172,7 +172,7 @@ char *get_notification_channel_sock_path(void)
                        goto error;
                }
        } else {
                        goto error;
                }
        } else {
-               char *home_path = utils_get_home_dir();
+               const char *home_path = utils_get_home_dir();
 
                if (!home_path) {
                        ERR("Can't get HOME directory for socket creation");
 
                if (!home_path) {
                        ERR("Can't get HOME directory for socket creation");
index 52979af0d1fb0df1f8f99409b954e15520091cf2..6de527553124df51be2d8f811928750701434c1b 100644 (file)
@@ -77,7 +77,7 @@ error:
  * On success, returns 0;
  * on error, returns -1.
  */
  * On success, returns 0;
  * on error, returns -1.
  */
-static int create_config_file(char *path)
+static int create_config_file(const char *path)
 {
        int ret;
        FILE *fp;
 {
        int ret;
        FILE *fp;
@@ -155,7 +155,7 @@ end:
  */
 void config_destroy_default(void)
 {
  */
 void config_destroy_default(void)
 {
-       char *path = utils_get_home_dir();
+       const char *path = utils_get_home_dir();
        if (path == NULL) {
                return;
        }
        if (path == NULL) {
                return;
        }
@@ -302,7 +302,7 @@ error:
 int config_init(const char *session_name)
 {
        int ret;
 int config_init(const char *session_name)
 {
        int ret;
-       char *path;
+       const char *path;
 
        path = utils_get_home_dir();
        if (path == NULL) {
 
        path = utils_get_home_dir();
        if (path == NULL) {
index 1e3b91344d24ae58470b2cb966758402bd41c322..fa2d3c9da626542fc9a0d1bb78bdf017197eedd1 100644 (file)
@@ -51,7 +51,8 @@ static const char *str_function = "Function";
 static
 char *_get_session_name(int quiet)
 {
 static
 char *_get_session_name(int quiet)
 {
-       char *path, *session_name = NULL;
+       const char *path;
+       char *session_name = NULL;
 
        /* Get path to config file */
        path = utils_get_home_dir();
 
        /* Get path to config file */
        path = utils_get_home_dir();
index 8e5410c3f3b7971016e5f6e130f319703c8e997a..40019514bdb27021d63fb1ad563c2e3abe43c7e8 100644 (file)
@@ -250,7 +250,7 @@ int config_get_section_entries(const char *override_path, const char *section,
                config_entry_handler_cb handler, void *user_data)
 {
        int ret = 0;
                config_entry_handler_cb handler, void *user_data)
 {
        int ret = 0;
-       char *path;
+       const char *path;
        FILE *config_file = NULL;
        struct handler_filter_args filter = { section, handler, user_data };
 
        FILE *config_file = NULL;
        struct handler_filter_args filter = { section, handler, user_data };
 
@@ -3532,7 +3532,7 @@ int config_load_session(const char *path, const char *session_name,
        }
 
        if (!path) {
        }
 
        if (!path) {
-               char *home_path;
+               const char *home_path;
                const char *sys_path;
 
                /* Try home path */
                const char *sys_path;
 
                /* Try home path */
index 664ba3e8e82abbdcf3a0c15614ba9b5858fbea93..fda43152d30905fc278515277f79a11eb0104282 100644 (file)
@@ -1197,7 +1197,7 @@ int utils_get_count_order_u64(uint64_t x)
  * Otherwise returns the value of HOME.
  */
 LTTNG_HIDDEN
  * Otherwise returns the value of HOME.
  */
 LTTNG_HIDDEN
-char *utils_get_home_dir(void)
+const char *utils_get_home_dir(void)
 {
        char *val = NULL;
        struct passwd *pwd;
 {
        char *val = NULL;
        struct passwd *pwd;
index 57c7307bec3aaf37f3dc9af98946298e7339b02c..00b65939d163dedbf143d8eedbcc28dc08a8ed10 100644 (file)
@@ -55,7 +55,7 @@ int utils_parse_size_suffix(char const * const str, uint64_t * const size);
 int utils_parse_time_suffix(char const * const str, uint64_t * const time_us);
 int utils_get_count_order_u32(uint32_t x);
 int utils_get_count_order_u64(uint64_t x);
 int utils_parse_time_suffix(char const * const str, uint64_t * const time_us);
 int utils_get_count_order_u32(uint32_t x);
 int utils_get_count_order_u64(uint64_t x);
-char *utils_get_home_dir(void);
+const char *utils_get_home_dir(void);
 char *utils_get_user_home_dir(uid_t uid);
 size_t utils_get_current_time_str(const char *format, char *dst, size_t len);
 int utils_get_group_id(const char *name, bool warn, gid_t *gid);
 char *utils_get_user_home_dir(uid_t uid);
 size_t utils_get_current_time_str(const char *format, char *dst, size_t len);
 int utils_get_group_id(const char *name, bool warn, gid_t *gid);
This page took 0.029026 seconds and 4 git commands to generate.