Add --working-directory options to lttng-relayd
[deliverable/lttng-tools.git] / src / common / utils.c
index 7d018b53b1b9430cfb427761f9d4b4a4573e0334..7243a5d94b3cbdd091831103649529a8bbac1ab9 100644 (file)
@@ -1545,3 +1545,33 @@ int utils_show_help(int section, const char *page_name,
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int utils_change_working_dir(const char *path)
+{
+       int ret;
+
+       assert(path);
+
+       ret = chdir(path);
+       if (ret) {
+               PERROR("Failed to change working directory: %s", path);
+               goto end;
+       }
+
+       /* Check for write access */
+       if (access(path, W_OK)) {
+               if (errno == EACCES) {
+                       /*
+                        * Do not treat this as an error since the permission
+                        * might change in the lifetime of the process
+                        */
+                       DBG("Working directory is not writable: %s", path);
+               } else {
+                       PERROR("access");
+               }
+       }
+
+end:
+       return ret;
+}
This page took 0.02609 seconds and 5 git commands to generate.