X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-consumerd%2Fhealth-consumerd.c;h=60808f37094d304480468875c5cde6b944599c9c;hp=062e46b9343adda4da3d1edf9a5453eee465535f;hb=6c71277b0dc97ce8a4ac6b8d359b4b349c04b658;hpb=d74df4226a1b4461c896d51a221afe38e07809a7 diff --git a/src/bin/lttng-consumerd/health-consumerd.c b/src/bin/lttng-consumerd/health-consumerd.c index 062e46b93..60808f370 100644 --- a/src/bin/lttng-consumerd/health-consumerd.c +++ b/src/bin/lttng-consumerd/health-consumerd.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,7 @@ void *thread_manage_health(void *data) struct lttng_poll_event events; struct health_comm_msg msg; struct health_comm_reply reply; + int is_root; DBG("[thread] Manage health check started"); @@ -193,6 +195,28 @@ void *thread_manage_health(void *data) goto error; } + is_root = !getuid(); + if (is_root) { + /* lttng health client socket path permissions */ + ret = chown(health_unix_sock_path, 0, + utils_get_group_id(tracing_group_name)); + if (ret < 0) { + ERR("Unable to set group on %s", health_unix_sock_path); + PERROR("chown"); + ret = -1; + goto error; + } + + ret = chmod(health_unix_sock_path, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + if (ret < 0) { + ERR("Unable to set permissions on %s", health_unix_sock_path); + PERROR("chmod"); + ret = -1; + goto error; + } + } + /* * Set the CLOEXEC flag. Return code is useless because either way, the * show must go on. @@ -288,47 +312,18 @@ restart: assert(msg.cmd == HEALTH_CMD_CHECK); - switch (msg.component) { - case LTTNG_HEALTH_CONSUMERD_CHANNEL: - reply.ret_code = health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_CHANNEL); - break; - case LTTNG_HEALTH_CONSUMERD_METADATA: - reply.ret_code = health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_METADATA); - break; - case LTTNG_HEALTH_CONSUMERD_DATA: - reply.ret_code = health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_DATA); - break; - case LTTNG_HEALTH_CONSUMERD_SESSIOND: - reply.ret_code = health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_SESSIOND); - break; - case LTTNG_HEALTH_CONSUMERD_METADATA_TIMER: - reply.ret_code = health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_METADATA_TIMER); - break; - - case LTTNG_HEALTH_CONSUMERD_ALL: - reply.ret_code = - health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_CHANNEL) && - health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_METADATA) && - health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_DATA) && - health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_SESSIOND) && - health_check_state(health_consumerd, HEALTH_CONSUMERD_TYPE_METADATA_TIMER); - break; - default: - reply.ret_code = LTTNG_ERR_UND; - break; - } - - /* - * Flip ret value since 0 is a success and 1 indicates a bad health for - * the client where in the sessiond it is the opposite. Again, this is - * just to make things easier for us poor developer which enjoy a lot - * lazyness. - */ - if (reply.ret_code == 0 || reply.ret_code == 1) { - reply.ret_code = !reply.ret_code; + reply.ret_code = 0; + for (i = 0; i < NR_HEALTH_CONSUMERD_TYPES; i++) { + /* + * health_check_state return 0 if thread is in + * error. + */ + if (!health_check_state(health_consumerd, i)) { + reply.ret_code |= 1ULL << i; + } } - DBG2("Health check return value %d", reply.ret_code); + DBG2("Health check return value %" PRIx64, reply.ret_code); ret = send_unix_sock(new_sock, (void *) &reply, sizeof(reply)); if (ret < 0) {