Use compiler-agnostic defines to silence warning
[lttng-tools.git] / src / bin / lttng-sessiond / agent-thread.cpp
index c3d76896cdbf54b0fdf2e55acb44519e6a30af17..9b5a5b569f5bc75245f0093b32e3cb2bb9ae2dcb 100644 (file)
 #include <common/common.hpp>
 #include <common/compat/endian.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/urcu.hpp>
 #include <common/uri.hpp>
 #include <common/utils.hpp>
 
+#include <fcntl.h>
+
 namespace {
 struct thread_notifiers {
        struct lttng_pipe *quit_pipe;
@@ -56,15 +59,13 @@ const char *default_reg_uri = "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS;
  */
 static void update_agent_app(const struct agent_app *app)
 {
-       struct ltt_session *session, *stmp;
        struct ltt_session_list *list;
-       struct agent *trigger_agent;
-       struct lttng_ht_iter iter;
 
        list = session_get_list();
        LTTNG_ASSERT(list);
 
-       cds_list_for_each_entry_safe (session, stmp, &list->head, list) {
+       for (auto *session :
+            lttng::urcu::list_iteration_adapter<ltt_session, &ltt_session::list>(list->head)) {
                if (!session_get(session)) {
                        continue;
                }
@@ -73,37 +74,35 @@ static void update_agent_app(const struct agent_app *app)
                if (session->ust_session) {
                        const struct agent *agt;
 
-                       rcu_read_lock();
+                       const lttng::urcu::read_lock_guard read_lock;
                        agt = trace_ust_find_agent(session->ust_session, app->domain);
                        if (agt) {
                                agent_update(agt, app);
                        }
-                       rcu_read_unlock();
                }
                session_unlock(session);
                session_put(session);
        }
 
-       rcu_read_lock();
        /*
         * We are protected against the addition of new events by the session
         * list lock being held.
         */
-       cds_lfht_for_each_entry (
-               the_trigger_agents_ht_by_domain->ht, &iter.iter, trigger_agent, node.node) {
+       for (auto *trigger_agent :
+            lttng::urcu::lfht_iteration_adapter<agent, decltype(agent::node), &agent::node>(
+                    *the_trigger_agents_ht_by_domain->ht)) {
                agent_update(trigger_agent, app);
        }
-       rcu_read_unlock();
 }
 
 /*
  * Create and init socket from uri.
  */
-static struct lttcomm_sock *init_tcp_socket(void)
+static struct lttcomm_sock *init_tcp_socket()
 {
        int ret;
-       struct lttng_uri *uri = NULL;
-       struct lttcomm_sock *sock = NULL;
+       struct lttng_uri *uri = nullptr;
+       struct lttcomm_sock *sock = nullptr;
        unsigned int port;
        bool bind_succeeded = false;
 
@@ -118,7 +117,7 @@ static struct lttcomm_sock *init_tcp_socket(void)
 
        sock = lttcomm_alloc_sock_from_uri(uri);
        uri_free(uri);
-       if (sock == NULL) {
+       if (sock == nullptr) {
                ERR("agent allocating TCP socket");
                goto error;
        }
@@ -178,7 +177,7 @@ error:
        if (sock) {
                lttcomm_destroy_sock(sock);
        }
-       return NULL;
+       return nullptr;
 }
 
 /*
@@ -217,6 +216,8 @@ static const char *domain_type_str(enum lttng_domain_type domain_type)
                return "jul";
        case LTTNG_DOMAIN_LOG4J:
                return "log4j";
+       case LTTNG_DOMAIN_LOG4J2:
+               return "log4j2";
        case LTTNG_DOMAIN_PYTHON:
                return "python";
        default:
@@ -302,7 +303,7 @@ static int accept_agent_connection(struct lttcomm_sock *reg_sock,
             new_sock->fd);
 
        *agent_app_socket = new_sock;
-       new_sock = NULL;
+       new_sock = nullptr;
        ret = 0;
        goto end;
 
@@ -313,7 +314,7 @@ end:
        return ret;
 }
 
-bool agent_tracing_is_enabled(void)
+bool agent_tracing_is_enabled()
 {
        int enabled;
 
@@ -407,7 +408,7 @@ static void *thread_agent_management(void *data)
                goto error;
        }
 
-       while (1) {
+       while (true) {
                DBG3("Manage agent polling");
 
                /* Inifinite blocking call, waiting for transmission */
@@ -440,7 +441,7 @@ static void *thread_agent_management(void *data)
                        /* Activity on the registration socket. */
                        if (revents & LPOLLIN) {
                                struct agent_app_id new_app_id;
-                               struct agent_app *new_app = NULL;
+                               struct agent_app *new_app = nullptr;
                                struct lttcomm_sock *new_app_socket;
                                int new_app_socket_fd;
 
@@ -464,7 +465,7 @@ static void *thread_agent_management(void *data)
                                        continue;
                                }
                                new_app_socket_fd = new_app_socket->fd;
-                               new_app_socket = NULL;
+                               new_app_socket = nullptr;
 
                                /*
                                 * Since this is a command socket (write then
@@ -482,7 +483,7 @@ static void *thread_agent_management(void *data)
                                 * the agent application's configuration is
                                 * updated.
                                 */
-                               session_lock_list();
+                               const auto list_lock = lttng::sessiond::lock_session_list();
 
                                /*
                                 * Update the newly registered applications's
@@ -496,7 +497,6 @@ static void *thread_agent_management(void *data)
                                        /* Removing from the poll set. */
                                        ret = lttng_poll_del(&events, new_app_socket_fd);
                                        if (ret < 0) {
-                                               session_unlock_list();
                                                goto error;
                                        }
                                        continue;
@@ -504,8 +504,6 @@ static void *thread_agent_management(void *data)
 
                                /* Publish the new agent app. */
                                agent_add_app(new_app);
-
-                               session_unlock_list();
                        } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
                                /* Removing from the poll set */
                                ret = lttng_poll_del(&events, pollfd);
@@ -532,7 +530,7 @@ error_poll_create:
        DBG("Cleaning up and stopping.");
        rcu_thread_offline();
        rcu_unregister_thread();
-       return NULL;
+       return nullptr;
 }
 
 static bool shutdown_agent_management_thread(void *data)
@@ -552,7 +550,7 @@ static void cleanup_agent_management_thread(void *data)
        free(notifiers);
 }
 
-bool launch_agent_management_thread(void)
+bool launch_agent_management_thread()
 {
        struct thread_notifiers *notifiers;
        struct lttng_thread *thread;
This page took 0.02721 seconds and 4 git commands to generate.