Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl-health.cpp
index 2a992830d5a41209cb99c162b71c6d2a4e38f57c..c490f8993c0c1ca55b31613dbad82d1142bce47b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Linux Trace Toolkit Health Control Library
  *
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * SPDX-License-Identifier: LGPL-2.1-only
  */
 
 #define _LGPL_SOURCE
-#include <unistd.h>
-#include <sys/types.h>
-#include <stdint.h>
-#include <limits.h>
-#include <string.h>
-#include <lttng/health-internal.h>
+#include "lttng-ctl-helper.hpp"
 
-#include <bin/lttng-sessiond/health-sessiond.h>
-#include <bin/lttng-consumerd/health-consumerd.h>
-#include <bin/lttng-relayd/health-relayd.h>
-#include <common/defaults.h>
-#include <common/utils.h>
-#include <common/compat/errno.h>
+#include <common/compat/errno.hpp>
+#include <common/compiler.hpp>
+#include <common/defaults.hpp>
+#include <common/utils.hpp>
 
-#include "lttng-ctl-helper.h"
+#include <lttng/health-internal.hpp>
+
+#include <bin/lttng-consumerd/health-consumerd.hpp>
+#include <bin/lttng-relayd/health-relayd.hpp>
+#include <bin/lttng-sessiond/health-sessiond.hpp>
+#include <limits.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 enum health_component {
        HEALTH_COMPONENT_SESSIOND,
