projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: lttng: poptGetArg doesn't provide string ownership
[lttng-tools.git]
/
src
/
bin
/
lttng
/
commands
/
list.cpp
diff --git
a/src/bin/lttng/commands/list.cpp
b/src/bin/lttng/commands/list.cpp
index 4bb681e09c1a9dca8850242dfc156c98beb8e62e..5f52a57f6dcd4973faad510c66461bb65c6c0d01 100644
(file)
--- a/
src/bin/lttng/commands/list.cpp
+++ b/
src/bin/lttng/commands/list.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2011
David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011
EfficiOS Inc.
* Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* SPDX-License-Identifier: GPL-2.0-only
@@
-14,13
+14,13
@@
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-#include <common/mi-lttng.h>
-#include <common/time.h>
-#include <common/tracker.h>
-#include <lttng/domain-internal.h>
+#include <common/mi-lttng.h
pp
>
+#include <common/time.h
pp
>
+#include <common/tracker.h
pp
>
+#include <lttng/domain-internal.h
pp
>
#include <lttng/lttng.h>
#include <lttng/lttng.h>
-#include "../command.h"
+#include "../command.h
pp
"
static int opt_userspace;
static int opt_kernel;
static int opt_userspace;
static int opt_kernel;
@@
-91,11
+91,12
@@
static char *get_cmdline_by_pid(pid_t pid)
}
/* Caller must free() *cmdline */
}
/* Caller must free() *cmdline */
- cmdline =
(char *) zmalloc
(PATH_MAX);
+ cmdline =
zmalloc<char>
(PATH_MAX);
if (!cmdline) {
PERROR("malloc cmdline");
goto end;
}
if (!cmdline) {
PERROR("malloc cmdline");
goto end;
}
+
ret = fread(cmdline, 1, PATH_MAX, fp);
if (ret < 0) {
PERROR("fread proc list");
ret = fread(cmdline, 1, PATH_MAX, fp);
if (ret < 0) {
PERROR("fread proc list");
@@
-338,13
+339,8
@@
static void print_events(struct lttng_event *event)
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
- const char * const filter_fmt = " [filter: '%s']";
-
- filter_msg = (char *) malloc(strlen(filter_str) +
- strlen(filter_fmt) + 1);
- if (filter_msg) {
- sprintf(filter_msg, filter_fmt,
- filter_str);
+ if (asprintf(&filter_msg, " [filter: '%s']", filter_str) == -1) {
+ filter_msg = NULL;
}
}
}
}
@@
-1151,14
+1147,8
@@
static int list_session_agent_events(void)
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
- const char * const filter_fmt =
- " [filter: '%s']";
-
- filter_msg = (char *) malloc(strlen(filter_str) +
- strlen(filter_fmt) + 1);
- if (filter_msg) {
- sprintf(filter_msg, filter_fmt,
- filter_str);
+ if (asprintf(&filter_msg, " [filter: '%s']", filter_str) == -1) {
+ filter_msg = NULL;
}
}
}
}
@@
-2281,7
+2271,7
@@
end:
int cmd_list(int argc, const char **argv)
{
int opt, ret = CMD_SUCCESS;
int cmd_list(int argc, const char **argv)
{
int opt, ret = CMD_SUCCESS;
- const char *session_name, *leftover = NULL;
+ const char *
arg_
session_name, *leftover = NULL;
static poptContext pc;
struct lttng_domain domain;
struct lttng_domain *domains = NULL;
static poptContext pc;
struct lttng_domain domain;
struct lttng_domain *domains = NULL;
@@
-2340,8
+2330,8
@@
int cmd_list(int argc, const char **argv)
}
/* Get session name (trailing argument) */
}
/* Get session name (trailing argument) */
- session_name = poptGetArg(pc);
- DBG2("Session name: %s", session_name);
+
arg_
session_name = poptGetArg(pc);
+ DBG2("Session name: %s",
arg_
session_name);
leftover = poptGetArg(pc);
if (leftover) {
leftover = poptGetArg(pc);
if (leftover) {
@@
-2371,14
+2361,14
@@
int cmd_list(int argc, const char **argv)
}
if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
}
if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
- the_handle = lttng_create_handle(session_name, &domain);
+ the_handle = lttng_create_handle(
arg_
session_name, &domain);
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
}
}
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
}
}
- if (session_name == NULL) {
+ if (
arg_
session_name == NULL) {
if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
&& !opt_python) {
ret = list_sessions(NULL);
if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
&& !opt_python) {
ret = list_sessions(NULL);
@@
-2426,19
+2416,19
@@
int cmd_list(int argc, const char **argv)
}
}
/* MI: the ouptut of list_sessions is an unclosed session element */
}
}
/* MI: the ouptut of list_sessions is an unclosed session element */
- ret = list_sessions(session_name);
+ ret = list_sessions(
arg_
session_name);
if (ret) {
goto end;
}
if (ret) {
goto end;
}
- ret = list_rotate_settings(session_name);
+ ret = list_rotate_settings(
arg_
session_name);
if (ret) {
goto end;
}
/* Domain listing */
if (opt_domain) {
if (ret) {
goto end;
}
/* Domain listing */
if (opt_domain) {
- ret = list_domains(session_name);
+ ret = list_domains(
arg_
session_name);
goto end;
}
goto end;
}
@@
-2489,7
+2479,7
@@
int cmd_list(int argc, const char **argv)
int i, nb_domain;
/* We want all domain(s) */
int i, nb_domain;
/* We want all domain(s) */
- nb_domain = lttng_list_domains(session_name, &domains);
+ nb_domain = lttng_list_domains(
arg_
session_name, &domains);
if (nb_domain < 0) {
ret = CMD_ERROR;
ERR("%s", lttng_strerror(nb_domain));
if (nb_domain < 0) {
ret = CMD_ERROR;
ERR("%s", lttng_strerror(nb_domain));
@@
-2544,7
+2534,7
@@
int cmd_list(int argc, const char **argv)
}
the_handle = lttng_create_handle(
}
the_handle = lttng_create_handle(
- session_name, &domains[i]);
+
arg_
session_name, &domains[i]);
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
if (the_handle == NULL) {
ret = CMD_FATAL;
goto end;
This page took
0.027132 seconds
and
4
git commands to generate.