From edb59d490737438baf15fff49ef6da21790a2b26 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 29 Sep 2022 10:45:20 +0200 Subject: avoid useless retries when a fatal error occurs 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. --- src/main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') 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, -- cgit v1.2.3-18-g5258