- relayd start using daemonize common lib,
- wait for health check thread, listener and live listener threads to be
ready before letting the parent know it is ready (in daemon and
background modes).
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
+ lttng_relay_notify_ready();
+
while (1) {
DBG("Health check ready");
while (1) {
DBG("Health check ready");
+ lttng_relay_notify_ready();
+
while (1) {
health_code_update();
while (1) {
health_code_update();
extern const char * const config_section_name;
struct relay_stream *relay_stream_find_by_id(uint64_t stream_id);
extern const char * const config_section_name;
struct relay_stream *relay_stream_find_by_id(uint64_t stream_id);
+void lttng_relay_notify_ready(void);
#endif /* LTTNG_RELAYD_H */
#endif /* LTTNG_RELAYD_H */
#include <common/compat/poll.h>
#include <common/compat/socket.h>
#include <common/defaults.h>
#include <common/compat/poll.h>
#include <common/compat/socket.h>
#include <common/defaults.h>
+#include <common/daemonize.h>
#include <common/futex.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/sessiond-comm/inet.h>
#include <common/futex.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/sessiond-comm/inet.h>
/* command line options */
char *opt_output_path;
static int opt_daemon, opt_background;
/* command line options */
char *opt_output_path;
static int opt_daemon, opt_background;
+
+/*
+ * We need to wait for listener and live listener threads, as well as
+ * health check thread, before being ready to signal readiness.
+ */
+#define NR_LTTNG_RELAY_READY 3
+static int lttng_relay_ready = NR_LTTNG_RELAY_READY;
+static int recv_child_signal; /* Set to 1 when a SIGUSR1 signal is received. */
+static pid_t child_ppid; /* Internal parent PID use with daemonize. */
+
static struct lttng_uri *control_uri;
static struct lttng_uri *data_uri;
static struct lttng_uri *live_uri;
static struct lttng_uri *control_uri;
static struct lttng_uri *data_uri;
static struct lttng_uri *live_uri;
DBG("SIGTERM caught");
stop_threads();
break;
DBG("SIGTERM caught");
stop_threads();
break;
+ case SIGUSR1:
+ CMM_STORE_SHARED(recv_child_signal, 1);
+ break;
- DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT");
+ if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) {
+ PERROR("sigaction");
+ return ret;
+ }
+
+ DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
+void lttng_relay_notify_ready(void)
+{
+ /* Notify the parent of the fork() process that we are ready. */
+ if (opt_daemon || opt_background) {
+ if (uatomic_sub_return(<tng_relay_ready, 1) == 0) {
+ kill(child_ppid, SIGUSR1);
+ }
+ }
+}
+
/*
* Init thread quit pipe.
*
/*
* Init thread quit pipe.
*
+ lttng_relay_notify_ready();
+
while (1) {
health_code_update();
while (1) {
health_code_update();
void *status;
struct relay_local_data *relay_ctx;
void *status;
struct relay_local_data *relay_ctx;
- /* Create thread quit pipe */
- if ((ret = init_thread_quit_pipe()) < 0) {
- goto error;
- }
-
/* Parse arguments */
progname = argv[0];
if ((ret = set_options(argc, argv)) < 0) {
/* Parse arguments */
progname = argv[0];
if ((ret = set_options(argc, argv)) < 0) {
/* Daemonize */
if (opt_daemon || opt_background) {
/* Daemonize */
if (opt_daemon || opt_background) {
- ret = daemon(0, opt_background);
+ int i;
+
+ ret = lttng_daemonize(&child_ppid, &recv_child_signal,
+ !opt_background);
+
+ /*
+ * We are in the child. Make sure all other file
+ * descriptors are closed, in case we are called with
+ * more opened file descriptors than the standard ones.
+ */
+ for (i = 3; i < sysconf(_SC_OPEN_MAX); i++) {
+ (void) close(i);
+ }
+ }
+
+ /* Create thread quit pipe */
+ if ((ret = init_thread_quit_pipe()) < 0) {
+ goto error;
}
/* We need those values for the file/dir creation. */
}
/* We need those values for the file/dir creation. */