From f04234a9cb6f8e1c47034404847b332481f95b7c Mon Sep 17 00:00:00 2001 From: zhanglei Date: Wed, 10 Feb 2010 03:31:34 +0000 Subject: Add support for $DISTCC_IO_TIMEOUT. Reviewed by Fergus Henderson. git-svn-id: http://distcc.googlecode.com/svn/trunk@712 01de4be4-8c4a-0410-9132-4925637da917 --- man/distcc.1 | 7 +++++++ src/daemon.c | 3 +++ src/distcc.h | 3 ++- src/io.c | 31 +++++++++++++++++++++++++------ src/pump.c | 8 +++++--- src/sendfile.c | 4 +++- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/man/distcc.1 b/man/distcc.1 index e3528cb..2a0bcc4 100644 --- a/man/distcc.1 +++ b/man/distcc.1 @@ -763,6 +763,13 @@ variable is set to 0 then fallbacks are disabled and those compilations will simply fail. Note that this does not affect jobs which must always be local such as linking. .TP +.B "DISTCC_IO_TIMEOUT" +Specifies how long (in seconds) distcc will wait before deciding a +distributed job has timed out. If a distributed job is expected to +takes a long time, consider increasing this value so the job does +not time out and fallback to a local compile. By default set to +300 seconds. +.TP .B "DISTCC_SAVE_TEMPS" If set to 1, temporary files are not deleted after use. Good for debugging, or if your disks are too empty. diff --git a/src/daemon.c b/src/daemon.c index 395d953..984ad62 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -222,6 +222,9 @@ int main(int argc, char *argv[]) } #endif + /* Initialize the distcc io timeout value */ + dcc_get_io_timeout(); + if (dcc_should_be_inetd()) ret = dcc_inetd_server(); else diff --git a/src/distcc.h b/src/distcc.h index d4fb44b..7f2578f 100644 --- a/src/distcc.h +++ b/src/distcc.h @@ -320,6 +320,7 @@ int dcc_r_str_alloc(int fd, unsigned len, char **buf); int tcp_cork_sock(int fd, int corked); int dcc_close(int fd); +int dcc_get_io_timeout(void); int dcc_want_mmap(void); @@ -331,7 +332,7 @@ int dcc_load_file_string(const char *filename, char **retbuf); -extern const int dcc_connect_timeout, dcc_io_timeout; +extern const int dcc_connect_timeout; /* pump.c */ diff --git a/src/io.c b/src/io.c index 28d20ca..5206035 100644 --- a/src/io.c +++ b/src/io.c @@ -62,10 +62,29 @@ -/** Timeout for all IO other than opening connections. Much longer, because - * compiling files can take a long time. **/ -const int dcc_io_timeout = 300; /* seconds */ - +int dcc_get_io_timeout(void) +{ + /** Timeout for all IO other than opening connections. Much longer, + * because compiling files can take a long time. **/ + static const int default_dcc_io_timeout = 300; /* seconds */ + static int current_timeout = 0; + + if (current_timeout > 0) + return current_timeout; + + const char *user_timeout = getenv("DISTCC_IO_TIMEOUT"); + if (user_timeout) { + int parsed_user_timeout = atoi(user_timeout); + if (parsed_user_timeout <= 0) { + rs_log_error("Bad DISTCC_IO_TIMEOUT value: %s", user_timeout); + exit(EXIT_BAD_ARGUMENTS); + } + current_timeout = parsed_user_timeout; + } else { + current_timeout = default_dcc_io_timeout; + } + return current_timeout; +} /** * @todo Perhaps only apply the timeout for initial connections, not when @@ -178,7 +197,7 @@ int dcc_readx(int fd, void *buf, size_t len) r = read(fd, buf, len); if (r == -1 && errno == EAGAIN) { - if ((ret = dcc_select_for_read(fd, dcc_io_timeout))) + if ((ret = dcc_select_for_read(fd, dcc_get_io_timeout()))) return ret; else continue; @@ -215,7 +234,7 @@ int dcc_writex(int fd, const void *buf, size_t len) r = write(fd, buf, len); if (r == -1 && errno == EAGAIN) { - if ((ret = dcc_select_for_write(fd, dcc_io_timeout))) + if ((ret = dcc_select_for_write(fd, dcc_get_io_timeout()))) return ret; else continue; diff --git a/src/pump.c b/src/pump.c index 06d6d9b..9ec4307 100644 --- a/src/pump.c +++ b/src/pump.c @@ -107,7 +107,7 @@ dcc_pump_readwrite(int ofd, int ifd, size_t n) r_in = read(ifd, buf, (size_t) wanted); if (r_in == -1 && errno == EAGAIN) { - if ((ret = dcc_select_for_read(ifd, dcc_io_timeout)) != 0) + if ((ret = dcc_select_for_read(ifd, dcc_get_io_timeout())) != 0) return ret; else continue; @@ -132,10 +132,12 @@ dcc_pump_readwrite(int ofd, int ifd, size_t n) r_out = write(ofd, p, (size_t) r_in); if (r_out == -1 && errno == EAGAIN) { - if ((ret = dcc_select_for_write(ofd, dcc_io_timeout)) != 0) + if ((ret = dcc_select_for_write(ofd, + dcc_get_io_timeout())) != 0) { return ret; - else + } else { continue; + } } else if (r_out == -1 && errno == EINTR) { continue; } else if (r_out == -1 || r_out == 0) { diff --git a/src/sendfile.c b/src/sendfile.c index 16df443..d8a9e0a 100644 --- a/src/sendfile.c +++ b/src/sendfile.c @@ -206,8 +206,10 @@ dcc_pump_sendfile(int ofd, int ifd, size_t size) if (sent == -1) { if (errno == EAGAIN) { /* Sleep until we're able to write out more data. */ - if ((ret = dcc_select_for_write(ofd, dcc_io_timeout)) != 0) + if ((ret = dcc_select_for_write(ofd, + dcc_get_io_timeout())) != 0) { return ret; + } rs_trace("select() returned, continuing to write"); } else if (errno == EINTR) { rs_trace("sendfile() interrupted, continuing"); -- cgit v1.2.1