summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-09-29 10:45:20 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-09-29 17:03:23 +0200
commitedb59d490737438baf15fff49ef6da21790a2b26 (patch)
tree4042d70754e69c4cf7369d97a541c5c167d05a28
parentec5b9dc003c5490365f04bf2bf50951cc1d054e4 (diff)
avoid useless retries when a fatal error occursHEADv1.0.0master
Adds "fatal" bool field to struct tip_client. Fatal is looked for when cli->error is set, if fatal is set then no retry is done and tiptorrent-client should terminate.
-rw-r--r--src/main.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 85f2969..961b650 100644
--- a/src/main.c
+++ b/src/main.c
@@ -61,6 +61,7 @@ struct tip_client {
int num_retries;
int fd;
bool error;
+ bool fatal;
bool redirected;
bool server_only;
struct timeval tv_start, tv_last;
@@ -289,6 +290,7 @@ static int tip_client_head_hdr(struct tip_client *cli)
syslog(LOG_ERR, "failed to allocate room for file %s: %s",
filename, strerror(errno));
delete_file(filename);
+ cli->fatal = true;
return -1;
}
@@ -501,6 +503,10 @@ static int tip_client_request_file(struct tip_client *cli,
ev_loop(tip_main_loop, 0);
if (cli->error) {
+ if (cli->fatal) {
+ syslog(LOG_ERR, "Fatal error, bailing out!\n");
+ return -1;
+ }
syslog(LOG_ERR, "Failed to fetch file %s\n", filename);
sleep(WAIT_RETRY);
if (cli->num_retries++ >= MAX_RETRIES) {
@@ -581,7 +587,7 @@ int main(int argc, char *argv[])
} while (ret > 0);
if (ret < 0)
- goto err_max_retries;
+ goto err_bailout;
if (_cli.state != TIP_CLIENT_DONE)
goto err;
@@ -613,7 +619,7 @@ int main(int argc, char *argv[])
}
if (ret < 0)
- goto err_max_retries;
+ goto err_bailout;
if (_cli.redirected)
tip_client_stats.redirects++;
@@ -655,7 +661,10 @@ err:
tip_client_stats.redirects);
return EXIT_FAILURE;
-err_max_retries:
+err_bailout:
+ if (_cli.fatal)
+ return EXIT_FAILURE;
+
syslog(LOG_INFO, "Failure after maximum number of retries. "
"Direct from server: %u Redirected: %u\n",
tip_client_stats.direct_from_server,