X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=0147c8c994d3cb89f7fa936633863e043cdd2221;hb=8e1ef46e89a86865736a62d2def88f70acb0be55;hp=17a313ee16f66efe8c574ddfddc8f94f156b9e11;hpb=cec6b2a556f6880230c326b07facbc3f673ee0c7;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index 17a313ee1..0147c8c99 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1014,7 +1014,7 @@ static inline unsigned int fls_u32(uint32_t x) #define HAS_FLS_U32 #endif -#if defined(__x86_64) +#if defined(__x86_64) && defined(__LP64__) static inline unsigned int fls_u64(uint64_t x) { @@ -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; +}