X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=ef22144d4e8637ddf15af3f456c11e0a10585efd;hp=7006a21581ea91f952c7d7dbe57a1095d467979e;hb=440bede9ee59598b9ea8a3a3ff3191b8c84bd4f7;hpb=6f1105342bcca0c5ba8177ae134c197c19ba215f diff --git a/src/common/utils.c b/src/common/utils.c index 7006a2158..ef22144d4 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -65,7 +65,7 @@ * to specify the size of the resolved_path argument if given, or the size to * allocate. */ -LTTNG_HIDDEN +static char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) { char *cut_path = NULL, *try_path = NULL, *try_path_prev = NULL; @@ -679,8 +679,8 @@ int utils_mkdir(const char *path, mode_t mode, int uid, int gid) int ret; struct lttng_directory_handle *handle; const struct lttng_credentials creds = { - .uid = (uid_t) uid, - .gid = (gid_t) gid, + .uid = LTTNG_OPTIONAL_INIT_VALUE(uid), + .gid = LTTNG_OPTIONAL_INIT_VALUE(gid), }; handle = lttng_directory_handle_create(NULL); @@ -708,8 +708,8 @@ int utils_mkdir_recursive(const char *path, mode_t mode, int uid, int gid) int ret; struct lttng_directory_handle *handle; const struct lttng_credentials creds = { - .uid = (uid_t) uid, - .gid = (gid_t) gid, + .uid = LTTNG_OPTIONAL_INIT_VALUE(uid), + .gid = LTTNG_OPTIONAL_INIT_VALUE(gid), }; handle = lttng_directory_handle_create(NULL); @@ -1274,8 +1274,14 @@ int utils_get_group_id(const char *name, bool warn, gid_t *gid) } } if (ret) { - PERROR("Failed to get group file entry for group name \"%s\"", - name); + if (ret == ESRCH) { + DBG("Could not find group file entry for group name '%s'", + name); + } else { + PERROR("Failed to get group file entry for group name '%s'", + name); + } + ret = -1; goto error; } @@ -1663,3 +1669,39 @@ end: free(buf); return ret_val; } + +LTTNG_HIDDEN +int utils_parse_unsigned_long_long(const char *str, + unsigned long long *value) +{ + int ret; + char *endptr; + + assert(str); + assert(value); + + errno = 0; + *value = strtoull(str, &endptr, 10); + + /* Conversion failed. Out of range? */ + if (errno != 0) { + /* Don't print an error; allow the caller to log a better error. */ + DBG("Failed to parse string as unsigned long long number: string = '%s', errno = %d", + str, errno); + ret = -1; + goto end; + } + + /* Not the end of the string or empty string. */ + if (*endptr || endptr == str) { + DBG("Failed to parse string as unsigned long long number: string = '%s'", + str); + ret = -1; + goto end; + } + + ret = 0; + +end: + return ret; +}