From f730657ef5dcca5188d856dfaa91ce29f546f665 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:37:58 -0700 Subject: Give stdout back from a slot in one place --- source/cache.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/cache.c b/source/cache.c index be1a3c9..4802ab5 100644 --- a/source/cache.c +++ b/source/cache.c @@ -238,6 +238,15 @@ static int lock_slot(struct cache_slot *slot) return 0; } +static void restore_stdout(struct cache_slot *slot) +{ + if (slot->saved_stdout >= 0) { + dup2(slot->saved_stdout, STDOUT_FILENO); + close(slot->saved_stdout); + slot->saved_stdout = -1; + } +} + static int unlock_slot(struct cache_slot *slot, int replace_old_slot) { int err; @@ -247,11 +256,7 @@ static int unlock_slot(struct cache_slot *slot, int replace_old_slot) else err = unlink(slot->lock_path); - if (slot->saved_stdout >= 0) { - dup2(slot->saved_stdout, STDOUT_FILENO); - close(slot->saved_stdout); - slot->saved_stdout = -1; - } + restore_stdout(slot); if (err) return errno; @@ -295,11 +300,7 @@ int cache_abandon_fill(void) // caller that could not write it must not try again here. fflush(stdout); - if (slot->saved_stdout >= 0) { - dup2(slot->saved_stdout, STDOUT_FILENO); - close(slot->saved_stdout); - slot->saved_stdout = -1; - } + restore_stdout(slot); replay_lock_file(slot); unlink(slot->lock_path); return 1; -- cgit