[lttng-dev] [RFC PATCH lttng-tools] Allow environment variable LTTNG_HOME to override HOME - for lttng-tools

Amit Margalit AMITM at il.ibm.com
Tue Jun 11 08:07:16 EDT 2013


Hello all, 

Patch functionality - If LTTNG_HOME environment variable exists, it is 
used instead of HOME. 
Reason for patch - We are trying to deploy LTTng on a system where $HOME 
is on a filesystem mounted read-only, but cannot afford to run lttng as a 
different user and cannot move the home directories of users to writeable 
locations. 
Patch baseline: 2.2.0 rc2 

This patch handles only lttng-tools.

I can provide the same patches against git, if asked.

diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng/conf.c 
lttng-tools-2.2.0-rc2/src/bin/lttng/conf.c
--- lttng-tools-2.2.0-rc2-orig/src/bin/lttng/conf.c     2013-05-06 
21:50:59.000000000 +0300
+++ lttng-tools-2.2.0-rc2/src/bin/lttng/conf.c  2013-06-11 
14:17:34.681673309 +0300
@@ -127,6 +127,11 @@
  */
 char *config_get_default_path(void)
 {
+       char *val = NULL;
+       val = getenv("LTTNG_HOME");
+       if (val != NULL) {
+               return val;
+       }
        return getenv("HOME");
 }
 
diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng-relayd/utils.c 
lttng-tools-2.2.0-rc2/src/bin/lttng-relayd/utils.c
--- lttng-tools-2.2.0-rc2-orig/src/bin/lttng-relayd/utils.c     2013-05-06 
21:50:59.000000000 +0300
+++ lttng-tools-2.2.0-rc2/src/bin/lttng-relayd/utils.c  2013-06-11 
14:15:52.553673444 +0300
@@ -34,7 +34,11 @@
  */
 static char *get_default_path(void)
 {
-       return getenv("HOME");
+       char *val = NULL;
+       val = getenv("LTTNG_HOME");
+       if (val != NULL) {
+               return val;
+       }
 }
 
 static char *create_output_path_auto(char *path_name)
diff -ur lttng-tools-2.2.0-rc2-orig/src/bin/lttng-sessiond/utils.c 
lttng-tools-2.2.0-rc2/src/bin/lttng-sessiond/utils.c
--- lttng-tools-2.2.0-rc2-orig/src/bin/lttng-sessiond/utils.c   2013-01-07 
22:05:16.000000000 +0200
+++ lttng-tools-2.2.0-rc2/src/bin/lttng-sessiond/utils.c        2013-06-11 
14:16:16.697673412 +0300
@@ -53,5 +53,10 @@
  */
 const char *get_home_dir(void)
 {
+       const char *val = NULL;
+       val = ((const char *) getenv("LTTNG_HOME"));
+       if (val != NULL) {
+               return val;
+       }
        return ((const char *) getenv("HOME"));
 }
diff -ur lttng-tools-2.2.0-rc2-orig/src/lib/lttng-ctl/lttng-ctl.c 
lttng-tools-2.2.0-rc2/src/lib/lttng-ctl/lttng-ctl.c
--- lttng-tools-2.2.0-rc2-orig/src/lib/lttng-ctl/lttng-ctl.c    2013-05-07 
22:42:07.000000000 +0300
+++ lttng-tools-2.2.0-rc2/src/lib/lttng-ctl/lttng-ctl.c 2013-06-11 
14:19:15.177673176 +0300
@@ -74,6 +74,22 @@
 int lttng_opt_verbose;
 
 /*
+ * Get the value of LTTNG_HOME if present, or HOME if not.
+ * Caller must not free the returned pointer.
+ * Used 
+ */
+static const char *get_lttng_home_dir(void)
+{
+       const char *val = NULL;
+       val = ((const char *) getenv("LTTNG_HOME"));
+       if (val != NULL) {
+               return val;
+       }
+       return ((const char *) getenv("HOME"));
+}
+
+
+/*
  * Compare two URL destination.
  *
  * Return 0 is equal else is not equal.
@@ -485,7 +501,7 @@
                 * 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, 
get_lttng_home_dir());
                if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {
                        goto error;
                }
@@ -1543,7 +1559,7 @@
                 * 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 = get_lttng_home_dir();
                if (home == NULL) {
                        /* Fallback in /tmp .. */
                        home = "/tmp";

Thanks,

Amit Margalit
IBM XIV - Storage Reinvented
XIV-NAS Development Team
Tel. 03-689-7774
Fax. 03-689-7230
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20130611/11a03183/attachment-0001.html>


More information about the lttng-dev mailing list