From 8b5295fa533104f59348a6e9a5418804f27b82fe Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Fri, 15 Nov 2024 10:55:39 -0500 Subject: [PATCH] lttng-relayd: Add `--sig-parent` parameter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I3a456f43de7ba2e557c1ca1c98466421e78e2f2e Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- doc/man/lttng-relayd.8.txt | 9 ++++++++- src/bin/lttng-relayd/main.cpp | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/man/lttng-relayd.8.txt b/doc/man/lttng-relayd.8.txt index 3f38b2fe0..f55149732 100644 --- a/doc/man/lttng-relayd.8.txt +++ b/doc/man/lttng-relayd.8.txt @@ -18,7 +18,7 @@ SYNOPSIS [option:--live-port='URL'] [option:--output='DIR'] [option:--group='GROUP'] [option:--verbose]... [option:--working-directory='DIR'] [option:--group-output-by-host | option:--group-output-by-session] [option:--disallow-clear] - [option:--dynamic-port-allocation] [option:--pid-file='FILE'] + [option:--dynamic-port-allocation] [option:--pid-file='FILE'] [option:--sig-parent] DESCRIPTION @@ -241,6 +241,13 @@ option:-P, option:--pid-file:: + This file is not otherwise used by lttng-relayd and is removed at shutdown. +option:-S, option:--sig-parent:: + Send the `USR1` signal to the parent process to notify readiness. ++ +You can also use the option:--daemonize or option:--background option, +in which case `lttng-relayd` ensures the daemon is ready to receive +client commands before it exits. + Output ~~~~~~ See the ``<>'' section above to learn diff --git a/src/bin/lttng-relayd/main.cpp b/src/bin/lttng-relayd/main.cpp index c5485dfa1..e4c121538 100644 --- a/src/bin/lttng-relayd/main.cpp +++ b/src/bin/lttng-relayd/main.cpp @@ -99,7 +99,7 @@ enum relay_connection_status { /* command line options */ char *opt_output_path, *opt_working_directory, *opt_pid_file = nullptr; static int opt_daemon, opt_background, opt_print_version, - opt_allow_clear = 1, opt_dynamic_port_allocation = 0; + opt_allow_clear = 1, opt_dynamic_port_allocation = 0, opt_sig_parent = 0; enum relay_group_output_by opt_group_output_by = RELAYD_GROUP_OUTPUT_BY_UNKNOWN; /* Argument variables */ @@ -272,6 +272,12 @@ static struct option long_options[] = { }, { "disallow-clear", 0, nullptr, 'x' }, { "dynamic-port-allocation", 0, nullptr, '\0' }, + { + "sig-parent", + 0, + nullptr, + 'S' + }, { nullptr, 0, @@ -478,6 +484,9 @@ static int set_option(int opt, const char *arg, const char *optname) /* Disallow clear */ opt_allow_clear = 0; break; + case 'S': + opt_sig_parent = getppid(); + break; default: /* Unknown option or other error. * Error is printed by getopt, just return */ @@ -4620,6 +4629,11 @@ int main(int argc, char **argv) * signal that asks threads to teardown). */ + /* Initialization complete, signal parent PID if necessary. */ + if (opt_sig_parent != 0) { + kill(opt_sig_parent, SIGUSR1); + } + ret = relayd_live_join(); if (ret) { retval = -1; -- 2.39.5