commit 18a301504d974bcd7fa03f08f951469bbc329820
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Date:   Thu Jul 11 08:59:26 2013 -0400

    Introduce LTTNG_NETWORK_SOCKET_TIMEOUT env. var
    
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

diff --git a/doc/man/lttng-relayd.8 b/doc/man/lttng-relayd.8
index 44631b1..1d1802a 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 dfc9418..347bffc 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 8ddd5a3..e05a4b1 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 3b9f670..9ff1991 100644
--- a/src/bin/lttng-relayd/main.c
+++ b/src/bin/lttng-relayd/main.c
@@ -2114,6 +2114,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 048c1e1..b9404eb 100644
--- a/src/bin/lttng-sessiond/main.c
+++ b/src/bin/lttng-sessiond/main.c
@@ -4583,6 +4583,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 9a13f41..58a7ffb 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 b76135e..8377e9a 100644
--- a/src/common/sessiond-comm/sessiond-comm.h
+++ b/src/common/sessiond-comm/sessiond-comm.h
@@ -473,4 +473,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 */
