X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=df409aa4cc6ddde35c81cda88f7b4ef7f6330894;hb=refs%2Fheads%2Fsow-2020-0002-rev2;hp=2a20e5a8c4ab4cca1557ca917cfa2de02defd905;hpb=9120e619240c698c899a9baea203a52c4bdfd565;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index 2a20e5a8c..df409aa4c 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -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); @@ -1486,6 +1486,16 @@ fopen_error: return ret; } +LTTNG_HIDDEN +int utils_get_number_of_possible_cpus(void) +{ + /* + * Return the number of configured cpus as opposed to number of online + * cpus. + */ + return sysconf(_SC_NPROCESSORS_CONF); +} + /* * Returns an estimate of the number of bytes of memory available based on the * the information in `/proc/meminfo`. The number returned by this function is @@ -1669,3 +1679,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; +}