diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/s6-rc/deps-exe/s6-rc-format-upgrade | 2 | ||||
-rw-r--r-- | src/s6-rc/s6-rc-format-upgrade.c | 70 | ||||
-rw-r--r-- | src/s6-rc/s6-rc-update.c | 19 |
3 files changed, 75 insertions, 16 deletions
diff --git a/src/s6-rc/deps-exe/s6-rc-format-upgrade b/src/s6-rc/deps-exe/s6-rc-format-upgrade new file mode 100644 index 0000000..152b051 --- /dev/null +++ b/src/s6-rc/deps-exe/s6-rc-format-upgrade @@ -0,0 +1,2 @@ +${LIBS6RC} +-lskarnet diff --git a/src/s6-rc/s6-rc-format-upgrade.c b/src/s6-rc/s6-rc-format-upgrade.c new file mode 100644 index 0000000..3b399e3 --- /dev/null +++ b/src/s6-rc/s6-rc-format-upgrade.c @@ -0,0 +1,70 @@ +/* ISC license. */ + +#include <string.h> +#include <skalibs/types.h> +#include <skalibs/strerr2.h> +#include <skalibs/sgetopt.h> +#include <skalibs/tai.h> +#include <skalibs/unix-transactional.h> +#include <s6-rc/config.h> +#include <s6-rc/s6rc.h> + +#define USAGE "s6-rc-format-upgrade [ -v verbosity ] [ -t timeout ] [ -l live ] [ -b ] newdb" +#define dieusage() strerr_dieusage(100, USAGE) + +static unsigned int verbosity = 1 ; + + + /* This function will change if format changes become heavier */ + +static inline void update_livedir (char const *live, char const *newcompiled, tain_t const *deadline) +{ + size_t livelen = strlen(live) ; + char cfn[livelen + 10] ; + memcpy(cfn, live, livelen) ; + memcpy(cfn + livelen, "/compiled", 10) ; + if (!atomic_symlink(newcompiled, cfn, PROG)) + strerr_diefu4sys(111, "atomic_symlink ", cfn, " to ", newcompiled) ; +} + + +int main (int argc, char const *const *argv, char const *const *envp) +{ + tain_t deadline ; + char const *live = S6RC_LIVE_BASE ; + int blocking = 0 ; + int livelock ; + PROG = "s6-rc-format-upgrade" ; + { + unsigned int t = 0 ; + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "v:t:l:b", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; + case 'l' : live = l.arg ; break ; + case 'b' : blocking = 1 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (t) tain_from_millisecs(&deadline, t) ; + else deadline = tain_infinite_relative ; + } + if (!argc) dieusage() ; + if (argv[0][0] != '/') + strerr_dief2x(100, argv[0], " is not an absolute path") ; + + tain_now_g() ; + tain_add_g(&deadline, &deadline) ; + + if (!s6rc_lock(live, 2, &livelock, 0, 0, 0, blocking)) + strerr_diefu2sys(111, "take lock on ", live) ; + + update_livedir(live, argv[0], &deadline) ; + return 0 ; +} diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c index dc3806b..0313f1e 100644 --- a/src/s6-rc/s6-rc-update.c +++ b/src/s6-rc/s6-rc-update.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <skalibs/nonposix.h> /* Solaris doesn't know mkdtemp() is POSIX */ #include <string.h> #include <stdint.h> #include <limits.h> @@ -21,7 +20,6 @@ #include <skalibs/tai.h> #include <skalibs/djbunix.h> #include <skalibs/skamisc.h> -#include <skalibs/webipc.h> #include <skalibs/unix-transactional.h> #include <execline/execline.h> #include <s6/config.h> @@ -516,31 +514,20 @@ static void fill_tfmt (char *tfmt, tain_t const *deadline) static inline void update_fdholder (s6rc_db_t const *olddb, unsigned char const *oldstate, s6rc_db_t const *newdb, unsigned char const *newstate, unsigned int const *invimage, char const *const *envp, tain_t const *deadline) { - int fdsocket ; s6_fdholder_t a = S6_FDHOLDER_ZERO ; char fnsocket[livelen + sizeof("/servicedirs/" S6RC_FDHOLDER "/s")] ; if (!(newstate[1] & 1)) return ; memcpy(fnsocket, live, livelen) ; memcpy(fnsocket + livelen, "/servicedirs/" S6RC_FDHOLDER "/s", sizeof("/servicedirs/" S6RC_FDHOLDER "/s")) ; - fdsocket = ipc_stream_nb() ; - if (fdsocket < 0) goto hammer ; - if (!ipc_timed_connect_g(fdsocket, fnsocket, deadline)) - { - if (errno == ETIMEDOUT) strerr_dief1x(2, "timed out during s6rc-fdholder update") ; - else goto closehammer ; - } - s6_fdholder_init(&a, fdsocket) ; + if (!s6_fdholder_start_g(&a, fnsocket, deadline)) goto hammer ; if (!delete_unused_pipes(&a, olddb, oldstate, deadline)) goto freehammer ; if (!rename_pipes(&a, olddb, newdb, newstate, invimage, deadline)) goto freehammer ; if (!create_new_pipes(&a, newdb, newstate, deadline)) goto freehammer ; - s6_fdholder_free(&a) ; - close(fdsocket) ; + s6_fdholder_end(&a) ; return ; freehammer: - s6_fdholder_free(&a) ; - closehammer: - close(fdsocket) ; + s6_fdholder_end(&a) ; hammer: if (verbosity) strerr_warnwu1x("live update s6rc-fdholder - restarting it") ; { |