Blame SOURCES/0001-Never-leave-behind-repodata-lock-on-exit-RhBug-1906831.patch

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