[lttng-dev] [PATCH lttng-tools] Add a -l/--load option to the session-daemon

Jérémie Galarneau jeremie.galarneau at efficios.com
Thu May 8 12:02:52 EDT 2014


This option makes it possible to set a PATH from which session
configurations are loaded by the session daemon on startup.

Usage: lttng-sessiond -l PATH

The session configuration file found at PATH, or all those present
in it if it is a directory, will be loaded.

All sessions found under the user's session configuration directory
and under the system session configuration directory are now loaded
by default.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
 src/bin/lttng-sessiond/Makefile.am           |  3 +-
 src/bin/lttng-sessiond/load-session-thread.c | 57 ++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/load-session-thread.h | 25 ++++++++++++
 src/bin/lttng-sessiond/main.c                | 47 ++++++++++++++++++++++-
 4 files changed, 129 insertions(+), 3 deletions(-)
 create mode 100644 src/bin/lttng-sessiond/load-session-thread.c
 create mode 100644 src/bin/lttng-sessiond/load-session-thread.h

diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am
index 71df926..5bd62e5 100644
--- a/src/bin/lttng-sessiond/Makefile.am
+++ b/src/bin/lttng-sessiond/Makefile.am
@@ -28,7 +28,8 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        testpoint.h ht-cleanup.c \
                        snapshot.c snapshot.h \
                        jul.c jul.h \
-                       save.h save.c
+                       save.h save.c \
+                       load-session-thread.h load-session-thread.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/load-session-thread.c b/src/bin/lttng-sessiond/load-session-thread.c
new file mode 100644
index 0000000..9afd6dc
--- /dev/null
+++ b/src/bin/lttng-sessiond/load-session-thread.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau at 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.
+ */
+
+#define _GNU_SOURCE
+#include "load-session-thread.h"
+#include <common/error.h>
+#include <common/config/config.h>
+
+extern sem_t message_thread_ready;
+void lttng_sessiond_notify_ready(void);
+
+/*
+ * This thread loads session configurations once the session daemon is
+ * ready to process client messages.
+ */
+void *thread_load_session(void *data)
+{
+	int ret;
+	const char *path = data;
+
+	DBG("[load-session-thread] Load session");
+
+	ret = sem_wait(&message_thread_ready);
+	if (ret) {
+		PERROR("sem_wait message_thread_ready");
+		goto end;
+	}
+
+	ret = sem_destroy(&message_thread_ready);
+	if (ret) {
+		PERROR("sem_destroy message_thread_ready");
+		goto end;
+	}
+
+	ret = config_load_session(path, NULL, 0);
+	if (ret) {
+		ERR("Session load failed: %s", error_get_str(ret));
+	}
+
+end:
+	lttng_sessiond_notify_ready();
+	return NULL;
+}
diff --git a/src/bin/lttng-sessiond/load-session-thread.h b/src/bin/lttng-sessiond/load-session-thread.h
new file mode 100644
index 0000000..70aaa31
--- /dev/null
+++ b/src/bin/lttng-sessiond/load-session-thread.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau at 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.
+ */
+
+#ifndef LOAD_SESSION_THREAD_H
+#define LOAD_SESSION_THREAD_H
+
+#include <semaphore.h>
+
+void *thread_load_session(void *session_name);
+
+#endif /* LOAD_SESSION_THREAD_H */
diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
index 052e32e..1b6f951 100644
--- a/src/bin/lttng-sessiond/main.c
+++ b/src/bin/lttng-sessiond/main.c
@@ -69,6 +69,7 @@
 #include "ust-thread.h"
 #include "jul-thread.h"
 #include "save.h"
+#include "load-session-thread.h"
 
 #define CONSUMERD_FILE	"lttng-consumerd"
 
@@ -80,6 +81,7 @@ static int opt_sig_parent;
 static int opt_verbose_consumer;
 static int opt_daemon, opt_background;
 static int opt_no_kernel;
+static char *opt_load_session_path;
 static pid_t ppid;          /* Parent PID for --sig-parent option */
 static pid_t child_ppid;    /* Internal parent PID use with daemonize. */
 static char *rundir;
@@ -152,6 +154,7 @@ static const struct option long_options[] = {
 	{ "pidfile", 1, 0, 'p' },
 	{ "jul-tcp-port", 1, 0, 'J' },
 	{ "config", 1, 0, 'f' },
+	{ "load", 1, 0, 'l' },
 	{ NULL, 0, 0, 0 }
 };
 
