Fix: sessiond: fix memory leak in receive_lttng_trigger
[lttng-tools.git] / src / bin / lttng-sessiond / health.c
index e8c42e4bd7fa6f2b8b7394e9af43461be4b26fb4..7fc557da5f8d28164af0cc9129d89768bda9949f 100644 (file)
@@ -1,19 +1,9 @@
 /*
- * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
- * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "lttng-sessiond.h"
@@ -87,7 +77,7 @@ static void *thread_manage_health(void *data)
        }
 
        /* Create unix socket */
-       sock = lttcomm_create_unix_sock(config.health_unix_sock_path.value);
+       sock = lttcomm_create_unix_sock(the_config.health_unix_sock_path.value);
        if (sock < 0) {
                ERR("Unable to create health check Unix socket");
                goto error;
@@ -95,18 +85,25 @@ static void *thread_manage_health(void *data)
 
        if (is_root) {
                /* lttng health client socket path permissions */
-               ret = chown(config.health_unix_sock_path.value, 0,
-                               utils_get_group_id(config.tracing_group_name.value));
+               gid_t gid;
+
+               ret = utils_get_group_id(the_config.tracing_group_name.value, true, &gid);
+               if (ret) {
+                       /* Default to root group. */
+                       gid = 0;
+               }
+
+               ret = chown(the_config.health_unix_sock_path.value, 0, gid);
                if (ret < 0) {
-                       ERR("Unable to set group on %s", config.health_unix_sock_path.value);
+                       ERR("Unable to set group on %s", the_config.health_unix_sock_path.value);
                        PERROR("chown");
                        goto error;
                }
 
-               ret = chmod(config.health_unix_sock_path.value,
+               ret = chmod(the_config.health_unix_sock_path.value,
                                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
                if (ret < 0) {
-                       ERR("Unable to set permissions on %s", config.health_unix_sock_path.value);
+                       ERR("Unable to set permissions on %s", the_config.health_unix_sock_path.value);
                        PERROR("chmod");
                        goto error;
                }
@@ -158,11 +155,6 @@ restart:
                        revents = LTTNG_POLL_GETEV(&events, i);
                        pollfd = LTTNG_POLL_GETFD(&events, i);
 
-                       if (!revents) {
-                               /* No activity for this FD (poll implementation). */
-                               continue;
-                       }
-
                        /* Event on the registration socket */
                        if (pollfd == sock) {
                                if (revents & LPOLLIN) {
@@ -211,7 +203,7 @@ restart:
                         * health_check_state returns 0 if health is
                         * bad.
                         */
-                       if (!health_check_state(health_sessiond, i)) {
+                       if (!health_check_state(the_health_sessiond, i)) {
                                reply.ret_code |= 1ULL << i;
                        }
                }
@@ -237,7 +229,7 @@ error:
                ERR("Health error occurred in %s", __func__);
        }
        DBG("Health check thread dying");
-       unlink(config.health_unix_sock_path.value);
+       unlink(the_config.health_unix_sock_path.value);
        if (sock >= 0) {
                ret = close(sock);
                if (ret) {
@@ -265,7 +257,7 @@ bool launch_health_management_thread(void)
 
        notifiers = zmalloc(sizeof(*notifiers));
        if (!notifiers) {
-               goto error;
+               goto error_alloc;
        }
 
        sem_init(&notifiers->ready, 0, 0);
@@ -287,5 +279,6 @@ bool launch_health_management_thread(void)
        return true;
 error:
        cleanup_health_management_thread(notifiers);
+error_alloc:
        return false;
 }
This page took 0.025229 seconds and 4 git commands to generate.