projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: relayd: notify parent of readiness when all threads ready
[lttng-tools.git]
/
src
/
bin
/
lttng-relayd
/
main.c
diff --git
a/src/bin/lttng-relayd/main.c
b/src/bin/lttng-relayd/main.c
index c32ea815d694f70593a44c5fea59d48067fc313a..86bad26b3d5c028bcdf2a2f8dffbc4859a8fe2ba 100644
(file)
--- a/
src/bin/lttng-relayd/main.c
+++ b/
src/bin/lttng-relayd/main.c
@@
-45,6
+45,7
@@
#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>
@@
-63,7
+64,17
@@
/* command line options */
char *opt_output_path;
/* command line options */
char *opt_output_path;
-static int opt_daemon;
+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;
@@
-131,6
+142,7
@@
static struct option long_options[] = {
{ "data-port", 1, 0, 'D', },
{ "live-port", 1, 0, 'L', },
{ "daemonize", 0, 0, 'd', },
{ "data-port", 1, 0, 'D', },
{ "live-port", 1, 0, 'L', },
{ "daemonize", 0, 0, 'd', },
+ { "background", 0, 0, 'b', },
{ "group", 1, 0, 'g', },
{ "help", 0, 0, 'h', },
{ "output", 1, 0, 'o', },
{ "group", 1, 0, 'g', },
{ "help", 0, 0, 'h', },
{ "output", 1, 0, 'o', },
@@
-150,6
+162,7
@@
void usage(void)
fprintf(stderr, "Usage: %s OPTIONS\n\nOptions:\n", progname);
fprintf(stderr, " -h, --help Display this usage.\n");
fprintf(stderr, " -d, --daemonize Start as a daemon.\n");
fprintf(stderr, "Usage: %s OPTIONS\n\nOptions:\n", progname);
fprintf(stderr, " -h, --help Display this usage.\n");
fprintf(stderr, " -d, --daemonize Start as a daemon.\n");
+ fprintf(stderr, " -b, --background Start as a daemon, keeping console open.\n");
fprintf(stderr, " -C, --control-port URL Control port listening.\n");
fprintf(stderr, " -D, --data-port URL Data port listening.\n");
fprintf(stderr, " -L, --live-port URL Live view port listening.\n");
fprintf(stderr, " -C, --control-port URL Control port listening.\n");
fprintf(stderr, " -D, --data-port URL Data port listening.\n");
fprintf(stderr, " -L, --live-port URL Live view port listening.\n");
@@
-210,6
+223,9
@@
int set_option(int opt, const char *arg, const char *optname)
case 'd':
opt_daemon = 1;
break;
case 'd':
opt_daemon = 1;
break;
+ case 'b':
+ opt_background = 1;
+ break;
case 'g':
tracing_group_name = strdup(arg);
tracing_group_name_override = 1;
case 'g':
tracing_group_name = strdup(arg);
tracing_group_name_override = 1;
@@
-504,6
+520,9
@@
void sighandler(int sig)
DBG("SIGTERM caught");
stop_threads();
break;
DBG("SIGTERM caught");
stop_threads();
break;
+ case SIGUSR1:
+ CMM_STORE_SHARED(recv_child_signal, 1);
+ break;
default:
break;
}
default:
break;
}
@@
-543,11
+562,26
@@
int set_signal_handler(void)
return ret;
}
return ret;
}
- 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");
return ret;
}
return ret;
}
+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.
*
@@
-717,6
+751,8
@@
void *relay_thread_listener(void *data)
goto error_poll_add;
}
goto error_poll_add;
}
+ lttng_relay_notify_ready();
+
while (1) {
health_code_update();
while (1) {
health_code_update();
@@
-2817,11
+2853,6
@@
int main(int argc, char **argv)
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) {
@@
-2847,12
+2878,28
@@
int main(int argc, char **argv)
}
/* Daemonize */
}
/* Daemonize */
- if (opt_daemon) {
- ret = daemon(0, 0);
+ if (opt_daemon || opt_background) {
+ int i;
+
+ ret = lttng_daemonize(&child_ppid, &recv_child_signal,
+ !opt_background);
if (ret < 0) {
if (ret < 0) {
- PERROR("daemon");
goto exit;
}
goto exit;
}
+
+ /*
+ * 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. */
@@
-2881,6
+2928,7
@@
int main(int argc, char **argv)
/* Initialize communication library */
lttcomm_init();
/* Initialize communication library */
lttcomm_init();
+ lttcomm_inet_init();
relay_ctx = zmalloc(sizeof(struct relay_local_data));
if (!relay_ctx) {
relay_ctx = zmalloc(sizeof(struct relay_local_data));
if (!relay_ctx) {
This page took
0.028314 seconds
and
5
git commands to generate.