Backport: Add --working-directory options to lttng-relayd
[lttng-tools.git] / src / common / utils.c
index 25d510854f972438085c98a8b6f41fd06001bf47..d8a78091a4076fd90bb9d9956286dd1dfb9b8f2b 100644 (file)
@@ -1452,3 +1452,33 @@ int utils_show_man_page(int section, const char *page_name)
                section_string, page_name, NULL);
        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.024331 seconds and 5 git commands to generate.