From: Alberto Leiva Popper Date: Mon, 8 Nov 2021 22:06:18 +0000 (-0600) Subject: RRDP: Fix underutilization of the filename stack X-Git-Tag: 1.5.3~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5373f1edf4aead529762d3e65ca49e2e438ee10;p=thirdparty%2FFORT-validator.git RRDP: Fix underutilization of the filename stack Lots of error messages were referring to the wrong file, and several of them printed the correct file manually as what I can only describe as a quick workaround. It's not perfect; not all the RRDP code has been patched. That'll have to wait until the deep RRDP refactor. --- diff --git a/src/http/http.c b/src/http/http.c index 87312e37..147be88c 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -254,11 +254,11 @@ http_fetch(struct http_handler *handler, char const *uri, long *response_code, *response_code = http_code; if (res != CURLE_OK) { - pr_val_err("Error requesting URL %s: %s. (HTTP code: %ld)", - uri, curl_err_string(handler, res), http_code); + pr_val_err("Error requesting URL: %s. (HTTP code: %ld)", + curl_err_string(handler, res), http_code); if (log_operation) - pr_op_err("Error requesting URL %s: %s. (HTTP code: %ld)", - uri, curl_err_string(handler, res), http_code); + pr_op_err("Error requesting URL: %s. (HTTP code: %ld)", + curl_err_string(handler, res), http_code); switch (res) { case CURLE_FILESIZE_EXCEEDED: @@ -391,12 +391,11 @@ __http_download_file(struct rpki_uri *uri, long *response_code, long ims_value, if (retries == config_get_http_retry_count()) { if (retries > 0) - pr_val_warn("Max HTTP retries (%u) reached requesting for '%s', won't retry again.", - retries, uri_get_global(uri)); + pr_val_warn("Max HTTP retries (%u) reached. Won't retry again.", + retries); break; } - pr_val_warn("Retrying HTTP request '%s' in %u seconds, %u attempts remaining.", - uri_get_global(uri), + pr_val_warn("Retrying HTTP request in %u seconds. %u attempts remaining.", config_get_http_retry_interval(), config_get_http_retry_count() - retries); retries++; diff --git a/src/rrdp/rrdp_loader.c b/src/rrdp/rrdp_loader.c index 89fffc61..b43c48fa 100644 --- a/src/rrdp/rrdp_loader.c +++ b/src/rrdp/rrdp_loader.c @@ -197,7 +197,6 @@ __rrdp_load(struct rpki_uri *uri, bool force_snapshot, bool *data_updated) if (error) goto upd_end; - /* No updates at the file (yet), didn't pushed to fnstack */ if (upd_notification == NULL) { pr_val_debug("The Update Notification has not changed."); goto upd_end; @@ -274,10 +273,8 @@ set_update: uri_get_global(uri)); db_rrdp_uris_set_last_update(uri_get_global(uri)); upd_destroy: - if (upd_notification != NULL) { + if (upd_notification != NULL) update_notification_destroy(upd_notification); - fnstack_pop(); /* Pop from rrdp_parse_notification */ - } upd_end: /* Just return on success */ if (!error) { diff --git a/src/rrdp/rrdp_parser.c b/src/rrdp/rrdp_parser.c index 46808fa1..34d840ca 100644 --- a/src/rrdp/rrdp_parser.c +++ b/src/rrdp/rrdp_parser.c @@ -909,6 +909,8 @@ process_delta(struct delta_head *delta_head, void *arg) if (error) return error; + fnstack_push_uri(uri); + error = download_file(uri, 0, args->log_operation); if (error) goto release_uri; @@ -918,6 +920,7 @@ process_delta(struct delta_head *delta_head, void *arg) delete_from_uri(uri, NULL); /* Error 0 its ok */ release_uri: + fnstack_pop(); uri_refput(uri); return error; } @@ -942,21 +945,23 @@ rrdp_parse_notification(struct rpki_uri *uri, bool log_operation, bool force, if (uri == NULL || uri_is_rsync(uri)) pr_crit("Wrong call, trying to parse a non HTTPS URI"); - pr_val_debug("Processing notification '%s'.", uri_get_global(uri)); + fnstack_push_uri(uri); + pr_val_debug("Processing notification."); + last_update = 0; if (!force) { error = db_rrdp_uris_get_last_update(uri_get_global(uri), &last_update); if (error && error != -ENOENT) - return error; + goto end; } error = download_file(uri, last_update, log_operation); if (error < 0) - return error; + goto end; /* Request error, stop processing to handle as such */ if (error == EREQFAILED) - return error; + goto end; /* * Mark as visited, if it doesn't exists yet, there's no problem since @@ -965,26 +970,24 @@ rrdp_parse_notification(struct rpki_uri *uri, bool log_operation, bool force, */ vis_err = db_rrdp_uris_set_request_status(uri_get_global(uri), RRDP_URI_REQ_VISITED); - if (vis_err && vis_err != -ENOENT) - return pr_val_err("Couldn't mark '%s' as visited", - uri_get_global(uri)); + if (vis_err && vis_err != -ENOENT) { + error = pr_val_err("Couldn't mark file as visited."); + goto end; + } /* No updates yet */ if (error > 0) { delete_from_uri(uri, NULL); *result = NULL; - return 0; + error = 0; + goto end; } - fnstack_push_uri(uri); error = parse_notification(uri, result); - delete_from_uri(uri, NULL); - if (error) { - fnstack_pop(); - return error; - } - return 0; + delete_from_uri(uri, NULL); +end: fnstack_pop(); + return error; } int @@ -1004,6 +1007,8 @@ rrdp_parse_snapshot(struct update_notification *parent, if (error) return error; + fnstack_push_uri(uri); + error = download_file(uri, 0, log_operation); if (error) goto release_uri; @@ -1013,6 +1018,7 @@ rrdp_parse_snapshot(struct update_notification *parent, delete_from_uri(uri, NULL); /* Error 0 is ok */ release_uri: + fnstack_pop(); uri_refput(uri); return error; } diff --git a/src/thread_var.c b/src/thread_var.c index e6eab3fa..ab7a206d 100644 --- a/src/thread_var.c +++ b/src/thread_var.c @@ -153,6 +153,26 @@ fnstack_cleanup(void) * Any pr_op_err()s and friends will now include the new file name. * Use fnstack_pop() to revert back to the previously stacked file name. * @file is not cloned; it's expected to outlive the push/pop operation. + * + * Sample usage: + * + * void + * test_fnstack(void) + * { + * fnstack_push("text.txt"); + * pr_val_info("Message 1"); + * fnstack_push("image.png"); + * pr_val_info("Message 2"); + * fnstack_pop(); + * pr_val_info("Message 3"); + * fnstack_pop(); + * } + * + * Prints + * + * text.txt: Message 1 + * image.png: Message 2 + * text.txt: Message 3 */ void fnstack_push(char const *file)