Using LTTNG_HOME environment variable if exists, with fallback to HOME
authorAmit Margalit <amitm@il.ibm.com>
Thu, 13 Jun 2013 09:35:13 +0000 (12:35 +0300)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 19 Jun 2013 18:47:22 +0000 (14:47 -0400)
12 files changed:
doc/man/lttng.1
src/bin/lttng-relayd/utils.c
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/utils.c
src/bin/lttng/commands/create.c
src/bin/lttng/conf.c
src/bin/lttng/conf.h
src/bin/lttng/utils.c
src/common/defaults.h
src/common/utils.c
src/common/utils.h
src/lib/lttng-ctl/lttng-ctl.c

index f472d389d7bd9262d57dfacc109eab47d3f677ce..26fd44a69db986148a9b7150868a721b8ca8f4b1 100644 (file)
@@ -214,6 +214,10 @@ automatically created having this form: 'auto-yyyymmdd-hhmmss'.
 
 If no \fB\-o, \-\-output\fP is specified, the traces will be written in
 $HOME/lttng-traces.
+
+The $HOME environment variable can be overridden by defining the environment
+variable LTTNG_HOME. This is useful when the user running the commands has
+a non-writeable home directory.
 .fi
 
 .B OPTIONS:
index ad13d3277eb4106c7320bfbe3563d53ba57c1d72..392fab6a1b68bf6e25061bb6ec869e6738e67c8a 100644 (file)
 #include "lttng-relayd.h"
 #include "utils.h"
 
