Run clang-format on the whole tree
[lttng-tools.git] / src / common / spawn-viewer.cpp
index bcbc229a2f2760e83b2fe27fbe34193a50d16910..e3aeb8314858badb81ab71684489025e481d6475 100644 (file)
@@ -1,45 +1,46 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
  *
- * SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
  */
 
+#include "error.hpp"
+#include "macros.hpp"
+#include "spawn-viewer.hpp"
+
+#include <common/compat/errno.hpp>
+
+#include <lttng/constant.h>
+
 #include <stdbool.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <lttng/constant.h>
-
-#include <common/compat/errno.h>
-#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" };
-
 /*
  * Type is also use as the index in the viewers array. So please, make sure
  * your enum value is in the right order in the array below.
  */
 enum viewer_type {
-       VIEWER_BABELTRACE    = 0,
-       VIEWER_BABELTRACE2   = 1,
-       VIEWER_USER_DEFINED  = 2,
+       VIEWER_BABELTRACE = 0,
+       VIEWER_BABELTRACE2 = 1,
+       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 +48,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 +87,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<char *>(num_opts + 2);
        if (argv == NULL) {
                goto error;
        }
@@ -122,11 +124,13 @@ error:
  *
  * The returning pointer is ready to be passed to execvp().
  */
-static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len,
-               const char *trace_path, bool opt_live_mode)
+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 +142,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<char *>(mem_len);
        if (argv == NULL) {
                goto error;
        }
@@ -162,7 +163,6 @@ error:
        return argv;
 }
 
-
 /*
  * Spawn viewer with the trace directory path.
  */
@@ -189,9 +189,8 @@ retry_viewer:
                } else {
                        viewer_bin = viewer->exec_name;
                }
-               argv = alloc_argv_from_local_opts(babeltrace2_opts,
-                               ARRAY_SIZE(babeltrace2_opts), trace_path,
-                               opt_live_mode);
+               argv = alloc_argv_from_local_opts(
+                       babeltrace2_opts, ARRAY_SIZE(babeltrace2_opts), trace_path, opt_live_mode);
                break;
        case VIEWER_BABELTRACE:
                if (stat(babeltrace_bin, &status) == 0) {
@@ -199,9 +198,8 @@ retry_viewer:
                } else {
                        viewer_bin = viewer->exec_name;
                }
-               argv = alloc_argv_from_local_opts(babeltrace_opts,
-                               ARRAY_SIZE(babeltrace_opts), trace_path,
-                               opt_live_mode);
+               argv = alloc_argv_from_local_opts(
+                       babeltrace_opts, ARRAY_SIZE(babeltrace_opts), trace_path, opt_live_mode);
                break;
        case VIEWER_USER_DEFINED:
                argv = alloc_argv_from_user_opts(opt_viewer, trace_path);
@@ -226,16 +224,16 @@ retry_viewer:
                        if (viewer->type == VIEWER_BABELTRACE2) {
                                /* Fallback to legacy babeltrace. */
                                DBG("Default viewer \"%s\" not installed on the system, falling back to \"%s\"",
-                                               viewers[VIEWER_BABELTRACE2].exec_name,
-                                               viewers[VIEWER_BABELTRACE].exec_name);
+                                   viewers[VIEWER_BABELTRACE2].exec_name,
+                                   viewers[VIEWER_BABELTRACE].exec_name);
                                viewer = &viewers[VIEWER_BABELTRACE];
                                free(argv);
                                argv = NULL;
                                goto retry_viewer;
                        } else {
                                ERR("Default viewer \"%s\" (and fallback \"%s\") not found on the system",
-                                               viewers[VIEWER_BABELTRACE2].exec_name,
-                                               viewers[VIEWER_BABELTRACE].exec_name);
+                                   viewers[VIEWER_BABELTRACE2].exec_name,
+                                   viewers[VIEWER_BABELTRACE].exec_name);
                        }
                } else {
                        PERROR("Failed to launch \"%s\" viewer", viewer_bin);
This page took 0.026924 seconds and 4 git commands to generate.