summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Landden <shawn@git.icu>2021-09-27 21:19:54 +0400
committerGitHub <noreply@github.com>2021-09-27 21:19:54 +0400
commit3d543c06263744452d099e2b1860052ab061a842 (patch)
tree5e5d7094b7ac6afb1197cd5e006a2a372436d428
parentda7412679d16d161f1e6d23e8f93f15f11fcbf73 (diff)
parenta59c8a58caa912e85867749cbd03861f4654acc1 (diff)
downloaddistcc-git-3d543c06263744452d099e2b1860052ab061a842.tar.gz
Merge pull request #438 from asheplyakov/fix-434
Restrict number of retries when backoff is disabled
-rw-r--r--src/backoff.c33
-rw-r--r--src/compile.c24
-rw-r--r--src/distcc.h1
3 files changed, 41 insertions, 17 deletions
diff --git a/src/backoff.c b/src/backoff.c
index b3d656c..5aaf45a 100644
--- a/src/backoff.c
+++ b/src/backoff.c
@@ -52,6 +52,19 @@
static int dcc_backoff_period = 60; /* seconds */
+static int dcc_get_backoff_period(void)
+{
+ char *bp;
+ bp = getenv("DISTCC_BACKOFF_PERIOD");
+ if (bp)
+ dcc_backoff_period = atoi(bp);
+ return dcc_backoff_period;
+}
+
+int dcc_backoff_is_enabled(void)
+{
+ return dcc_get_backoff_period() != 0;
+}
/**
* Remember that this host is working OK.
@@ -61,23 +74,17 @@ static int dcc_backoff_period = 60; /* seconds */
**/
int dcc_enjoyed_host(const struct dcc_hostdef *host)
{
- char *bp;
-
/* special-case: if DISTCC_BACKOFF_PERIOD==0, don't manage backoff files */
- bp = getenv("DISTCC_BACKOFF_PERIOD");
- if (bp && (atoi(bp) == 0))
- return 0;
+ if (!dcc_backoff_is_enabled())
+ return 0;
return dcc_remove_timefile("backoff", host);
}
int dcc_disliked_host(const struct dcc_hostdef *host)
{
- char *bp;
-
/* special-case: if DISTCC_BACKOFF_PERIOD==0, don't manage backoff files */
- bp = getenv("DISTCC_BACKOFF_PERIOD");
- if (bp && (atoi(bp) == 0))
+ if (!dcc_backoff_is_enabled())
return 0;
/* i hate you (but only for dcc_backoff_period seconds) */
@@ -108,14 +115,8 @@ static int dcc_check_backoff(struct dcc_hostdef *host)
int dcc_remove_disliked(struct dcc_hostdef **hostlist)
{
struct dcc_hostdef *h;
- char *bp;
- bp = getenv("DISTCC_BACKOFF_PERIOD");
- if (bp)
- dcc_backoff_period = atoi(bp);
-
- /* special-case: if DISTCC_BACKOFF_PERIOD==0, don't manage backoff files */
- if (dcc_backoff_period == 0)
+ if (!dcc_backoff_is_enabled())
return 0;
while ((h = *hostlist) != NULL) {
diff --git a/src/compile.c b/src/compile.c
index 9c02a6e..1b2b080 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -636,6 +636,18 @@ static int dcc_gcc_rewrite_fqn(char **argv)
return -ENOENT;
}
+static int dcc_get_max_retries(void)
+{
+ if (dcc_backoff_is_enabled()) {
+ /* eventually distcc will either find a suitable host or mark
+ * all hosts as faulty (and fallback to a local compilation)
+ */
+ return 0; /* no limit */
+ } else {
+ return 3; /* somewhat arbitrary */
+ }
+}
+
/**
* Execute the commands in argv remotely or locally as appropriate.
*
@@ -692,10 +704,13 @@ dcc_build_somewhere(char *argv[],
int cpu_lock_fd = -1, local_cpu_lock_fd = -1;
int ret;
int remote_ret = 0;
+ int retry_count = 0, max_retries;
struct dcc_hostdef *host = NULL;
char *discrepancy_filename = NULL;
char **new_argv;
+ max_retries = dcc_get_max_retries();
+
if ((ret = dcc_expand_preprocessor_options(&argv)) != 0)
goto clean_up;
@@ -846,7 +861,14 @@ dcc_build_somewhere(char *argv[],
/* dcc_compile_remote() already unlocked local_cpu_lock_fd. */
local_cpu_lock_fd = -1;
bad_host(host, &cpu_lock_fd, &local_cpu_lock_fd);
- goto choose_host;
+ retry_count++;
+ if (max_retries == 0 || retry_count < max_retries)
+ goto choose_host;
+ else {
+ rs_log_warning("Couldn't find a host in %d attempts, retrying locally",
+ retry_count);
+ goto fallback;
+ }
}
/* dcc_compile_remote() already unlocked local_cpu_lock_fd. */
local_cpu_lock_fd = -1;
diff --git a/src/distcc.h b/src/distcc.h
index 4b94aec..d4f6334 100644
--- a/src/distcc.h
+++ b/src/distcc.h
@@ -190,6 +190,7 @@ int dcc_support_masquerade(char *argv[], char *progname, int *);
int dcc_enjoyed_host(const struct dcc_hostdef *host);
int dcc_disliked_host(const struct dcc_hostdef *host);
int dcc_remove_disliked(struct dcc_hostdef **hostlist);
+int dcc_backoff_is_enabled(void);