<font size=2 face="sans-serif">I think I've done all that you suggested,
for lttng-tools only, though, based on cfa9a5a2b4a96e0d6a9eeddd2622a6d7c173b7ac
which is the latest master as of right now.</font>
<br>
<br><font size=2 face="sans-serif">Here is the patch:</font>
<br>
<div><tt><font size=2>From 5881718a60608d640ac1124c9c1f439a2a084707 Mon
Sep 17 00:00:00 2001<br>
From: Amit Margalit <amitm@il.ibm.com><br>
Date: Thu, 13 Jun 2013 12:35:13 +0300<br>
Subject: [PATCH] Using LTTNG_HOME environment variable if exists, with<br>
fallback to HOME</font></tt>
<br>
<br><tt><font size=2>---<br>
src/bin/lttng-relayd/utils.c | 10 +---------<br>
src/bin/lttng-sessiond/main.c | 2 +-<br>
src/bin/lttng-sessiond/utils.c | 10 ----------<br>
src/bin/lttng/commands/create.c | 2 +-<br>
src/bin/lttng/conf.c | 13 +++----------<br>
src/bin/lttng/conf.h | 1
-<br>
src/bin/lttng/utils.c | 3 ++-<br>
src/common/defaults.h | 2 ++<br>
src/common/utils.c | 15
+++++++++++++++<br>
src/common/utils.h | 1
+<br>
src/lib/lttng-ctl/lttng-ctl.c | 5 +++--<br>
11 files changed, 29 insertions(+), 35 deletions(-)</font></tt>
<br>
<br><tt><font size=2>diff --git a/src/bin/lttng-relayd/utils.c b/src/bin/lttng-relayd/utils.c<br>
index ad13d32..392fab6 100644<br>
--- a/src/bin/lttng-relayd/utils.c<br>
+++ b/src/bin/lttng-relayd/utils.c<br>
@@ -29,14 +29,6 @@<br>
#include "lttng-relayd.h"<br>
#include "utils.h"<br>
<br>
-/*<br>
- * Returns the HOME directory path. Caller MUST NOT free(3) the return
pointer.<br>
- */<br>
-static char *get_default_path(void)<br>
-{<br>
- return getenv("HOME");<br>
-}<br>
-<br>
static char *create_output_path_auto(char *path_name)<br>
{<br>
int ret;<br>
@@ -44,7 +36,7 @@ static char *create_output_path_auto(char *path_name)<br>
char *alloc_path = NULL;<br>
char *default_path;<br>
<br>
- default_path = get_default_path();<br>
+ default_path = utils_get_home_dir();<br>
if (default_path == NULL) {<br>
ERR("Home
path not found.\n \<br>
Please
specify an output path using -o, --output PATH");<br>
diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c<br>
index 4470afc..256ffba 100644<br>
--- a/src/bin/lttng-sessiond/main.c<br>
+++ b/src/bin/lttng-sessiond/main.c<br>
@@ -4136,7 +4136,7 @@ int main(int argc, char **argv)</font></tt>
<br><tt><font size=2>
DBG2("Kernel consumer cmd path: %s",<br>
kconsumer_data.cmd_unix_sock_path);<br>
} else {<br>
- home_path
= get_home_dir();<br>
+ home_path
= utils_get_home_dir();<br>
if
(home_path == NULL) {<br>
/* TODO: Add --socket PATH option */<br>
ERR("Can't get HOME directory for sockets
creation.");<br>
diff --git a/src/bin/lttng-sessiond/utils.c b/src/bin/lttng-sessiond/utils.c<br>
index 5ea3374..af42ad0 100644<br>
--- a/src/bin/lttng-sessiond/utils.c<br>
+++ b/src/bin/lttng-sessiond/utils.c<br>
@@ -45,13 +45,3 @@ int notify_thread_pipe(int wpipe)<br>
<br>
return ret;<br>
}<br>
-<br>
-/*<br>
- * Return pointer to home directory path using the env variable HOME.<br>
- *<br>
- * No home, NULL is returned.<br>
- */<br>
-const char *get_home_dir(void)<br>
-{<br>
- return ((const char *) getenv("HOME"));<br>
-}<br>
diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c<br>
index 805cdb1..ddd2983 100644<br>
--- a/src/bin/lttng/commands/create.c<br>
+++ b/src/bin/lttng/commands/create.c<br>
@@ -250,7 +250,7 @@ static int create_session(void)<br>
print_str_url
= url;<br>
} else {<br>
/*
Auto output path */</font></tt>
<br><tt><font size=2>-
alloc_path = config_get_default_path();<br>
+ alloc_path
= utils_get_home_dir();<br>
if
(alloc_path == NULL) {<br>
ERR("HOME path not found.\n \<br>
Please specify an output path using -o, --output
PATH");<br>
diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c<br>
index b6632fc..5a0da9d 100644<br>
--- a/src/bin/lttng/conf.c<br>
+++ b/src/bin/lttng/conf.c<br>
@@ -25,6 +25,7 @@<br>
#include <unistd.h><br>
<br>
#include <common/error.h><br>
+#include <common/utils.h><br>
<br>
#include "conf.h"<br>
<br>
@@ -123,14 +124,6 @@ end:<br>
}<br>
<br>
/*<br>
- * Returns the HOME directory path. Caller MUST NOT free(3) the return
pointer.<br>
- */<br>
-char *config_get_default_path(void)<br>
-{<br>
- return getenv("HOME");<br>
-}<br>
-<br>
-/*<br>
* Destroys directory config and file config.<br>
*/<br>
void config_destroy(char *path)<br>
@@ -161,7 +154,7 @@ end:<br>
*/<br>
void config_destroy_default(void)<br>
{<br>
- char *path = config_get_default_path();<br>
+ char *path = utils_get_home_dir();<br>
if (path == NULL) {<br>
return;<br>
}<br>
@@ -277,7 +270,7 @@ int config_init(char *session_name)<br>
int ret;<br>
char *path;<br>
<br>
- path = config_get_default_path();</font></tt>
<br><tt><font size=2>+ path = utils_get_home_dir();<br>
if (path == NULL) {<br>
ret
= -1;<br>
goto
error;<br>
diff --git a/src/bin/lttng/conf.h b/src/bin/lttng/conf.h<br>
index 2cb04b0..3bed59c 100644<br>
--- a/src/bin/lttng/conf.h<br>
+++ b/src/bin/lttng/conf.h<br>
@@ -25,7 +25,6 @@ void config_destroy_default(void);<br>
int config_exists(const char *path);<br>
int config_init(char *path);<br>
int config_add_session_name(char *path, char *name);<br>
-char *config_get_default_path(void);<br>
<br>
/* Must free() the return pointer */<br>
char *config_read_session_name(char *path);<br>
diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c<br>
index 94c4527..6041655 100644<br>
--- a/src/bin/lttng/utils.c<br>
+++ b/src/bin/lttng/utils.c<br>
@@ -21,6 +21,7 @@<br>
#include <limits.h><br>
<br>
#include <common/error.h><br>
+#include <common/utils.h><br>
<br>
#include "conf.h"<br>
#include "utils.h"<br>
@@ -36,7 +37,7 @@ char *get_session_name(void)<br>
char *path, *session_name = NULL;<br>
<br>
/* Get path to config file */<br>
- path = config_get_default_path();<br>
+ path = utils_get_home_dir();<br>
if (path == NULL) {<br>
goto
error;<br>
}</font></tt>
<br><tt><font size=2>diff --git a/src/common/defaults.h b/src/common/defaults.h<br>
index 66bb972..c040634 100644<br>
--- a/src/common/defaults.h<br>
+++ b/src/common/defaults.h<br>
@@ -77,6 +77,8 @@<br>
#define DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH DEFAULT_USTCONSUMERD32_PATH
"/error"<br>
<br>
/* Default lttng run directory */<br>
+#define DEFAULT_LTTNG_HOME_ENV_VAR
"LTTNG_HOME"<br>
+#define DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR "HOME"<br>
#define DEFAULT_LTTNG_RUNDIR
"/var/run/lttng"<br>
#define DEFAULT_LTTNG_HOME_RUNDIR
"%s/.lttng"<br>
#define DEFAULT_LTTNG_SESSIOND_PIDFILE "lttng-sessiond.pid"<br>
diff --git a/src/common/utils.c b/src/common/utils.c<br>
index 38f78a7..436febe 100644<br>
--- a/src/common/utils.c<br>
+++ b/src/common/utils.c<br>
@@ -32,6 +32,7 @@<br>
#include <common/runas.h><br>
<br>
#include "utils.h"<br>
+#include "defaults.h"<br>
<br>
/*<br>
* Return the realpath(3) of the path even if the last directory
token does not<br>
@@ -584,3 +585,17 @@ int utils_get_count_order_u32(uint32_t x)<br>
<br>
return fls_u32(x - 1);<br>
}<br>
+<br>
+/**<br>
+ * Obtain the value of LTTNG_HOME environment variable, if exists.</font></tt>
<br><tt><font size=2>+ * Otherwise returns the value of HOME.<br>
+ */<br>
+char *utils_get_home_dir(void)<br>
+{<br>
+ char *val = NULL;<br>
+ val = getenv(DEFAULT_LTTNG_HOME_ENV_VAR);<br>
+ if (val != NULL) {<br>
+ return
val;<br>
+ }<br>
+ return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR);<br>
+}<br>
diff --git a/src/common/utils.h b/src/common/utils.h<br>
index 083acef..9e6fb37 100644<br>
--- a/src/common/utils.h<br>
+++ b/src/common/utils.h<br>
@@ -40,5 +40,6 @@ int utils_rotate_stream_file(char *path_name, char *file_name,
uint64_t size,<br>
uint64_t
count, int uid, int gid, int out_fd, uint64_t *new_count);<br>
int utils_parse_size_suffix(char *str, uint64_t *size);<br>
int utils_get_count_order_u32(uint32_t x);<br>
+char *utils_get_home_dir(void);<br>
<br>
#endif /* _COMMON_UTILS_H */<br>
diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c<br>
index a7328eb..9d76f79 100644<br>
--- a/src/lib/lttng-ctl/lttng-ctl.c<br>
+++ b/src/lib/lttng-ctl/lttng-ctl.c<br>
@@ -32,6 +32,7 @@<br>
#include <common/defaults.h><br>
#include <common/sessiond-comm/sessiond-comm.h><br>
#include <common/uri.h><br>
+#include <common/utils.h></font></tt>
<br><tt><font size=2> #include <lttng/lttng.h><br>
<br>
#include "filter/filter-ast.h"<br>
@@ -485,7 +486,7 @@ static int set_session_daemon_path(void)<br>
*
With GNU C >= 2.1, snprintf returns the required size (excluding closing
null)<br>
*/<br>
ret
= snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),<br>
-
DEFAULT_HOME_CLIENT_UNIX_SOCK,
getenv("HOME"));<br>
+
DEFAULT_HOME_CLIENT_UNIX_SOCK,
utils_get_home_dir());<br>
if
((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {<br>
goto error;<br>
}<br>
@@ -1543,7 +1544,7 @@ static int set_health_socket_path(void)<br>
*
With GNU C < 2.1, snprintf returns -1 if the target buffer is
too small;<br>
*
With GNU C >= 2.1, snprintf returns the required size (excluding closing
null)<br>
*/<br>
- home
= getenv("HOME");<br>
+ home
= utils_get_home_dir();<br>
if
(home == NULL) {<br>
/* Fallback in /tmp .. */<br>
home = "/tmp";<br>
-- <br>
1.7.11.7</font></tt>
<br>
<br>
<br><font size=2 color=#000080 face="sans-serif">Amit Margalit</font>
<br><font size=2 color=#808000 face="sans-serif">IBM XIV </font><font size=2 face="sans-serif">-
<i>Storage Reinvented</i></font>
<br><font size=2 face="sans-serif">XIV-NAS Development Team</font>
<br><font size=2 face="sans-serif">Tel. 03</font><font size=2 face="Arial">-689-7774</font>
<br><font size=2 face="Arial">Fax. 03-689-7230</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:
</font><font size=1 face="sans-serif">David Goulet <dgoulet@efficios.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">Amit Margalit/Israel/IBM@IBMIL</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:
</font><font size=1 face="sans-serif">lttng-dev@lists.lttng.org</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">06/12/2013 05:46 PM</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: [lttng-dev]
[RFC PATCH lttng-tools] Allow environment variable LTTNG_HOME to override
HOME - for lttng-tools</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>This looks good! It appears that there are multiple
callsites doing the same<br>
thing... We might want to just put it in src/common/utils.c with something
like<br>
utils_get_home_dir() and use it from there.<br>
<br>
Also, adding "LTTNG_HOME" in defaults.h as a defined value for
the env. variable<br>
name. Finally, updating the man page would be also great. :)<br>
<br>
Once you are ready to submit the patch, it would be good to use "git<br>
format-patch" or send me a pull request based on git HEAD master.<br>
<br>
Big thanks for this contribution!<br>
David<br>
<br>
Amit Margalit:<br>
> Hello all,<br>
> <br>
> Patch functionality - If LTTNG_HOME environment variable exists, it
is used<br>
> instead of HOME.<br>
> Reason for patch - We are trying to deploy LTTng on a system where
$HOME is on a<br>
> filesystem mounted read-only, but cannot afford to run lttng as a
different user<br>
> and cannot move the home directories of users to writeable locations.<br>
> Patch baseline: 2.2.0 rc2<br>
> <br>
> This patch handles only lttng-tools.<br>
> <br>
> I can provide the same patches against git, if asked.<br>
> <br>
> diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng/conf.c<br>
> lttng-tools-2.2.0-rc2/src/bin/lttng/conf.c<br>
> --- lttng-tools-2.2.0-rc2-orig/src/bin/lttng/conf.c
2013-05-06<br>
> 21:50:59.000000000 +0300<br>
> +++ lttng-tools-2.2.0-rc2/src/bin/lttng/conf.c
2013-06-11<br>
> 14:17:34.681673309 +0300<br>
> @@ -127,6 +127,11 @@<br>
> */<br>
> char *config_get_default_path(void)<br>
> {<br>
> + char *val = NULL;<br>
> + val = getenv("LTTNG_HOME");<br>
> + if (val != NULL) {<br>
> + return val;<br>
> + }<br>
> return getenv("HOME");<br>
> }<br>
> <br>
> diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng-relayd/utils.c<br>
> lttng-tools-2.2.0-rc2/src/bin/lttng-relayd/utils.c<br>
> --- lttng-tools-2.2.0-rc2-orig/src/bin/lttng-relayd/utils.c
2013-05-06<br>
> 21:50:59.000000000 +0300<br>
> +++ lttng-tools-2.2.0-rc2/src/bin/lttng-relayd/utils.c
2013-06-11<br>
> 14:15:52.553673444 +0300<br>
> @@ -34,7 +34,11 @@<br>
> */<br>
> static char *get_default_path(void)<br>
> {<br>
> - return getenv("HOME");<br>
> + char *val = NULL;<br>
> + val = getenv("LTTNG_HOME");<br>
> + if (val != NULL) {<br>
> + return val;<br>
> + }<br>
> }<br>
> <br>
> static char *create_output_path_auto(char *path_name)<br>
> diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng-sessiond/utils.c<br>
> lttng-tools-2.2.0-rc2/src/bin/lttng-sessiond/utils.c<br>
> --- lttng-tools-2.2.0-rc2-orig/src/bin/lttng-sessiond/utils.c
2013-01-07<br>
> 22:05:16.000000000 +0200<br>
> +++ lttng-tools-2.2.0-rc2/src/bin/lttng-sessiond/utils.c
2013-06-11<br>
> 14:16:16.697673412 +0300<br>
> @@ -53,5 +53,10 @@<br>
> */<br>
> const char *get_home_dir(void)<br>
> {<br>
> + const char *val = NULL;<br>
> + val = ((const char *) getenv("LTTNG_HOME"));<br>
> + if (val != NULL) {<br>
> + return val;<br>
> + }<br>
> return ((const char *) getenv("HOME"));<br>
> }<br>
> diff -ur lttng-tools-2.2.0-rc2-orig/src/lib/lttng-ctl/lttng-ctl.c<br>
> lttng-tools-2.2.0-rc2/src/lib/lttng-ctl/lttng-ctl.c<br>
> --- lttng-tools-2.2.0-rc2-orig/src/lib/lttng-ctl/lttng-ctl.c
2013-05-07<br>
> 22:42:07.000000000 +0300<br>
> +++ lttng-tools-2.2.0-rc2/src/lib/lttng-ctl/lttng-ctl.c
2013-06-11<br>
> 14:19:15.177673176 +0300<br>
> @@ -74,6 +74,22 @@<br>
> int lttng_opt_verbose;<br>
> <br>
> /*<br>
> + * Get the value of LTTNG_HOME if present, or HOME if not.<br>
> + * Caller must not free the returned pointer.<br>
> + * Used<br>
> + */<br>
> +static const char *get_lttng_home_dir(void)<br>
> +{<br>
> + const char *val = NULL;<br>
> + val = ((const char *) getenv("LTTNG_HOME"));<br>
> + if (val != NULL) {<br>
> + return val;<br>
> + }<br>
> + return ((const char *) getenv("HOME"));<br>
> +}<br>
> +<br>
> +<br>
> +/*<br>
> * Compare two URL destination.<br>
> *<br>
> * Return 0 is equal else is not equal.<br>
> @@ -485,7 +501,7 @@<br>
> * With
GNU C >= 2.1, snprintf returns the required size<br>
> (excluding closing null)<br>
> */<br>
> ret
= snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),<br>
> -
DEFAULT_HOME_CLIENT_UNIX_SOCK,
getenv("HOME"));<br>
> +
DEFAULT_HOME_CLIENT_UNIX_SOCK,<br>
> get_lttng_home_dir());<br>
> if ((ret
< 0) || (ret >= sizeof(sessiond_sock_path))) {<br>
>
goto error;<br>
> }<br>
> @@ -1543,7 +1559,7 @@<br>
> * With
GNU C < 2.1, snprintf returns -1 if the target buffer<br>
> is too small;<br>
> * With
GNU C >= 2.1, snprintf returns the required size<br>
> (excluding closing null)<br>
> */<br>
> - home = getenv("HOME");<br>
> + home = get_lttng_home_dir();<br>
> if (home
== NULL) {<br>
>
/* Fallback in /tmp .. */<br>
>
home = "/tmp";<br>
> <br>
> Thanks,<br>
> <br>
> Amit Margalit<br>
> IBM XIV - /Storage Reinvented/<br>
> XIV-NAS Development Team<br>
> Tel. 03-689-7774<br>
> Fax. 03-689-7230<br>
> <br>
> <br>
> This body part will be downloaded on demand.<br>
<br>
</font></tt>
<br></div>