diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-09-30 10:17:07 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-09-30 10:17:07 +0000 |
commit | f44565234a719600bbd8dc66308bc7be2683a8a6 (patch) | |
tree | dd48ea192725a30b5e422a636824a8a083342eb0 | |
parent | ba7a742ff69c606f1ca36e96ed71fe37387f8ff2 (diff) | |
download | s6-rc-f44565234a719600bbd8dc66308bc7be2683a8a6.tar.xz |
Use mkdtemp() for the new livedir in s6-rc-update
-rw-r--r-- | src/s6-rc/s6-rc-update.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c index a6e7cfe..5dfd0d7 100644 --- a/src/s6-rc/s6-rc-update.c +++ b/src/s6-rc/s6-rc-update.c @@ -2,10 +2,12 @@ #include <string.h> #include <stdint.h> +#include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <skalibs/types.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> @@ -19,7 +21,6 @@ #include <skalibs/skamisc.h> #include <skalibs/webipc.h> #include <skalibs/unix-transactional.h> -#include <skalibs/random.h> #include <execline/execline.h> #include <s6/config.h> #include <s6/s6-supervise.h> @@ -30,6 +31,7 @@ #define USAGE "s6-rc-update [ -n ] [ -v verbosity ] [ -t timeout ] [ -l live ] [ -f conversion_file ] [ -b ] newdb" #define dieusage() strerr_dieusage(100, USAGE) #define dienomem() strerr_diefu1sys(111, "build string") ; +#define SUFFIX ":update:XXXXXX" static char const *live = S6RC_LIVE_BASE ; static size_t livelen = sizeof(S6RC_LIVE_BASE) - 1 ; @@ -333,9 +335,10 @@ static inline void make_new_livedir (unsigned char const *oldstate, s6rc_db_t co if (sareadlink(&satmp, live) < 0) strerr_diefu2sys(111, "readlink ", live) ; if (!s6rc_sanitize_dir(sa, live, &dirlen)) dienomem() ; llen = sa->len ; - if (!random_sauniquename(sa, 8) || !stralloc_0(sa)) dienomem() ; + if (!stralloc_catb(sa, SUFFIX, sizeof(SUFFIX))) dienomem() ; newlen = --sa->len ; - if (mkdir(sa->s + sabase, 0755) < 0) strerr_diefu2sys(111, "mkdir ", sa->s + sabase) ; + if (!mkdtemp(sa->s + sabase)) strerr_diefu2sys(111, "mkdtemp ", sa->s + sabase) ; + if (chmod(sa->s + sabase, 0755) < 0) { e = errno ; goto err ; } { size_t tmplen = satmp.len ; char fn[llen - sabase + 9] ; @@ -642,9 +645,6 @@ int main (int argc, char const *const *argv, char const *const *envp) strerr_dief2x(100, live, " is not an absolute path") ; livelen = strlen(live) ; - if (!random_init()) - strerr_diefu1sys(111, "init random generator") ; - { int livelock, oldlock, newlock ; int fdoldc, fdnewc ; |