Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Give stdout back from a slot in one place
Diffstat (limited to 'source/cache.c')
-rw-r--r--source/cache.c21
1 file changed, 11 insertions, 10 deletions
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;