Skip to content

Commit

Permalink
Failure_exit_cleanup uses global var instead of parameter it never got
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura authored and Conan-Kudo committed May 24, 2019
1 parent 6355d0f commit 0e26638
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/createrepo_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}

// Set exit_value pointer used in cleanup handlers
cr_set_global_exit_value(&exit_val);

// Setup cleanup handlers
if (!cr_set_cleanup_handler(lock_dir, tmp_out_repo, &tmp_err)) {
g_printerr("%s\n", tmp_err->message);
Expand Down
13 changes: 9 additions & 4 deletions src/createrepo_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "misc.h"
#include "cleanup.h"

int *global_exit_status = NULL; // pointer to exit_value used in failure_exit_cleanup

char *global_lock_dir = NULL; // Path to .repodata/ dir that is used as a lock
char *global_tmp_out_repo = NULL; // Path to temporary repodata directory,
Expand All @@ -40,13 +41,11 @@ char *global_tmp_out_repo = NULL; // Path to temporary repodata directory,
* for other createrepo[_c] processes.
* This functions acts only if exit status != EXIST_SUCCESS.
*
* @param exit_status Status
* @param data User data (unused)
*/
static void
failure_exit_cleanup(int exit_status, G_GNUC_UNUSED void *data)
failure_exit_cleanup()
{
if (exit_status != EXIT_SUCCESS) {
if (global_exit_status && *global_exit_status != EXIT_SUCCESS) {
if (global_lock_dir) {
g_debug("Removing %s", global_lock_dir);
cr_remove_dir(global_lock_dir, NULL);
Expand All @@ -69,6 +68,12 @@ sigint_catcher(int sig)
exit(1);
}

void
cr_set_global_exit_value(int *exit_val)
{
global_exit_status = exit_val;
}

gboolean
cr_set_cleanup_handler(const char *lock_dir,
const char *tmp_out_repo,
Expand Down
20 changes: 13 additions & 7 deletions src/createrepo_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ extern "C" {

/**
* This function does:
* 1) Sets atexit cleanup function that removes temporary directories
* 2) Sets a signal handler for signals that lead to process temination.
* (List obtained from the "man 7 signal")
* Signals that are ignored (SIGCHILD) or lead just to stop (SIGSTOP, ...)
* don't get this handler - these signals do not terminate the process!
* This handler assures that the cleanup function that is hooked on exit
* gets called.
* Sets a signal handler for signals that lead to process temination.
* (List obtained from the "man 7 signal")
* Signals that are ignored (SIGCHILD) or lead just to stop (SIGSTOP, ...)
* don't get this handler - these signals do not terminate the process!
* This handler assures that the cleanup function that is hooked on exit
* gets called.
*
* @param lock_dir Dir that serves as lock (".repodata/")
* @param tmp_out_repo Dir that is really used for repodata generation
Expand Down Expand Up @@ -121,6 +120,13 @@ cr_unset_cleanup_handler(GError **err);
void
cr_setup_logging(gboolean quiet, gboolean verbose);

/**
* Set global pointer to exit value that is used in function set by atexit
* @param exit_val Pointer to exit_value int
*/
void
cr_set_global_exit_value(int *exit_val);

/** @} */

#ifdef __cplusplus
Expand Down

0 comments on commit 0e26638

Please sign in to comment.