Clean-up: move global sessiond symbols out of main.o
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Nov 2018 20:32:24 +0000 (15:32 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 16 Nov 2018 18:49:51 +0000 (13:49 -0500)
The global symbols defined in main.c prevent the use of numerous
functions from various other files. For instance, using timer.h
utils from session.o forces the redefinition of symbols that
are defined in main.o in the session unit tests.

This is a problem that has often occured in the past, more or less
forcing the unit tests to link against all sessiond objects. Moving
the global symbols to their own files (thread-utils.c,
process-utils.c, globals.c, and ready.c) does not solve this problem,
but it allows the unit tests to link against their resulting
objects and forego the stub-ing of symbols.

In the future, we could consider moving most the session daemon
to an internal library which could be re-used by the unit tests.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 files changed:
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/globals.c [new file with mode: 0644]
src/bin/lttng-sessiond/lttng-sessiond.h
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/process-utils.c [new file with mode: 0644]
src/bin/lttng-sessiond/ready.c [new file with mode: 0644]
src/bin/lttng-sessiond/rotation-thread.c
src/bin/lttng-sessiond/rotation-thread.h
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/thread-utils.c [new file with mode: 0644]
tests/regression/tools/live/Makefile.am
tests/regression/tools/live/live_test.c
tests/unit/Makefile.am

index 2e4b95dcef0beb5334f130fe20e9134854d02e01..cfcdc5e86188dc34702af07973059b3dee8b41cc 100644 (file)
@@ -39,7 +39,11 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        sessiond-config.h sessiond-config.c \
                        rotate.h rotate.c \
                        rotation-thread.h rotation-thread.c \
-                       timer.c timer.h
+                       timer.c timer.h \
+                       ready.c \
+                       globals.c \
+                       thread-utils.c \
+                       process-utils.c
 
 if HAVE_LIBLTTNG_UST_CTL
 lttng_sessiond_SOURCES += trace-ust.c ust-registry.c ust-app.c \
diff --git a/src/bin/lttng-sessiond/globals.c b/src/bin/lttng-sessiond/globals.c
new file mode 100644 (file)
index 0000000..fe92474
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *               2013 - 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.
+ *
+ * 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"
+
+int ust_consumerd64_fd = -1;
+int ust_consumerd32_fd = -1;
+
+long page_size;
+
+struct health_app *health_sessiond;
+
+struct notification_thread_handle *notification_thread_handle;
+
+struct lttng_ht *agent_apps_ht_by_sock = NULL;
+
+int kernel_tracer_fd = -1;
+
+int apps_cmd_notify_pipe[2] = { -1, -1 };
+
+pid_t ppid;
+pid_t child_ppid;
+
+struct sessiond_config config;
index 25e410b25c67fce9d42d80406b382877f4d2ae07..f0bd98781987b96f12b185b4a5cc78037183f09d 100644 (file)
@@ -39,6 +39,7 @@ extern const char default_home_dir[],
 /* Set in main.c at boot time of the daemon */
 extern int kernel_tracer_fd;
 
+/* Notification thread handle. */
 extern struct notification_thread_handle *notification_thread_handle;
 
 /*
@@ -105,23 +106,30 @@ extern int ht_cleanup_pipe[2];
 
 /*
  * Populated when the daemon starts with the current page size of the system.
+ * Set in main() with the current page size.
  */
 extern long page_size;
 
 /* Application health monitoring */
 extern struct health_app *health_sessiond;
 
-/*
- * Section name to look for in the daemon configuration file.
- */
-extern const char * const config_section_name;
+extern struct sessiond_config config;
 
-/* Is this daemon root or not. */
-extern int is_root;
+extern int lttng_sessiond_ready;
 
-extern struct sessiond_config config;
+extern int ust_consumerd64_fd, ust_consumerd32_fd;
+
+/* Parent PID for --sig-parent option */
+extern pid_t ppid;
+/* Internal parent PID use with daemonize. */
+extern pid_t child_ppid;
 
+int sessiond_init_thread_quit_pipe(void);
 int sessiond_check_thread_quit_pipe(int fd, uint32_t events);
+int sessiond_wait_for_quit_pipe(unsigned int timeout_us);
+int sessiond_notify_quit_pipe(void);
+void sessiond_close_quit_pipe(void);
+
 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
 void sessiond_notify_ready(void);
 void sessiond_signal_parents(void);
index 67d990027f523079e3ae5635f5ec605573bc9c20..7a0cdb81c83ac0c451341aa41ed29c57d4d3cb77 100644 (file)
@@ -92,8 +92,6 @@ NULL
 ;
 
 const char *progname;
-static pid_t ppid;          /* Parent PID for --sig-parent option */
-static pid_t child_ppid;    /* Internal parent PID use with daemonize. */
 static int lockfile_fd = -1;
 
 /* Set to 1 when a SIGUSR1 signal is received. */
@@ -170,8 +168,6 @@ static const struct option long_options[] = {
        { NULL, 0, 0, 0 }
 };
 
-struct sessiond_config config;
-
 /* Command line options to ignore from configuration file */
 static const char *config_ignore_options[] = { "help", "version", "config" };
 
@@ -181,23 +177,14 @@ static int dispatch_thread_exit;
 /* Sockets and FDs */
 static int client_sock = -1;
 static int apps_sock = -1;
-int kernel_tracer_fd = -1;
 static int kernel_poll_pipe[2] = { -1, -1 };
 
-/*
- * Quit pipe for all threads. This permits a single cancellation point
- * for all threads when receiving an event on the pipe.
- */
-static int thread_quit_pipe[2] = { -1, -1 };
-
 /*
  * This pipe is used to inform the thread managing application communication
  * that a command is queued and ready to be processed.
  */
 static int apps_cmd_pipe[2] = { -1, -1 };
 
-int apps_cmd_notify_pipe[2] = { -1, -1 };
-
 /* Pthread, Mutexes and Semaphores */
 static pthread_t apps_thread;
 static pthread_t apps_notify_thread;
@@ -236,9 +223,6 @@ static struct ust_cmd_queue ust_cmd_queue;
  */
 static struct ltt_session_list *session_list_ptr;
 
-int ust_consumerd64_fd = -1;
-int ust_consumerd32_fd = -1;
-
 static const char *module_proc_lttng = "/proc/lttng";
 
 /*
@@ -275,178 +259,19 @@ enum consumerd_state {
 static enum consumerd_state ust_consumerd_state;
 static enum consumerd_state kernel_consumerd_state;
 
-/* Set in main() with the current page size. */
-long page_size;
-
-/* Application health monitoring */
-struct health_app *health_sessiond;
-
-/* Am I root or not. */
-int is_root;                   /* Set to 1 if the daemon is running as root */
-
-const char * const config_section_name = "sessiond";
-
 /* Load session thread information to operate. */
-struct load_session_thread_data *load_info;
-
-/* Notification thread handle. */
-struct notification_thread_handle *notification_thread_handle;
-
-/* Rotation thread handle. */
-struct rotation_thread_handle *rotation_thread_handle;
-
-/* Global hash tables */
-struct lttng_ht *agent_apps_ht_by_sock = NULL;
+static struct load_session_thread_data *load_info;
 
 /*
- * The initialization of the session daemon is done in multiple phases.
- *
- * While all threads are launched near-simultaneously, only some of them
- * are needed to ensure the session daemon can start to respond to client
- * requests.
- *
- * There are two important guarantees that we wish to offer with respect
- * to the initialisation of the session daemon:
- *   - When the daemonize/background launcher process exits, the sessiond
- *     is fully able to respond to client requests,
- *   - Auto-loaded sessions are visible to clients.
- *
- * In order to achieve this, a number of support threads have to be launched
- * to allow the "client" thread to function properly. Moreover, since the
- * "load session" thread needs the client thread, we must provide a way
- * for the "load session" thread to know that the "client" thread is up
- * and running.
- *
- * Hence, the support threads decrement the lttng_sessiond_ready counter
- * while the "client" threads waits for it to reach 0. Once the "client" thread
- * unblocks, it posts the message_thread_ready semaphore which allows the
- * "load session" thread to progress.
- *
- * This implies that the "load session" thread is the last to be initialized
- * and will explicitly call sessiond_signal_parents(), which signals the parents
- * that the session daemon is fully initialized.
- *
- * The four (4) support threads are:
- *  - agent_thread
- *  - notification_thread
- *  - rotation_thread
- *  - health_thread
+ * Section name to look for in the daemon configuration file.
  */
-#define NR_LTTNG_SESSIOND_SUPPORT_THREADS 4
-int lttng_sessiond_ready = NR_LTTNG_SESSIOND_SUPPORT_THREADS;
-
-int sessiond_check_thread_quit_pipe(int fd, uint32_t events)
-{
-       return (fd == thread_quit_pipe[0] && (events & LPOLLIN)) ? 1 : 0;
-}
+static const char * const config_section_name = "sessiond";
 
-/* Notify parents that we are ready for cmd and health check */
-LTTNG_HIDDEN
-void sessiond_signal_parents(void)
-{
-       /*
-        * Notify parent pid that we are ready to accept command
-        * for client side.  This ppid is the one from the
-        * external process that spawned us.
-        */
-       if (config.sig_parent) {
-               kill(ppid, SIGUSR1);
-       }
-
-       /*
-        * Notify the parent of the fork() process that we are
-        * ready.
-        */
-       if (config.daemonize || config.background) {
-               kill(child_ppid, SIGUSR1);
-       }
-}
-
-LTTNG_HIDDEN
-void sessiond_notify_ready(void)
-{
-       /*
-        * This memory barrier is paired with the one performed by
-        * the client thread after it has seen that 'lttng_sessiond_ready' is 0.
-        *
-        * The purpose of these memory barriers is to ensure that all
-        * initialization operations of the various threads that call this
-        * function to signal that they are ready are commited/published
-        * before the client thread can see the 'lttng_sessiond_ready' counter
-        * reach 0.
-        *
-        * Note that this could be a 'write' memory barrier, but a full barrier
-        * is used in case the code using this utility changes. The performance
-        * implications of this choice are minimal since this is a slow path.
-        */
-       cmm_smp_mb();
-       uatomic_sub(&lttng_sessiond_ready, 1);
-}
-
-static
-int __sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size,
-               int *a_pipe)
-{
-       int ret;
+/* Am I root or not. Set to 1 if the daemon is running as root */
+static int is_root;
 
-       assert(events);
-
-       ret = lttng_poll_create(events, size, LTTNG_CLOEXEC);
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Add quit pipe */
-       ret = lttng_poll_add(events, a_pipe[0], LPOLLIN | LPOLLERR);
-       if (ret < 0) {
-               goto error;
-       }
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
- */
-int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size)
-{
-       return __sessiond_set_thread_pollset(events, size, thread_quit_pipe);
-}
-
-/*
- * Init thread quit pipe.
- *
- * Return -1 on error or 0 if all pipes are created.
- */
-static int __init_thread_quit_pipe(int *a_pipe)
-{
-       int ret, i;
-
-       ret = pipe(a_pipe);
-       if (ret < 0) {
-               PERROR("thread quit pipe");
-               goto error;
-       }
-
-       for (i = 0; i < 2; i++) {
-               ret = fcntl(a_pipe[i], F_SETFD, FD_CLOEXEC);
-               if (ret < 0) {
-                       PERROR("fcntl");
-                       goto error;
-               }
-       }
-
-error:
-       return ret;
-}
-
-static int init_thread_quit_pipe(void)
-{
-       return __init_thread_quit_pipe(thread_quit_pipe);
-}
+/* Rotation thread handle. */
+static struct rotation_thread_handle *rotation_thread_handle;
 
 /*
  * Stop all threads by closing the thread quit pipe.
@@ -457,7 +282,7 @@ static void stop_threads(void)
 
        /* Stopping all threads */
        DBG("Terminating all threads");