@@ -47,13 +49,12 @@ struct lttng_health {
        char health_sock_path[PATH_MAX];
        /* For consumer health only */
        enum lttng_health_consumerd consumerd_type;
-       struct lttng_health_thread thread[];
+       struct lttng_health_thread thread[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 };
 
-static
-const char *get_sessiond_thread_name(health_type_sessiond type) {
-       switch (type)
-       {
+static const char *get_sessiond_thread_name(health_type_sessiond type)
+{
+       switch (type) {
        case HEALTH_SESSIOND_TYPE_CMD:
                return "Session daemon command";
        case HEALTH_SESSIOND_TYPE_APP_MANAGE:
@@ -64,8 +65,6 @@ const char *get_sessiond_thread_name(health_type_sessiond type) {
                return "Session daemon kernel";
        case HEALTH_SESSIOND_TYPE_CONSUMER:
                return "Session daemon consumer manager";
-       case HEALTH_SESSIOND_TYPE_HT_CLEANUP:
-               return "Session daemon hash table cleanup";
        case HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY:
                return "Session daemon application notification manager";
        case HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH:
@@ -85,8 +84,8 @@ const char *get_sessiond_thread_name(health_type_sessiond type) {
        abort();
 };
 
-static
-const char *get_consumerd_thread_name(health_type_consumerd type) {
+static const char *get_consumerd_thread_name(health_type_consumerd type)
+{
        switch (type) {
        case HEALTH_CONSUMERD_TYPE_CHANNEL:
                return "Consumer daemon channel";
@@ -105,8 +104,7 @@ const char *get_consumerd_thread_name(health_type_consumerd type) {
        abort();
 };
 
-static
-const char *get_relayd_thread_name(health_type_relayd type)
+static const char *get_relayd_thread_name(health_type_relayd type)
 {
        switch (type) {
        case HEALTH_RELAYD_TYPE_DISPATCHER:
@@ -128,8 +126,7 @@ const char *get_relayd_thread_name(health_type_relayd type)
        abort();
 }
 
-static
-const char *get_thread_name(int comp, int nr)
+static const char *get_thread_name(int comp, int nr)
 {
        switch (comp) {
        case HEALTH_COMPONENT_SESSIOND:
@@ -150,9 +147,7 @@ const char *get_thread_name(int comp, int nr)
  *
  * Returns 0 on success or a negative errno.
  */
-static
-int set_health_socket_path(struct lttng_health *lh,
-               int tracing_group)
+static int set_health_socket_path(struct lttng_health *lh, int tracing_group)
 {
        uid_t uid;
        const char *home;
@@ -189,7 +184,7 @@ int set_health_socket_path(struct lttng_health *lh,
                } else {
                        return 0;
                }
-               break;  /* Unreached */
+               break; /* Unreached */
        default:
                return -EINVAL;
        }
@@ -197,9 +192,7 @@ int set_health_socket_path(struct lttng_health *lh,
        uid = getuid();
 
        if (uid == 0 || tracing_group) {
-               ret = lttng_strncpy(lh->health_sock_path,
-                               global_str,
-                               sizeof(lh->health_sock_path));
+               ret = lttng_strncpy(lh->health_sock_path, global_str, sizeof(lh->health_sock_path));
                return ret == 0 ? 0 : -EINVAL;
        }
 
@@ -209,13 +202,15 @@ int set_health_socket_path(struct lttng_health *lh,
         * required size (excluding closing null).
         */
        home = utils_get_home_dir();
-       if (home == NULL) {
+       if (home == nullptr) {
                /* Fallback in /tmp */
                home = "/tmp";
        }
 
-       ret = snprintf(lh->health_sock_path, sizeof(lh->health_sock_path),
-                       home_str, home);
+       DIAGNOSTIC_PUSH
+       DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
+       ret = snprintf(lh->health_sock_path, sizeof(lh->health_sock_path), home_str, home);
+       DIAGNOSTIC_POP
        if ((ret < 0) || (ret >= sizeof(lh->health_sock_path))) {
                return -ENOMEM;
        }
@@ -223,20 +218,18 @@ int set_health_socket_path(struct lttng_health *lh,
        return 0;
 }
 
-static
-struct lttng_health *lttng_health_create(enum health_component hc,
-               unsigned int nr_threads)
+static struct lttng_health *lttng_health_create(enum health_component hc, unsigned int nr_threads)
 {
        struct lttng_health *lh;
        int i;
 
-       lh = (lttng_health *) zmalloc(sizeof(*lh) + sizeof(lh->thread[0]) * nr_threads);
+       lh = zmalloc<lttng_health>(sizeof(*lh) + sizeof(lh->thread[0]) * nr_threads);
        if (!lh) {
-               return NULL;
+               return nullptr;
        }
 
        lh->component = hc;
-       lh->state = UINT64_MAX;         /* All bits in error initially */
+       lh->state = UINT64_MAX; /* All bits in error initially */
        lh->nr_threads = nr_threads;
        for (i = 0; i < nr_threads; i++) {
                lh->thread[i].p = lh;
@@ -248,23 +241,20 @@ struct lttng_health *lttng_health_create_sessiond(void)
 {
        struct lttng_health *lh;
 
-       lh = lttng_health_create(HEALTH_COMPONENT_SESSIOND,
-                       NR_HEALTH_SESSIOND_TYPES);
+       lh = lttng_health_create(HEALTH_COMPONENT_SESSIOND, NR_HEALTH_SESSIOND_TYPES);
        if (!lh) {
-               return NULL;
+               return nullptr;
        }
        return lh;
 }
 
-struct lttng_health *
-       lttng_health_create_consumerd(enum lttng_health_consumerd consumerd)
+struct lttng_health *lttng_health_create_consumerd(enum lttng_health_consumerd consumerd)
 {
        struct lttng_health *lh;
 
-       lh = lttng_health_create(HEALTH_COMPONENT_CONSUMERD,
-                       NR_HEALTH_CONSUMERD_TYPES);
+       lh = lttng_health_create(HEALTH_COMPONENT_CONSUMERD, NR_HEALTH_CONSUMERD_TYPES);
        if (!lh) {
-               return NULL;
+               return nullptr;
        }
        lh->consumerd_type = consumerd;
        return lh;
@@ -273,20 +263,18 @@ struct lttng_health *
 struct lttng_health *lttng_health_create_relayd(const char *path)
 {
        int ret;
-       struct lttng_health *lh = NULL;
+       struct lttng_health *lh = nullptr;
 
        if (!path) {
                goto error;
        }
 
-       lh = lttng_health_create(HEALTH_COMPONENT_RELAYD,
-                       NR_HEALTH_RELAYD_TYPES);
+       lh = lttng_health_create(HEALTH_COMPONENT_RELAYD, NR_HEALTH_RELAYD_TYPES);
        if (!lh) {
                goto error;
        }
 
-       ret = lttng_strncpy(lh->health_sock_path, path,
-                       sizeof(lh->health_sock_path));
+       ret = lttng_strncpy(lh->health_sock_path, path, sizeof(lh->health_sock_path));
        if (ret) {
                goto error;
        }
@@ -295,7 +283,7 @@ struct lttng_health *lttng_health_create_relayd(const char *path)
 
 error:
        free(lh);
-       return NULL;
+       return nullptr;
 }
 
 void lttng_health_destroy(struct lttng_health *lh)
@@ -334,13 +322,13 @@ retry:
        memset(&msg, 0, sizeof(msg));
        msg.cmd = HEALTH_CMD_CHECK;
 
-       ret = lttcomm_send_unix_sock(sock, (void *)&msg, sizeof(msg));
+       ret = lttcomm_send_unix_sock(sock, (void *) &msg, sizeof(msg));
        if (ret < 0) {
                ret = -1;
                goto close_error;
        }
 
-       ret = lttcomm_recv_unix_sock(sock, (void *)&reply, sizeof(reply));
+       ret = lttcomm_recv_unix_sock(sock, (void *) &reply, sizeof(reply));
        if (ret < 0) {
                ret = -1;
                goto close_error;
@@ -356,12 +344,12 @@ retry:
        }
 
 close_error:
-       {
-               int closeret;
+{
+       int closeret;
 
-               closeret = close(sock);
-               LTTNG_ASSERT(!closeret);
-       }
+       closeret = close(sock);
+       LTTNG_ASSERT(!closeret);
+}
 
 error:
        if (ret >= 0)
@@ -390,12 +378,11 @@ int lttng_health_get_nr_threads(const struct lttng_health *health)
        return health->nr_threads;
 }
 
-const struct lttng_health_thread *
-       lttng_health_get_thread(const struct lttng_health *health,
-               unsigned int nth_thread)
+const struct lttng_health_thread *lttng_health_get_thread(const struct lttng_health *health,
+                                                         unsigned int nth_thread)
 {
        if (!health || nth_thread >= health->nr_threads) {
-               return NULL;
+               return nullptr;
        }
        return &health->thread[nth_thread];
 }
@@ -413,8 +400,8 @@ const char *lttng_health_thread_name(const struct lttng_health_thread *thread)
        unsigned int nr;
 
        if (!thread) {
-               return NULL;
+               return nullptr;
        }
        nr = thread - &thread->p->thread[0];
-       return get_thread_name (thread->p->component, nr);
+       return get_thread_name(thread->p->component, nr);
 }
This page took 0.026834 seconds and 4 git commands to generate.