|
|
fa515f |
From e21b038a231e2743e30915af9575b8c43e9fda1f Mon Sep 17 00:00:00 2001
|
|
|
fa515f |
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
|
|
|
fa515f |
Date: Tue, 15 Dec 2020 14:15:39 +0100
|
|
|
fa515f |
Subject: [PATCH] Never leave behind .repodata lock on exit (RhBug:1906831
|
|
|
fa515f |
|
|
|
fa515f |
createrepo_c was removing `.repodata` if `exit_val` was se to failure.
|
|
|
fa515f |
Problem is `exit_val` is set only on a couple of places so most of the
|
|
|
fa515f |
failures (no matter how rare) leave `.repodata` behind.
|
|
|
fa515f |
|
|
|
fa515f |
However because on a successful run `.repodata` is renamed to normal
|
|
|
fa515f |
output `repodata` we know that if `.repodata` are present there was an
|
|
|
fa515f |
error and we can delete them.
|
|
|
fa515f |
---
|
|
|
fa515f |
src/createrepo_c.c | 5 +----
|
|
|
fa515f |
src/createrepo_shared.c | 29 +++++++++--------------------
|
|
|
fa515f |
2 files changed, 10 insertions(+), 24 deletions(-)
|
|
|
fa515f |
|
|
|
fa515f |
diff --git a/src/createrepo_c.c b/src/createrepo_c.c
|
|
|
fa515f |
index 8c90ebd..eeb871c 100644
|
|
|
fa515f |
--- a/src/createrepo_c.c
|
|
|
fa515f |
+++ b/src/createrepo_c.c
|
|
|
fa515f |
@@ -665,9 +665,6 @@ main(int argc, char **argv)
|
|
|
fa515f |
exit(EXIT_FAILURE);
|
|
|
fa515f |
}
|
|
|
fa515f |
|
|
|
fa515f |
- // Set exit_value pointer used in cleanup handlers
|
|
|
fa515f |
- cr_set_global_exit_value(&exit_val);
|
|
|
fa515f |
-
|
|
|
fa515f |
// Setup cleanup handlers
|
|
|
fa515f |
if (!cr_set_cleanup_handler(lock_dir, tmp_out_repo, &tmp_err)) {
|
|
|
fa515f |
g_printerr("%s\n", tmp_err->message);
|
|
|
fa515f |
@@ -885,7 +882,7 @@ main(int argc, char **argv)
|
|
|
fa515f |
char *moduleindex_str = modulemd_module_index_dump_to_string (moduleindex, &tmp_err);
|
|
|
fa515f |
g_clear_pointer(&moduleindex, g_object_unref);
|
|
|
fa515f |
if (tmp_err) {
|
|
|
fa515f |
- g_critical("%s: Cannot cannot dump module index: %s", __func__, tmp_err->message);
|
|
|
fa515f |
+ g_critical("%s: Cannot dump module index: %s", __func__, tmp_err->message);
|
|
|
fa515f |
free(moduleindex_str);
|
|
|
fa515f |
g_clear_error(&tmp_err);
|
|
|
fa515f |
exit(EXIT_FAILURE);
|
|
|
fa515f |
diff --git a/src/createrepo_shared.c b/src/createrepo_shared.c
|
|
|
fa515f |
index f8ef998..d1a37bd 100644
|
|
|
fa515f |
--- a/src/createrepo_shared.c
|
|
|
fa515f |
+++ b/src/createrepo_shared.c
|
|
|
fa515f |
@@ -28,8 +28,6 @@
|
|
|
fa515f |
#include "misc.h"
|
|
|
fa515f |
#include "cleanup.h"
|
|
|
fa515f |
|
|
|
fa515f |
-int *global_exit_status = NULL; // pointer to exit_value used in failure_exit_cleanup
|
|
|
fa515f |
-
|
|
|
fa515f |
char *global_lock_dir = NULL; // Path to .repodata/ dir that is used as a lock
|
|
|
fa515f |
char *global_tmp_out_repo = NULL; // Path to temporary repodata directory,
|
|
|
fa515f |
// if NULL that it's same as
|
|
|
fa515f |
@@ -43,18 +41,16 @@ char *global_tmp_out_repo = NULL; // Path to temporary repodata directory,
|
|
|
fa515f |
*
|
|
|
fa515f |
*/
|
|
|
fa515f |
static void
|
|
|
fa515f |
-failure_exit_cleanup()
|
|
|
fa515f |
+exit_cleanup()
|
|
|
fa515f |
{
|
|
|
fa515f |
- if (global_exit_status && *global_exit_status != EXIT_SUCCESS) {
|
|
|
fa515f |
- if (global_lock_dir) {
|
|
|
fa515f |
- g_debug("Removing %s", global_lock_dir);
|
|
|
fa515f |
- cr_remove_dir(global_lock_dir, NULL);
|
|
|
fa515f |
- }
|
|
|
fa515f |
+ if (global_lock_dir) {
|
|
|
fa515f |
+ g_debug("Removing %s", global_lock_dir);
|
|
|
fa515f |
+ cr_remove_dir(global_lock_dir, NULL);
|
|
|
fa515f |
+ }
|
|
|
fa515f |
|
|
|
fa515f |
- if (global_tmp_out_repo) {
|
|
|
fa515f |
- g_debug("Removing %s", global_tmp_out_repo);
|
|
|
fa515f |
- cr_remove_dir(global_tmp_out_repo, NULL);
|
|
|
fa515f |
- }
|
|
|
fa515f |
+ if (global_tmp_out_repo) {
|
|
|
fa515f |
+ g_debug("Removing %s", global_tmp_out_repo);
|
|
|
fa515f |
+ cr_remove_dir(global_tmp_out_repo, NULL);
|
|
|
fa515f |
}
|
|
|
fa515f |
}
|
|
|
fa515f |
|
|
|
fa515f |
@@ -65,16 +61,9 @@ static void
|
|
|
fa515f |
sigint_catcher(int sig)
|
|
|
fa515f |
{
|
|
|
fa515f |
g_message("%s caught: Terminating...", strsignal(sig));
|
|
|
fa515f |
- *global_exit_status = 1;
|
|
|
fa515f |
exit(1);
|
|
|
fa515f |
}
|
|
|
fa515f |
|
|
|
fa515f |
-void
|
|
|
fa515f |
-cr_set_global_exit_value(int *exit_val)
|
|
|
fa515f |
-{
|
|
|
fa515f |
- global_exit_status = exit_val;
|
|
|
fa515f |
-}
|
|
|
fa515f |
-
|
|
|
fa515f |
gboolean
|
|
|
fa515f |
cr_set_cleanup_handler(const char *lock_dir,
|
|
|
fa515f |
const char *tmp_out_repo,
|
|
|
fa515f |
@@ -90,7 +79,7 @@ cr_set_cleanup_handler(const char *lock_dir,
|
|
|
fa515f |
global_tmp_out_repo = NULL;
|
|
|
fa515f |
|
|
|
fa515f |
// Register on exit cleanup function
|
|
|
fa515f |
- if (atexit(failure_exit_cleanup))
|
|
|
fa515f |
+ if (atexit(exit_cleanup))
|
|
|
fa515f |
g_warning("Cannot set exit cleanup function by atexit()");
|
|
|
fa515f |
|
|
|
fa515f |
// Prepare signal handler configuration
|