From: Mathieu Desnoyers Date: Wed, 7 Aug 2013 09:26:51 +0000 (-0400) Subject: Introduce LTTNG_NETWORK_SOCKET_TIMEOUT env. var X-Git-Tag: v2.3.0-rc3~54 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=554831e798d0646f5d8c261b6207527c5f839222;p=lttng-tools.git Introduce LTTNG_NETWORK_SOCKET_TIMEOUT env. var Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/doc/man/lttng-relayd.8 b/doc/man/lttng-relayd.8 index 44631b1b2..1d1802a4c 100644 --- a/doc/man/lttng-relayd.8 +++ b/doc/man/lttng-relayd.8 @@ -61,6 +61,15 @@ Output base directory. Must use an absolute path (~/lttng-traces is the default) .TP .BR "-V, --version" Show version number +.SH "ENVIRONMENT VARIABLES" + +.PP +.IP "LTTNG_NETWORK_SOCKET_TIMEOUT" +Control timeout of socket connection, receive and send. Takes an integer +parameter: the timeout value, in milliseconds. A value of 0 or -1 uses +the timeout of the operating system (this is the default). +.PP + .SH "SEE ALSO" .PP diff --git a/doc/man/lttng-sessiond.8 b/doc/man/lttng-sessiond.8 index dfc94185f..347bffcaa 100644 --- a/doc/man/lttng-sessiond.8 +++ b/doc/man/lttng-sessiond.8 @@ -134,9 +134,14 @@ Debug-mode disabling use of clone/fork. Insecure, but required to allow debuggers to work with sessiond on some operating systems. .IP "LTTNG_APP_SOCKET_TIMEOUT" Control the timeout of application's socket when sending and receiving -commands. After this period of time, the application is unregistered by the -session daemon. A value of 0 or -1 means an infinite timeout. Default value is -5 seconds. +commands. Takes an integer parameter: the timeout value, in seconds. +After this period of time, the application is unregistered by the +session daemon. A value of 0 or -1 means an infinite timeout. Default +value is 5 seconds. +.IP "LTTNG_NETWORK_SOCKET_TIMEOUT" +Control timeout of socket connection, receive and send. Takes an integer +parameter: the timeout value, in milliseconds. A value of 0 or -1 uses +the timeout of the operating system (this is the default). .SH "SEE ALSO" .PP diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index 8ddd5a372..e05a4b150 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -380,6 +380,9 @@ int main(int argc, char **argv) } ctx->type = opt_type; + /* Initialize communication library */ + lttcomm_init(); + /* Create thread to manage channels */ ret = pthread_create(&channel_thread, NULL, consumer_thread_channel_poll, (void *) ctx); diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 3bef52b43..53f1b49ce 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -2110,6 +2110,9 @@ int main(int argc, char **argv) /* Set up max poll set size */ lttng_poll_set_max_size(); + /* Initialize communication library */ + lttcomm_init(); + /* Setup the dispatcher thread */ ret = pthread_create(&dispatcher_thread, NULL, relay_thread_dispatcher, (void *) NULL); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 2929bba0d..e05d72bac 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -4631,6 +4631,9 @@ int main(int argc, char **argv) write_pidfile(); + /* Initialize communication library */ + lttcomm_init(); + /* Create thread to manage the client socket */ ret = pthread_create(&ht_cleanup_thread, NULL, thread_ht_cleanup, (void *) NULL); diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 9a13f4148..58a7ffb50 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -38,6 +38,8 @@ /* For Inet6 socket */ #include "inet6.h" +#define NETWORK_TIMEOUT_ENV "LTTNG_NETWORK_SOCKET_TIMEOUT" + static struct lttcomm_net_family net_families[] = { { LTTCOMM_INET, lttcomm_create_inet_sock }, { LTTCOMM_INET6, lttcomm_create_inet6_sock }, @@ -70,6 +72,8 @@ static const char *lttcomm_readable_code[] = { [ LTTCOMM_ERR_INDEX(LTTCOMM_NR) ] = "Unknown error code" }; +static unsigned long network_timeout; + /* * Return ptr to string representing a human readable error code from the * lttcomm_return_code enum. @@ -368,3 +372,30 @@ error_free: error: return NULL; } + +LTTNG_HIDDEN +void lttcomm_init(void) +{ + const char *env; + + env = getenv(NETWORK_TIMEOUT_ENV); + if (env) { + long timeout; + + errno = 0; + timeout = strtol(env, NULL, 0); + if (errno != 0 || timeout < -1L) { + PERROR("Network timeout"); + } else { + if (timeout > 0) { + network_timeout = timeout; + } + } + } +} + +LTTNG_HIDDEN +unsigned long lttcomm_get_network_timeout(void) +{ + return network_timeout; +} diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index ea8ad1ce0..2450e79ec 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -474,4 +474,8 @@ extern void lttcomm_copy_sock(struct lttcomm_sock *dst, extern struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock( struct lttng_uri *uri, uint32_t major, uint32_t minor); +extern void lttcomm_init(void); +/* Get network timeout, in milliseconds */ +extern unsigned long lttcomm_get_network_timeout(void); + #endif /* _LTTNG_SESSIOND_COMM_H */