-       ret = notify_thread_pipe(thread_quit_pipe[1]);
+       ret = sessiond_notify_quit_pipe();
        if (ret < 0) {
                ERR("write error on thread quit pipe");
        }
@@ -571,7 +396,7 @@ static void sessiond_cleanup(void)
         * Close the thread quit pipe. It has already done its job,
         * since we are now called.
         */
-       utils_close_pipe(thread_quit_pipe);
+       sessiond_close_quit_pipe();
 
        ret = remove(config.pid_file_path.value);
        if (ret < 0) {
@@ -4614,14 +4439,6 @@ static void *thread_manage_clients(void *data)
         * commands.
         */
        while (uatomic_read(&lttng_sessiond_ready) != 0) {
-               fd_set read_fds;
-               struct timeval timeout;
-
-               FD_ZERO(&read_fds);
-               FD_SET(thread_quit_pipe[0], &read_fds);
-               memset(&timeout, 0, sizeof(timeout));
-               timeout.tv_usec = 1000;
-
                /*
                 * If a support thread failed to launch, it may signal that
                 * we must exit and the sessiond would never be marked as
@@ -4630,9 +4447,8 @@ static void *thread_manage_clients(void *data)
                 * The timeout is set to 1ms, which serves as a way to
                 * pace down this check.
                 */
-               ret = select(thread_quit_pipe[0] + 1, &read_fds, NULL, NULL,
-                               &timeout);
-               if (ret > 0 || (ret < 0 && errno != EINTR)) {
+               ret = sessiond_wait_for_quit_pipe(1000);
+               if (ret > 0) {
                        goto exit;
                }
        }
@@ -5973,7 +5789,7 @@ int main(int argc, char **argv)
        }
 
        /* Create thread quit pipe */
-       if (init_thread_quit_pipe()) {
+       if (sessiond_init_thread_quit_pipe()) {
                retval = -1;
                goto exit_init_data;
        }
@@ -6235,7 +6051,6 @@ int main(int argc, char **argv)
 
        /* rotation_thread_data acquires the pipes' read side. */
        rotation_thread_handle = rotation_thread_handle_create(
-                       thread_quit_pipe[0],
                        rotation_timer_queue,
                        notification_thread_handle,
                        &notification_thread_ready);
diff --git a/src/bin/lttng-sessiond/process-utils.c b/src/bin/lttng-sessiond/process-utils.c
new file mode 100644 (file)
index 0000000..54a54f5
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *               2013 - 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.
+ *
+ * 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 <signal.h>
+#include "lttng-sessiond.h"
+
+/* Notify parents that we are ready for cmd and health check */
+void sessiond_signal_parents(void)
+{
+       /*
+        * Notify parent pid that we are ready to accept command
+        * for client side.  This ppid is the one from the
+        * external process that spawned us.
+        */
+       if (config.sig_parent) {
+               kill(ppid, SIGUSR1);
+       }
+
+       /*
+        * Notify the parent of the fork() process that we are
+        * ready.
+        */
+       if (config.daemonize || config.background) {
+               kill(child_ppid, SIGUSR1);
+       }
+}
diff --git a/src/bin/lttng-sessiond/ready.c b/src/bin/lttng-sessiond/ready.c
new file mode 100644 (file)
index 0000000..3a268b0
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *               2013 - 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.
+ *
+ * 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 <common/macros.h>
+#include <urcu.h>
+#include "lttng-sessiond.h"
+
+/*
+ * The initialization of the session daemon is done in multiple phases.
+ *
+ * While all threads are launched near-simultaneously, only some of them
+ * are needed to ensure the session daemon can start to respond to client
+ * requests.
+ *
+ * There are two important guarantees that we wish to offer with respect
+ * to the initialisation of the session daemon:
+ *   - When the daemonize/background launcher process exits, the sessiond
+ *     is fully able to respond to client requests,
+ *   - Auto-loaded sessions are visible to clients.
+ *
+ * In order to achieve this, a number of support threads have to be launched
+ * to allow the "client" thread to function properly. Moreover, since the
+ * "load session" thread needs the client thread, we must provide a way
+ * for the "load session" thread to know that the "client" thread is up
+ * and running.
+ *
+ * Hence, the support threads decrement the lttng_sessiond_ready counter
+ * while the "client" threads waits for it to reach 0. Once the "client" thread
+ * unblocks, it posts the message_thread_ready semaphore which allows the
+ * "load session" thread to progress.
+ *
+ * This implies that the "load session" thread is the last to be initialized
+ * and will explicitly call sessiond_signal_parents(), which signals the parents
+ * that the session daemon is fully initialized.
+ *
+ * The four (4) support threads are:
+ *  - agent_thread
+ *  - notification_thread
+ *  - rotation_thread
+ *  - health_thread
+ */
+#define NR_LTTNG_SESSIOND_SUPPORT_THREADS 4
+int lttng_sessiond_ready = NR_LTTNG_SESSIOND_SUPPORT_THREADS;
+
+LTTNG_HIDDEN
+void sessiond_notify_ready(void)
+{
+       /*
+        * This memory barrier is paired with the one performed by
+        * the client thread after it has seen that 'lttng_sessiond_ready' is 0.
+        *
+        * The purpose of these memory barriers is to ensure that all
+        * initialization operations of the various threads that call this
+        * function to signal that they are ready are commited/published
+        * before the client thread can see the 'lttng_sessiond_ready' counter
+        * reach 0.
+        *
+        * Note that this could be a 'write' memory barrier, but a full barrier
+        * is used in case the code using this utility changes. The performance
+        * implications of this choice are minimal since this is a slow path.
+        */
+       cmm_smp_mb();
+       uatomic_sub(&lttng_sessiond_ready, 1);
+}
index df70f8fd57e49a19c382b21c69eaf56c1f68047c..25dbf76a932c3414f294848f2211a42e5e8659e3 100644 (file)
@@ -72,7 +72,6 @@ struct rotation_thread_timer_queue {
 };
 
 struct rotation_thread_handle {
-       int quit_pipe;
        struct rotation_thread_timer_queue *rotation_timer_queue;
        /* Access to the notification thread cmd_queue */
        struct notification_thread_handle *notification_thread_handle;
@@ -169,7 +168,6 @@ void rotation_thread_handle_destroy(
 }
 
 struct rotation_thread_handle *rotation_thread_handle_create(
-               int quit_pipe,
                struct rotation_thread_timer_queue *rotation_timer_queue,
                struct notification_thread_handle *notification_thread_handle,
                sem_t *notification_thread_ready)
@@ -181,7 +179,6 @@ struct rotation_thread_handle *rotation_thread_handle_create(
                goto end;
        }
 
-       handle->quit_pipe = quit_pipe;
        handle->rotation_timer_queue = rotation_timer_queue;
        handle->notification_thread_handle = notification_thread_handle;
        handle->notification_thread_ready = notification_thread_ready;
@@ -276,15 +273,8 @@ int init_poll_set(struct lttng_poll_event *poll_set,
         *      - quit pipe,
         *      - rotation thread timer queue pipe,
         */
-       ret = lttng_poll_create(poll_set, 2, LTTNG_CLOEXEC);
-       if (ret < 0) {
-               goto end;
-       }
-
-       ret = lttng_poll_add(poll_set, handle->quit_pipe,
-                       LPOLLIN | LPOLLERR);
-       if (ret < 0) {
-               ERR("[rotation-thread] Failed to add quit_pipe fd to pollset");
+       ret = sessiond_set_thread_pollset(poll_set, 2);
+       if (ret) {
                goto error;
        }
        ret = lttng_poll_add(poll_set,
@@ -295,7 +285,6 @@ int init_poll_set(struct lttng_poll_event *poll_set,
                goto error;
        }
 
-end:
        return ret;
 error:
        lttng_poll_clean(poll_set);
@@ -960,7 +949,7 @@ void *thread_rotation(void *data)
                                goto error;
                        }
 
-                       if (fd == handle->quit_pipe) {
+                       if (sessiond_check_thread_quit_pipe(fd, revents)) {
                                DBG("[rotation-thread] Quit pipe activity");
                                /* TODO flush the queue. */
                                goto exit;
index 618797f108d3d842142c55d65a4842af10ad5e06..eb206e701ebccf7755009c4136a928e5c0a3da40 100644 (file)
@@ -46,7 +46,6 @@ void rotation_thread_timer_queue_destroy(
                struct rotation_thread_timer_queue *queue);
 
 struct rotation_thread_handle *rotation_thread_handle_create(
-               int thread_quit_pipe,
                struct rotation_thread_timer_queue *rotation_timer_queue,
                struct notification_thread_handle *notification_thread_handle,
                sem_t *notification_thread_ready);
index 38dbf6128c31639b668910ede62fc4a51f19d7c0..56c38714fc6c6ccad7ef56b3a39820f34062d2ca 100644 (file)
@@ -33,6 +33,7 @@
 #include "session.h"
 #include "utils.h"
 #include "trace-ust.h"
+#include "timer.h"
 
 /*
  * NOTES:
diff --git a/src/bin/lttng-sessiond/thread-utils.c b/src/bin/lttng-sessiond/thread-utils.c
new file mode 100644 (file)
index 0000000..99b8298
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *               2013 - 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.
+ *
+ * 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"
+#include "utils.h"
+#include <common/utils.h>
+
+/*
+ * Quit pipe for all threads. This permits a single cancellation point
+ * for all threads when receiving an event on the pipe.
+ */
+static int thread_quit_pipe[2] = { -1, -1 };
+
+/*
+ * Init thread quit pipe.
+ *
+ * Return -1 on error or 0 if all pipes are created.
+ */
+static int __init_thread_quit_pipe(int *a_pipe)
+{
+       int ret, i;
+
+       ret = pipe(a_pipe);
+       if (ret < 0) {
+               PERROR("thread quit pipe");
+               goto error;
+       }
+
+       for (i = 0; i < 2; i++) {
+               ret = fcntl(a_pipe[i], F_SETFD, FD_CLOEXEC);
+               if (ret < 0) {
+                       PERROR("fcntl");
+                       goto error;
+               }
+       }
+
+error:
+       return ret;
+}
+
+int sessiond_init_thread_quit_pipe(void)
+{
+       return __init_thread_quit_pipe(thread_quit_pipe);
+}
+
+int sessiond_check_thread_quit_pipe(int fd, uint32_t events)
+{
+       return (fd == thread_quit_pipe[0] && (events & LPOLLIN));
+}
+
+/*
+ * Wait for a notification on the quit pipe (with a timeout).
+ *
+ * Returns 1 if the caller should quit, 0 if the timeout was reached, and
+ * -1 if an error was encountered.
+ */
+int sessiond_wait_for_quit_pipe(unsigned int timeout_us)
+{
+       int ret;
+       fd_set read_fds;
+       struct timeval timeout;
+
+       FD_ZERO(&read_fds);
+       FD_SET(thread_quit_pipe[0], &read_fds);
+       memset(&timeout, 0, sizeof(timeout));
+       timeout.tv_usec = timeout_us;
+
+       while (true) {
+               ret = select(thread_quit_pipe[0] + 1, &read_fds, NULL, NULL,
+                               &timeout);
+               if (ret < 0 && errno == EINTR) {
+                       /* Retry on interrupt. */
+                       continue;
+               } else {
+                       break;
+               }
+       }
+
+       if (ret > 0) {
+               /* Should quit. */
+               ret = 1;
+       } else if (ret < 0 && errno != EINTR) {
+               /* Unknown error. */
+               PERROR("Failed to select() thread quit pipe");
+               ret = -1;
+       } else {
+               /* Timeout reached. */
+               ret = 0;
+       }
+
+       return ret;
+}
+
+int sessiond_notify_quit_pipe(void)
+{
+       return notify_thread_pipe(thread_quit_pipe[1]);
+}
+
+void sessiond_close_quit_pipe(void)
+{
+       utils_close_pipe(thread_quit_pipe);
+}
+
+static
+int __sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size,
+               int *a_pipe)
+{
+       int ret;
+
+       assert(events);
+
+       ret = lttng_poll_create(events, size, LTTNG_CLOEXEC);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Add quit pipe */
+       ret = lttng_poll_add(events, a_pipe[0], LPOLLIN | LPOLLERR);
+       if (ret < 0) {
+               goto error;
+       }
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
+ */
+int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size)
+{
+       return __sessiond_set_thread_pollset(events, size, thread_quit_pipe);
+}
index 46186d383583d7c21cf50b0d66e74ea8fb81d099..7a26b42cfd3ecf7b708207094a1d4548186c0398 100644 (file)
@@ -8,8 +8,7 @@ LIBHASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la
 LIBRELAYD=$(top_builddir)/src/common/relayd/librelayd.la
 LIBHEALTH=$(top_builddir)/src/common/health/libhealth.la
 
-LIVE=$(top_builddir)/src/bin/lttng-sessiond/session.$(OBJEXT) \
-        $(top_builddir)/src/bin/lttng-sessiond/consumer.$(OBJEXT) \
+LIVE= $(top_builddir)/src/bin/lttng-sessiond/consumer.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/utils.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/snapshot.$(OBJEXT)
 
index 8ff97db253652dad50e5f3d08816bba689b7288f..9f4532cfd6078c71e6e4ad0e3a547cb570ccf872 100644 (file)
@@ -36,7 +36,6 @@
 #include <lttng/lttng.h>
 
 #include <urcu/list.h>
-#include <bin/lttng-sessiond/session.h>
 #include <common/common.h>
 
 #include <bin/lttng-relayd/lttng-viewer-abi.h>
index ee4a37b7f8510d66245072cb5fd717eb0adae5d6..0f8a8bb1db3f545af0025913dc7a481581fed3fc 100644 (file)
@@ -39,48 +39,88 @@ endif
 test_uri_SOURCES = test_uri.c
 test_uri_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBHASHTABLE) $(DL_LIBS)
 
-# Session unit test
-SESSIONS=$(top_builddir)/src/bin/lttng-sessiond/session.$(OBJEXT) \
+# Sessiond objects
+SESSIOND_OBJS = $(top_builddir)/src/bin/lttng-sessiond/buffer-registry.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/load-session-thread.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/cmd.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/save.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/notification-thread-commands.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/shm.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/kernel.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/ht-cleanup.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/notification-thread.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/lttng-syscall.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/channel.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/agent.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/ready.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/kernel-consumer.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/trace-kernel.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/rotation-thread.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/context.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/consumer.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/utils.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/fd-limit.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/notification-thread-events.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/event.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/timer.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/snapshot.$(OBJEXT) \
-        $(top_builddir)/src/bin/lttng-sessiond/ht-cleanup.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/sessiond-config.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/rotate.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/modprobe.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/session.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/globals.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/thread-utils.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/process-utils.$(OBJEXT) \
         $(top_builddir)/src/common/libcommon.la \
         $(top_builddir)/src/common/testpoint/libtestpoint.la \
         $(top_builddir)/src/common/compat/libcompat.la \
         $(top_builddir)/src/common/health/libhealth.la \
         $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la
 
+if HAVE_LIBLTTNG_UST_CTL
+SESSIOND_OBJS += $(top_builddir)/src/bin/lttng-sessiond/trace-ust.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-registry.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-app.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-consumer.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-thread.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-metadata.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/agent-thread.$(OBJEXT) \
+                $(top_builddir)/src/bin/lttng-sessiond/ust-field-utils.$(OBJEXT)
+endif
 
 test_session_SOURCES = test_session.c
 test_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \
-                    $(LIBHASHTABLE) $(DL_LIBS) -lrt
-test_session_LDADD += $(SESSIONS)
+                    $(LIBHASHTABLE) $(DL_LIBS) -lrt -lurcu-common -lurcu \
+                    $(KMOD_LIBS) \
+                    $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \
+                    $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \
+                    $(top_builddir)/src/common/compat/libcompat.la \
+                    $(top_builddir)/src/common/testpoint/libtestpoint.la \
+                    $(top_builddir)/src/common/health/libhealth.la \
+                    $(top_builddir)/src/common/config/libconfig.la \
+                    $(top_builddir)/src/common/string-utils/libstring-utils.la
+
+test_session_LDADD += $(SESSIOND_OBJS)
 
-# UST data structures unit test
 if HAVE_LIBLTTNG_UST_CTL
-UST_DATA_TRACE=$(top_builddir)/src/bin/lttng-sessiond/trace-ust.$(OBJEXT) \
-              $(top_builddir)/src/bin/lttng-sessiond/consumer.$(OBJEXT) \
-              $(top_builddir)/src/bin/lttng-sessiond/utils.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/buffer-registry.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/ust-registry.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/ust-field-utils.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/ust-metadata.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/ust-app.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/ust-consumer.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/fd-limit.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/session.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/snapshot.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/agent.$(OBJEXT) \
-                  $(top_builddir)/src/bin/lttng-sessiond/notification-thread-commands.$(OBJEXT) \
-                  $(top_builddir)/src/common/libcommon.la \
-                  $(top_builddir)/src/common/health/libhealth.la \
-                  $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la
+test_session_LDADD += -llttng-ust-ctl
+endif
 
+# UST data structures unit test
+if HAVE_LIBLTTNG_UST_CTL
 test_ust_data_SOURCES = test_ust_data.c
-test_ust_data_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM)\
-                     $(LIBHASHTABLE) $(DL_LIBS) -lrt -llttng-ust-ctl
-test_ust_data_LDADD += $(UST_DATA_TRACE)
+test_ust_data_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \
+                     $(LIBHASHTABLE) $(DL_LIBS) -lrt -lurcu-common -lurcu \
+                     -llttng-ust-ctl \
+                     $(KMOD_LIBS) \
+                     $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \
+                     $(top_builddir)/src/common/kernel-ctl/libkernel-ctl.la \
+                     $(top_builddir)/src/common/compat/libcompat.la \
+                     $(top_builddir)/src/common/testpoint/libtestpoint.la \
+                     $(top_builddir)/src/common/health/libhealth.la \
+                     $(top_builddir)/src/common/config/libconfig.la \
+                     $(top_builddir)/src/common/string-utils/libstring-utils.la
+test_ust_data_LDADD += $(SESSIOND_OBJS)
 endif
 
 # Kernel data structures unit test
This page took 0.03865 seconds and 4 git commands to generate.