X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=2e07d4ff0b6d366268755b7969dab0d58199385e;hp=3cdb6b76063caf4545761a93b52523dd2c39b14c;hb=83c50c540631cb2cd9cd099a801f2329a5c4b8bf;hpb=a1e4ab8b82429320c5f962038c0f28b874f8ea6f diff --git a/src/common/utils.c b/src/common/utils.c index 3cdb6b760..2e07d4ff0 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -324,7 +324,7 @@ error: * The returned string was allocated in the function, it is thus of * the responsibility of the caller to free this memory. */ -LTTNG_HIDDEN +static char *_utils_expand_path(const char *path, bool keep_symlink) { int ret; @@ -1501,3 +1501,35 @@ int utils_get_memory_total(size_t *value) { return read_proc_meminfo_field(PROC_MEMINFO_MEMTOTAL_LINE, value); } + +LTTNG_HIDDEN +int utils_change_working_directory(const char *path) +{ + int ret; + + assert(path); + + DBG("Changing working directory to \"%s\"", path); + ret = chdir(path); + if (ret) { + PERROR("Failed to change working directory to \"%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 \"%s\" is not writable", path); + } else { + PERROR("Failed to check if working directory \"%s\" is writable", + path); + } + } + +end: + return ret; +}