X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fspawn-viewer.cpp;h=0b605a6442a797ad0822e7d034e016d8abd84e5d;hb=f149493493fbd8a3efa4748832c03278c96c38ca;hp=bcbc229a2f2760e83b2fe27fbe34193a50d16910;hpb=a6bc4ca9d659caf016ef932fcd944029737ac57c;p=lttng-tools.git diff --git a/src/common/spawn-viewer.cpp b/src/common/spawn-viewer.cpp index bcbc229a2..0b605a644 100644 --- a/src/common/spawn-viewer.cpp +++ b/src/common/spawn-viewer.cpp @@ -1,9 +1,9 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2014 Mathieu Desnoyers * Copyright (C) 2020 Francis Deslauriers * - * SPDX-License-Identifier: GPL-2.0-only + * SPDX-License-Identifier: LGPL-2.1-only * */ @@ -14,20 +14,10 @@ #include -#include -#include "error.h" -#include "macros.h" -#include "spawn-viewer.h" - - -static const char *babeltrace_bin = CONFIG_BABELTRACE_BIN; -static const char *babeltrace2_bin = CONFIG_BABELTRACE2_BIN; - -/* - * This is needed for each viewer since we are using execvp(). - */ -static const char *babeltrace_opts[] = { "babeltrace" }; -static const char *babeltrace2_opts[] = { "babeltrace2" }; +#include +#include "error.hpp" +#include "macros.hpp" +#include "spawn-viewer.hpp" /* * Type is also use as the index in the viewers array. So please, make sure @@ -39,7 +29,17 @@ enum viewer_type { VIEWER_USER_DEFINED = 2, }; -static const struct viewer { +namespace { +const char *babeltrace_bin = CONFIG_BABELTRACE_BIN; +const char *babeltrace2_bin = CONFIG_BABELTRACE2_BIN; + +/* + * This is needed for each viewer since we are using execvp(). + */ +const char *babeltrace_opts[] = { "babeltrace" }; +const char *babeltrace2_opts[] = { "babeltrace2" }; + +const struct viewer { const char *exec_name; enum viewer_type type; } viewers[] = { @@ -47,6 +47,7 @@ static const struct viewer { { "babeltrace2", VIEWER_BABELTRACE2 }, { NULL, VIEWER_USER_DEFINED }, }; +} /* namespace */ static const struct viewer *parse_viewer_option(const char *opt_viewer) { @@ -85,7 +86,7 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path) } while (*token != '\0'); /* Add two here for the NULL terminating element and trace path */ - argv = (char **) zmalloc(sizeof(char *) * (num_opts + 2)); + argv = calloc(num_opts + 2); if (argv == NULL) { goto error; } @@ -126,7 +127,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len, const char *trace_path, bool opt_live_mode) { char **argv; - size_t size, mem_len; + size_t mem_len; /* Add one for the NULL terminating element. */ mem_len = opts_len + 1; @@ -138,10 +139,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len, mem_len += 1; } - size = sizeof(char *) * mem_len; - - /* Add two here for the trace_path and the NULL terminating element. */ - argv = (char **) zmalloc(size); + argv = calloc(mem_len); if (argv == NULL) { goto error; }