Using LTTNG_HOME environment variable if exists, with fallback to HOME
[lttng-tools.git] / src / common / utils.c
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);
+}
This page took 0.023862 seconds and 4 git commands to generate.