diff options
-rw-r--r-- | man/distcc.1 | 7 | ||||
-rw-r--r-- | src/daemon.c | 3 | ||||
-rw-r--r-- | src/distcc.h | 3 | ||||
-rw-r--r-- | src/io.c | 31 | ||||
-rw-r--r-- | src/pump.c | 8 | ||||
-rw-r--r-- | 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 */ @@ -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; @@ -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"); |