diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-09-29 10:45:20 +0200 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-09-29 17:03:23 +0200 |
commit | edb59d490737438baf15fff49ef6da21790a2b26 (patch) | |
tree | 4042d70754e69c4cf7369d97a541c5c167d05a28 | |
parent | ec5b9dc003c5490365f04bf2bf50951cc1d054e4 (diff) |
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.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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, |