#define PROC_MEMINFO_MEMAVAILABLE_LINE "MemAvailable:"
#define PROC_MEMINFO_MEMTOTAL_LINE "MemTotal:"
-/* The length of the longest field of `/proc/meminfo`. */
+/* The lnullptrh of the longest field of `/proc/meminfo`. */
#define PROC_MEMINFO_FIELD_MAX_NAME_LEN 20
#if (PROC_MEMINFO_FIELD_MAX_NAME_LEN == 20)
{
int ret;
- if (dst == NULL) {
+ if (dst == nullptr) {
return -1;
}
{
int ret, i;
- if (dst == NULL) {
+ if (dst == nullptr) {
return -1;
}
{
int ret, i;
- if (dst == NULL) {
+ if (dst == nullptr) {
return -1;
}
{
int i, ret;
- if (src == NULL) {
+ if (src == nullptr) {
return;
}
{
char *str = zmalloc<char>(end - begin + 1);
- if (str == NULL) {
+ if (str == nullptr) {
PERROR("zmalloc strdupdelim");
goto error;
}
int utils_create_pid_file(pid_t pid, const char *filepath)
{
int ret, fd = -1;
- FILE *fp = NULL;
+ FILE *fp = nullptr;
LTTNG_ASSERT(filepath);
}
fp = fdopen(fd, "w");
- if (fp == NULL) {
+ if (fp == nullptr) {
PERROR("fdopen file %s", filepath);
ret = -1;
if (close(fd)) {
return ret;
}
-/*
- * Create lock file to the given path and filename.
- * Returns the associated file descriptor, -1 on error.
- */
-int utils_create_lock_file(const char *filepath)
-{
- int ret;
- int fd;
- struct flock lock;
-
- LTTNG_ASSERT(filepath);
-
- memset(&lock, 0, sizeof(lock));
- fd = open(filepath, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
- if (fd < 0) {
- PERROR("open lock file %s", filepath);
- fd = -1;
- goto error;
- }
-
- /*
- * Attempt to lock the file. If this fails, there is
- * already a process using the same lock file running
- * and we should exit.
- */
- lock.l_whence = SEEK_SET;
- lock.l_type = F_WRLCK;
-
- ret = fcntl(fd, F_SETLK, &lock);
- if (ret == -1) {
- PERROR("fcntl lock file");
- ERR("Could not get lock file %s, another instance is running.", filepath);
- if (close(fd)) {
- PERROR("close lock file");
- }
- fd = ret;
- goto error;
- }
-
-error:
- return fd;
-}
-
/*
* Create directory using the given path and mode.
*
.gid = LTTNG_OPTIONAL_INIT_VALUE((gid_t) gid),
};
- handle = lttng_directory_handle_create(NULL);
+ handle = lttng_directory_handle_create(nullptr);
if (!handle) {
ret = -1;
goto end;
}
ret = lttng_directory_handle_create_subdirectory_as_user(
- handle, path, mode, (uid >= 0 || gid >= 0) ? &creds : NULL);
+ handle, path, mode, (uid >= 0 || gid >= 0) ? &creds : nullptr);
end:
lttng_directory_handle_put(handle);
return ret;
.gid = LTTNG_OPTIONAL_INIT_VALUE((gid_t) gid),
};
- handle = lttng_directory_handle_create(NULL);
+ handle = lttng_directory_handle_create(nullptr);
if (!handle) {
ret = -1;
goto end;
}
ret = lttng_directory_handle_create_subdirectory_recursive_as_user(
- handle, path, mode, (uid >= 0 || gid >= 0) ? &creds : NULL);
+ handle, path, mode, (uid >= 0 || gid >= 0) ? &creds : nullptr);
end:
lttng_directory_handle_put(handle);
return ret;
}
/* strtoull will accept a negative number, but we don't want to. */
- if (strchr(str, '-') != NULL) {
+ if (strchr(str, '-') != nullptr) {
DBG("utils_parse_size_suffix: invalid size string, should not contain '-'.");
ret = -1;
goto end;
}
/* strtoull will accept a negative number, but we don't want to. */
- if (strchr(str, '-') != NULL) {
+ if (strchr(str, '-') != nullptr) {
DBG("utils_parse_time_suffix: invalid time string, should not contain '-'.");
ret = -1;
goto end;
* Obtain the value of LTTNG_HOME environment variable, if exists.
* Otherwise returns the value of HOME.
*/
-const char *utils_get_home_dir(void)
+const char *utils_get_home_dir()
{
- char *val = NULL;
+ char *val = nullptr;
struct passwd *pwd;
val = lttng_secure_getenv(DEFAULT_LTTNG_HOME_ENV_VAR);
- if (val != NULL) {
+ if (val != nullptr) {
goto end;
}
val = lttng_secure_getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR);
- if (val != NULL) {
+ if (val != nullptr) {
goto end;
}
{
struct passwd pwd;
struct passwd *result;
- char *home_dir = NULL;
- char *buf = NULL;
+ char *home_dir = nullptr;
+ char *buf = nullptr;
long buflen;
int ret;
int ret;
struct lttng_directory_handle *handle;
- handle = lttng_directory_handle_create(NULL);
+ handle = lttng_directory_handle_create(nullptr);
if (!handle) {
ret = -1;
goto end;
return ret;
}
-static const char *get_man_bin_path(void)
+static const char *get_man_bin_path()
{
char *env_man_path = lttng_secure_getenv(DEFAULT_MAN_BIN_PATH_ENV);
return DEFAULT_MAN_BIN_PATH;
}
+static const char *get_manpath()
+{
+ char *manpath = lttng_secure_getenv(DEFAULT_MANPATH);
+
+ if (manpath) {
+ return manpath;
+ }
+
+ /* As defined during configuration. */
+ return MANPATH;
+}
+
int utils_show_help(int section, const char *page_name, const char *help_msg)
{
char section_string[8];
const char *man_bin_path = get_man_bin_path();
+ const char *manpath = get_manpath();
int ret = 0;
if (help_msg) {
}
/* Section integer -> section string */
- ret = sprintf(section_string, "%d", section);
+ ret = snprintf(section_string, sizeof(section_string), "%d", section);
LTTNG_ASSERT(ret > 0 && ret < 8);
/*
* be installed outside /usr, in which case its man pages are
* not located in the default /usr/share/man directory.
*/
- ret = execlp(man_bin_path, "man", "-M", MANPATH, section_string, page_name, NULL);
+ ret = execlp(man_bin_path, "man", "-M", manpath, section_string, page_name, NULL);
end:
return ret;
struct passwd p, *pres;
int ret;
enum lttng_error_code ret_val = LTTNG_OK;
- char *buf = NULL;
+ char *buf = nullptr;
ssize_t buflen;
buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
switch (ret) {
case 0:
- if (pres == NULL) {
+ if (pres == nullptr) {
ret_val = LTTNG_ERR_USER_NOT_FOUND;
} else {
*uid = p.pw_uid;
struct group g, *gres;
int ret;
enum lttng_error_code ret_val = LTTNG_OK;
- char *buf = NULL;
+ char *buf = nullptr;
ssize_t buflen;
buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
switch (ret) {
case 0:
- if (gres == NULL) {
+ if (gres == nullptr) {
ret_val = LTTNG_ERR_GROUP_NOT_FOUND;
} else {
*gid = g.gr_gid;