X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=d8a78091a4076fd90bb9d9956286dd1dfb9b8f2b;hb=a174e6fcacf84b0451d34b51503eef2b664888d1;hp=25d510854f972438085c98a8b6f41fd06001bf47;hpb=c4d7f609b1ea5dde017b93e21647fe9c91a9dfa6;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index 25d510854..d8a78091a 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -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; +}