Add kernel snapshot support
[lttng-tools.git] / src / common / utils.c
index 38f78a7e8e7d40cd6fcebefd297e5bb240c52aaf..ecac5381f061fb65c89bda64de0ad86e5be37f6f 100644 (file)
@@ -22,8 +22,8 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include <inttypes.h>
 #include <regex.h>
@@ -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
@@ -248,7 +249,6 @@ LTTNG_HIDDEN
 int utils_mkdir_recursive(const char *path, mode_t mode)
 {
        char *p, tmp[PATH_MAX];
-       struct stat statbuf;
        size_t len;
        int ret;
 
@@ -276,15 +276,12 @@ int utils_mkdir_recursive(const char *path, mode_t mode)
                                ret = -1;
                                goto error;
                        }
-                       ret = stat(tmp, &statbuf);
+                       ret = mkdir(tmp, mode);
                        if (ret < 0) {
-                               ret = mkdir(tmp, mode);
-                               if (ret < 0) {
-                                       if (errno != EEXIST) {
-                                               PERROR("mkdir recursive");
-                                               ret = -errno;
-                                               goto error;
-                                       }
+                               if (errno != EEXIST) {
+                                       PERROR("mkdir recursive");
+                                       ret = -errno;
+                                       goto error;
                                }
                        }
                        *p = '/';
@@ -311,7 +308,7 @@ error:
  * Return 0 on success or else a negative value.
  */
 LTTNG_HIDDEN
-int utils_create_stream_file(char *path_name, char *file_name, uint64_t size,
+int utils_create_stream_file(const char *path_name, char *file_name, uint64_t size,
                uint64_t count, int uid, int gid)
 {
        int ret, out_fd, flags, mode;
@@ -584,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.025243 seconds and 5 git commands to generate.