-/*
- * Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
- */
-static char *get_default_path(void)
-{
-       return getenv("HOME");
-}
-
 static char *create_output_path_auto(char *path_name)
 {
        int ret;
@@ -44,7 +36,7 @@ static char *create_output_path_auto(char *path_name)
        char *alloc_path = NULL;
        char *default_path;
 
-       default_path = get_default_path();
+       default_path = utils_get_home_dir();
        if (default_path == NULL) {
                ERR("Home path not found.\n \
                                Please specify an output path using -o, --output PATH");
index 55751e85b1d3bf480f24ef9e22cf231910a46f1b..f5a4db4dcb9830e98adc72ec8cd268bf6e7f3795 100644 (file)
@@ -4256,7 +4256,7 @@ int main(int argc, char **argv)
                DBG2("Kernel consumer cmd path: %s",
                                kconsumer_data.cmd_unix_sock_path);
        } else {
-               home_path = get_home_dir();
+               home_path = utils_get_home_dir();
                if (home_path == NULL) {
                        /* TODO: Add --socket PATH option */
                        ERR("Can't get HOME directory for sockets creation.");
index 358e407e9c326cf038024b570f4c9209a724e2ca..85a1f0203ae0e9088653271192d13172bf03f566 100644 (file)
@@ -49,16 +49,6 @@ int notify_thread_pipe(int wpipe)
        return ret;
 }
 
-/*
- * Return pointer to home directory path using the env variable HOME.
- *
- * No home, NULL is returned.
- */
-const char *get_home_dir(void)
-{
-       return ((const char *) getenv("HOME"));
-}
-
 void ht_cleanup_push(struct lttng_ht *ht)
 {
        int ret;
index 805cdb1d27157e73c674a93d6c13195b5d27fe36..ddd2983e238208a0888a90638c539bda692111cf 100644 (file)
@@ -250,7 +250,7 @@ static int create_session(void)
                print_str_url = url;
        } else {
                /* Auto output path */
-               alloc_path = config_get_default_path();
+               alloc_path = utils_get_home_dir();
                if (alloc_path == NULL) {
                        ERR("HOME path not found.\n \
                                        Please specify an output path using -o, --output PATH");
index b6632fcb144c052fa0ef4a9652843a074abd64c7..5a0da9d338feb6e3322965602f55386a87f301c2 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 
 #include <common/error.h>
+#include <common/utils.h>
 
 #include "conf.h"
 
@@ -122,14 +123,6 @@ end:
        return ret;
 }
 
-/*
- * Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
- */
-char *config_get_default_path(void)
-{
-       return getenv("HOME");
-}
-
 /*
  * Destroys directory config and file config.
  */
@@ -161,7 +154,7 @@ end:
  */
 void config_destroy_default(void)
 {
-       char *path = config_get_default_path();
+       char *path = utils_get_home_dir();
        if (path == NULL) {
                return;
        }
@@ -277,7 +270,7 @@ int config_init(char *session_name)
        int ret;
        char *path;
 
-       path = config_get_default_path();
+       path = utils_get_home_dir();
        if (path == NULL) {
                ret = -1;
                goto error;
index 2cb04b0c7f2c23b0cb6305c869137e9e60d1b404..3bed59c2a09a58bc2c56e5c01c107fe74d4571e7 100644 (file)
@@ -25,7 +25,6 @@ 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);
 
 /* Must free() the return pointer */
 char *config_read_session_name(char *path);
index 94c4527d97ff293029f99dbdca79e3cbf6956caa..6041655ddda0f6eb42de5b829cb29688c11f1a24 100644 (file)
@@ -21,6 +21,7 @@
 #include <limits.h>
 
 #include <common/error.h>
+#include <common/utils.h>
 
 #include "conf.h"
 #include "utils.h"
@@ -36,7 +37,7 @@ char *get_session_name(void)
        char *path, *session_name = NULL;
 
        /* Get path to config file */
-       path = config_get_default_path();
+       path = utils_get_home_dir();
        if (path == NULL) {
                goto error;
        }
index 66bb972fd7b219ead8c6ed14e192e33f3448e708..c040634880516231af7be0463e9ba650ff3b82db 100644 (file)
@@ -77,6 +77,8 @@
 #define DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH    DEFAULT_USTCONSUMERD32_PATH "/error"
 
 /* Default lttng run directory */
+#define DEFAULT_LTTNG_HOME_ENV_VAR              "LTTNG_HOME"
+#define DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR    "HOME"
 #define DEFAULT_LTTNG_RUNDIR                    "/var/run/lttng"
 #define DEFAULT_LTTNG_HOME_RUNDIR               "%s/.lttng"
 #define DEFAULT_LTTNG_SESSIOND_PIDFILE          "lttng-sessiond.pid"
index 3e659a1c81079d74b52aab9993c555fcaba6b62d..f253e797fae641e31ef98abcf4e829655feb8dfc 100644 (file)
@@ -32,6 +32,7 @@
 #include <common/runas.h>
 
 #include "utils.h"
+#include "defaults.h"
 
 /*
  * Return the realpath(3) of the path even if the last directory token does not
@@ -580,3 +581,17 @@ int utils_get_count_order_u32(uint32_t x)
 
        return fls_u32(x - 1);
 }
+
+/**
+ * Obtain the value of LTTNG_HOME environment variable, if exists.
+ * Otherwise returns the value of HOME.
+ */
+char *utils_get_home_dir(void)
+{
+       char *val = NULL;
+       val = getenv(DEFAULT_LTTNG_HOME_ENV_VAR);
+       if (val != NULL) {
+               return val;
+       }
+       return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR);
+}
index 083acef93a0a784e24f99a9299bddfa42ab23883..9e6fb37f007bec6f0f321e8ebb5ebe29a9034d8e 100644 (file)
@@ -40,5 +40,6 @@ int utils_rotate_stream_file(char *path_name, char *file_name, uint64_t size,
                uint64_t count, int uid, int gid, int out_fd, uint64_t *new_count);
 int utils_parse_size_suffix(char *str, uint64_t *size);
 int utils_get_count_order_u32(uint32_t x);
+char *utils_get_home_dir(void);
 
 #endif /* _COMMON_UTILS_H */
index 6c8ad411a3ab7de446f8a8bdda20c4b552dad6b6..1b9f3a8ab99a95d54e6ffcd6b8465092dfe4da17 100644 (file)
@@ -32,6 +32,7 @@
 #include <common/defaults.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/uri.h>
+#include <common/utils.h>
 #include <lttng/lttng.h>
 
 #include "filter/filter-ast.h"
@@ -485,7 +486,7 @@ static int set_session_daemon_path(void)
                 * With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
                 */
                ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
-                               DEFAULT_HOME_CLIENT_UNIX_SOCK, getenv("HOME"));
+                               DEFAULT_HOME_CLIENT_UNIX_SOCK, utils_get_home_dir());
                if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {
                        goto error;
                }
@@ -1543,7 +1544,7 @@ static int set_health_socket_path(void)
                 * With GNU C <  2.1, snprintf returns -1 if the target buffer is too small;
                 * With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
                 */
-               home = getenv("HOME");
+               home = utils_get_home_dir();
                if (home == NULL) {
                        /* Fallback in /tmp .. */
                        home = "/tmp";
This page took 0.034172 seconds and 5 git commands to generate.