aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo/s6-rc-repo-init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo/s6-rc-repo-init.c')
-rw-r--r--src/repo/s6-rc-repo-init.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/repo/s6-rc-repo-init.c b/src/repo/s6-rc-repo-init.c
index c18b7a3..6c8a7fa 100644
--- a/src/repo/s6-rc-repo-init.c
+++ b/src/repo/s6-rc-repo-init.c
@@ -16,6 +16,7 @@
#include <skalibs/gol.h>
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
+#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <skalibs/random.h>
#include <skalibs/unix-transactional.h>
@@ -88,6 +89,7 @@ int main (int argc, char const *const *argv)
strerr_dief1x(100, "stores cannot contain newlines in their path") ;
}
repolen = strlen(wgola[GOLA_REPODIR]) ;
+ tain_now_g() ;
if (!(wgolb & GOLB_UPDATE))
{
@@ -128,14 +130,6 @@ int main (int argc, char const *const *argv)
strerr_diefu2sys(111, "mkdir ", tmp) ;
}
- memcpy(tmp + repolen + 12, "stores", 7) ;
- if (mkdir(tmp, 02755) == -1)
- {
- cleanup(repotmp) ;
- strerr_diefu2sys(111, "mkdir ", tmp) ;
- }
- umask(m) ;
-
memcpy(tmp + repolen + 12, "lock", 5) ;
if (!openwritenclose_unsafe5(tmp, "", 0, 0, 0))
{
@@ -175,6 +169,7 @@ int main (int argc, char const *const *argv)
}
}
}
+ umask(m) ;
}
lockfd = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
@@ -192,19 +187,22 @@ int main (int argc, char const *const *argv)
int r = s6rc_repo_sync(wgola[GOLA_REPODIR], verbosity, wgola[GOLA_FDHUSER]) ;
if (r <= 0)
{
- char stores[repolen + 8] ;
- char snew[repolen + 16] ;
- memcpy(stores, wgola[GOLA_REPODIR], repolen) ;
- memcpy(stores + repolen, "/stores", 8) ;
- memcpy(snew, wgola[GOLA_REPODIR], repolen) ;
- snew[repolen] = '/' ;
- if (!atomic_symlink4(sold + repolen + 1, stores, snew + repolen + 1, 15))
- strerr_diefu7sys(111, "atomically switch back stores at ", wgola[GOLA_REPODIR], " - old store is ", sold + repolen + 1, " and new (invalid) store is ", snew + repolen + 1, " - reported error was") ;
- rm_rf(snew) ;
+ if (sold[repolen+1])
+ {
+ char stores[repolen + 8] ;
+ char snew[repolen + 16] ;
+ memcpy(stores, wgola[GOLA_REPODIR], repolen) ;
+ memcpy(stores + repolen, "/stores", 8) ;
+ memcpy(snew, wgola[GOLA_REPODIR], repolen) ;
+ snew[repolen] = '/' ;
+ if (!atomic_symlink4(sold + repolen + 1, stores, snew + repolen + 1, 15))
+ strerr_diefu7sys(111, "atomically switch back stores at ", wgola[GOLA_REPODIR], " - old store is ", sold + repolen + 1, " and new (invalid) store is ", snew + repolen + 1, " - reported error was") ;
+ rm_rf(snew) ;
+ }
_exit(r ? 111 : 1) ;
}
}
- rm_rf(sold) ;
+ if (sold[repolen+1]) rm_rf(sold) ;
_exit(0) ;
}