@@ -200,6 +203,7 @@ static pthread_t dispatch_thread;
 static pthread_t health_thread;
 static pthread_t ht_cleanup_thread;
 static pthread_t jul_reg_thread;
+LTTNG_HIDDEN sem_t message_thread_ready;
 
 /*
  * UST registration command queue. This queue is tied with a futex and uses a N
@@ -296,11 +300,11 @@ const char * const config_section_name = "sessiond";
  * NR_LTTNG_SESSIOND_READY must match the number of calls to
  * lttng_sessiond_notify_ready().
  */
-#define NR_LTTNG_SESSIOND_READY		2
+#define NR_LTTNG_SESSIOND_READY		3
 int lttng_sessiond_ready = NR_LTTNG_SESSIOND_READY;
 
 /* Notify parents that we are ready for cmd and health check */
-static
+LTTNG_HIDDEN
 void lttng_sessiond_notify_ready(void)
 {
 	if (uatomic_sub_return(&lttng_sessiond_ready, 1) == 0) {
@@ -647,6 +651,10 @@ static void cleanup(void)
 		free(opt_pidfile);
 	}
 
+	if (opt_load_session_path) {
+		free(opt_load_session_path);
+	}
+
 	/* <fun> */
 	DBG("%c[%d;%dm*** assert failed :-) *** ==> %c[%dm%c[%d;%dm"
 			"Matthew, BEET driven development works!%c[%dm",
@@ -3876,6 +3884,11 @@ static void *thread_manage_clients(void *data)
 	}
 
 	lttng_sessiond_notify_ready();
+	ret = sem_post(&message_thread_ready);
+	if (ret) {
+		PERROR("sem_post message_thread_ready");
+		goto error;
+	}
 
 	/* This testpoint is after we signal readiness to the parent. */
 	if (testpoint(sessiond_thread_manage_clients)) {
@@ -4110,6 +4123,7 @@ static void usage(void)
 	fprintf(stderr, "      --no-kernel                    Disable kernel tracer\n");
 	fprintf(stderr, "      --jul-tcp-port                 JUL application registration TCP port\n");
 	fprintf(stderr, "  -f  --config                       Load daemon configuration file\n");
+	fprintf(stderr, "  -l  --load PATH                    Load session configuration\n");
 }
 
 /*
@@ -4229,6 +4243,13 @@ static int set_option(int opt, const char *arg, const char *optname)
 		DBG3("JUL TCP port set to non default: %u", jul_tcp_port);
 		break;
 	}
+	case 'l':
+		opt_load_session_path = strdup(arg);
+		if (!opt_load_session_path) {
+			perror("strdup");
+			ret = -ENOMEM;
+		}
+		break;
 	default:
 		/* Unknown option or other error.
 		 * Error is printed by getopt, just return */
@@ -4764,6 +4785,7 @@ int main(int argc, char **argv)
 	int ret = 0;
 	void *status;
 	const char *home_path, *env_app_timeout;
+	pthread_t load_session_thread;
 
 	init_kernel_workarounds();
 
@@ -5065,6 +5087,12 @@ int main(int argc, char **argv)
 	/* This is to get the TCP timeout value. */
 	lttcomm_inet_init();
 
+	ret = sem_init(&message_thread_ready, 0, 0);
+	if (ret) {
+		PERROR("sem_init message_thread_ready");
+		goto error;
+	}
+
 	/*
 	 * Initialize the health check subsystem. This call should set the
 	 * appropriate time values.
@@ -5148,7 +5176,22 @@ int main(int argc, char **argv)
 			PERROR("pthread_create kernel");
 			goto exit_kernel;
 		}
+	}
+
+	/* Create session loading thread. */
+	ret = pthread_create(&load_session_thread, NULL,
+			thread_load_session,
+			(void *) opt_load_session_path);
+	if (ret != 0) {
+		PERROR("pthread_create load_session_thread");
+	}
 
+	ret = pthread_detach(load_session_thread);
+	if (ret != 0) {
+		PERROR("pthread_detach load_session_thread");
+	}
+
+	if (is_root && !opt_no_kernel) {
 		ret = pthread_join(kernel_thread, &status);
 		if (ret != 0) {
 			PERROR("pthread_join");
-- 
1.9.2




More information about the lttng-dev mailing list