Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / common / fd-tracker / utils.cpp
index be6c65df6aed6e0c836ca7d075342618a46a5687..408c5afc65756fcb92172c16db0b810dcc514cf7 100644 (file)
@@ -1,39 +1,38 @@
 /*
  * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
  */
 
-#include <common/error.h>
-#include <common/fd-tracker/utils.h>
-#include <common/utils.h>
+#include <common/error.hpp>
+#include <common/fd-tracker/utils.hpp>
+#include <common/utils.hpp>
+
 #include <lttng/constant.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-static
-int open_pipe_cloexec(void *data, int *fds)
+static int open_pipe_cloexec(void *data __attribute__((unused)), int *fds)
 {
        return utils_create_pipe_cloexec(fds);
 }
 
-static
-int close_pipe(void *data, int *pipe)
+static int close_pipe(void *data __attribute__((unused)), int *pipe)
 {
        utils_close_pipe(pipe);
        pipe[0] = pipe[1] = -1;
        return 0;
 }
 
-int fd_tracker_util_close_fd(void *unused, int *fd)
+int fd_tracker_util_close_fd(void *unused __attribute__((unused)), int *fd)
 {
        return close(*fd);
 }
 
-int fd_tracker_util_pipe_open_cloexec(
-               struct fd_tracker *tracker, const char *name, int *pipe)
+int fd_tracker_util_pipe_open_cloexec(struct fd_tracker *tracker, const char *name, int *pipe)
 {
        int ret;
        const char *name_prefix;
@@ -49,8 +48,8 @@ int fd_tracker_util_pipe_open_cloexec(
                goto end;
        }
 
-       ret = fd_tracker_open_unsuspendable_fd(tracker, pipe,
-                       (const char **) names, 2, open_pipe_cloexec, NULL);
+       ret = fd_tracker_open_unsuspendable_fd(
+               tracker, pipe, (const char **) names, 2, open_pipe_cloexec, nullptr);
        free(names[0]);
        free(names[1]);
 end:
@@ -59,27 +58,26 @@ end:
 
 int fd_tracker_util_pipe_close(struct fd_tracker *tracker, int *pipe)
 {
-       return fd_tracker_close_unsuspendable_fd(
-                       tracker, pipe, 2, close_pipe, NULL);
+       return fd_tracker_close_unsuspendable_fd(tracker, pipe, 2, close_pipe, nullptr);
 }
 
+namespace {
 struct open_directory_handle_args {
        const struct lttng_directory_handle *in_handle;
        struct lttng_directory_handle *ret_handle;
        const char *path;
 };
+} /* namespace */
 
-static
-int open_directory_handle(void *_args, int *out_fds)
+static int open_directory_handle(void *_args, int *out_fds)
 {
        int ret = 0;
        struct open_directory_handle_args *args = (open_directory_handle_args *) _args;
-       struct lttng_directory_handle *new_handle = NULL;
+       struct lttng_directory_handle *new_handle = nullptr;
 
        new_handle = args->in_handle ?
-                       lttng_directory_handle_create_from_handle(
-                               args->path, args->in_handle) :
-                       lttng_directory_handle_create(args->path);
+               lttng_directory_handle_create_from_handle(args->path, args->in_handle) :
+               lttng_directory_handle_create(args->path);
        if (!new_handle) {
                ret = -errno;
                goto end;
@@ -103,15 +101,13 @@ int open_directory_handle(void *_args, int *out_fds)
 #else
                abort();
 #endif
-
        }
 end:
        return ret;
 }
 
 #ifdef HAVE_DIRFD
-static
-int fd_close(void *unused, int *in_fds)
+static int fd_close(void *unused __attribute__((unused)), int *in_fds)
 {
        const int ret = close(in_fds[0]);
 
@@ -119,13 +115,11 @@ int fd_close(void *unused, int *in_fds)
        return ret;
 }
 
-static
-void directory_handle_destroy(
-               struct lttng_directory_handle *handle, void *data)
+static void directory_handle_destroy(struct lttng_directory_handle *handle, void *data)
 {
        struct fd_tracker *tracker = (fd_tracker *) data;
-       const int ret = fd_tracker_close_unsuspendable_fd(
-                       tracker, &handle->dirfd, 1, fd_close, NULL);
+       const int ret =
+               fd_tracker_close_unsuspendable_fd(tracker, &handle->dirfd, 1, fd_close, nullptr);
 
        if (ret) {
                ERR("Failed to untrack directory handle file descriptor");
@@ -133,24 +127,21 @@ void directory_handle_destroy(
 }
 #endif
 
-struct lttng_directory_handle *fd_tracker_create_directory_handle(
-               struct fd_tracker *tracker, const char *path)
+struct lttng_directory_handle *fd_tracker_create_directory_handle(struct fd_tracker *tracker,
+                                                                 const char *path)
 {
-       return fd_tracker_create_directory_handle_from_handle(
-                       tracker, NULL, path);
+       return fd_tracker_create_directory_handle_from_handle(tracker, nullptr, path);
 }
 
 struct lttng_directory_handle *fd_tracker_create_directory_handle_from_handle(
-               struct fd_tracker *tracker,
-               struct lttng_directory_handle *in_handle,
-               const char *path)
+       struct fd_tracker *tracker, struct lttng_directory_handle *in_handle, const char *path)
 {
        int ret;
        int dirfd = -1;
-       char *handle_name = NULL;
+       char *handle_name = nullptr;
        char cwd_path[LTTNG_PATH_MAX] = "working directory";
-       struct lttng_directory_handle *new_handle = NULL;
-       open_directory_handle_args open_args {};
+       struct lttng_directory_handle *new_handle = nullptr;
+       open_directory_handle_args open_args{};
 
        open_args.in_handle = in_handle;
        open_args.path = path;
@@ -162,18 +153,17 @@ struct lttng_directory_handle *fd_tracker_create_directory_handle_from_handle(
                }
        }
 
-       ret = asprintf(&handle_name, "Directory handle to %s",
-                       path ? path : cwd_path);
+       ret = asprintf(&handle_name, "Directory handle to %s", path ? path : cwd_path);
        if (ret < 0) {
                PERROR("Failed to format directory handle name");
                goto end;
        }
 
-       ret = fd_tracker_open_unsuspendable_fd(tracker, &dirfd,
-                       (const char **) &handle_name, 1, open_directory_handle,
-                       &open_args);
+       ret = fd_tracker_open_unsuspendable_fd(
+               tracker, &dirfd, (const char **) &handle_name, 1, open_directory_handle, &open_args);
        if (ret && ret != ENOTSUP) {
-               ERR("Failed to open directory handle to %s through the fd tracker", path ? path : cwd_path);
+               ERR("Failed to open directory handle to %s through the fd tracker",
+                   path ? path : cwd_path);
        }
        new_handle = open_args.ret_handle;
 
This page took 0.026003 seconds and 4 git commands to generate.