X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Futils.c;h=d8a78091a4076fd90bb9d9956286dd1dfb9b8f2b;hb=763755801af9465a7936b1a4cbb613123781f740;hp=25d510854f972438085c98a8b6f41fd06001bf47;hpb=874e125545cd9600a2c1e19f5eca44ce1af962b7;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; +}