X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=0147c8c994d3cb89f7fa936633863e043cdd2221;hb=20dd2de1fa1efe1519d1b6e88386efa89d60d1b9;hp=b0e5b63e34400c3f0e2e2df57b58fcdf0f875f32;hpb=2530e68bb73b6ed32df6c5b4a5031bca3f5f3015;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index b0e5b63e3..0147c8c99 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -379,6 +379,9 @@ char *_utils_expand_path(const char *path, bool keep_symlink) /* Resolve partially our path */ absolute_path = utils_partial_realpath(absolute_path, absolute_path, LTTNG_PATH_MAX); + if (!absolute_path) { + goto error; + } } ret = expand_double_slashes_dot_and_dotdot(absolute_path); @@ -1011,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) { @@ -1498,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; +}