*
* 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/compiler.hpp>
+#include <common/compat/errno.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,
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:
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:
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";
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:
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:
*
* 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;
} else {
return 0;
}
- break; /* Unreached */
+ break; /* Unreached */
default:
return -EINVAL;
}
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;
}
* required size (excluding closing null).
*/
home = utils_get_home_dir();
- if (home == NULL) {
+ if (home == nullptr) {
/* Fallback in /tmp */
home = "/tmp";
}
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
- ret = snprintf(lh->health_sock_path, sizeof(lh->health_sock_path),
- home_str, home);
+ 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;
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;
{
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;
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;
}
error:
free(lh);
- return NULL;
+ return nullptr;
}
void lttng_health_destroy(struct lttng_health *lh)
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;
}
close_error:
- {
- int closeret;
+{
+ int closeret;
- closeret = close(sock);
- LTTNG_ASSERT(!closeret);
- }
+ closeret = close(sock);
+ LTTNG_ASSERT(!closeret);
+}
error:
if (ret >= 0)
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];
}
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);
}