diff --git a/src/lib66/sanitize/sanitize_fdholder.c b/src/lib66/sanitize/sanitize_fdholder.c index af220ee26e9aa4a1c1bd669ffa3f834312402cb8..28017396dc3a5b5ef12e7b4b947e8c18dac8a4dc 100644 --- a/src/lib66/sanitize/sanitize_fdholder.c +++ b/src/lib66/sanitize/sanitize_fdholder.c @@ -30,6 +30,7 @@ #include <66/constants.h> #include <66/state.h> #include <66/enum.h> +#include <66/svc.h> #include <s6/fdholder.h> @@ -55,7 +56,6 @@ void sanitize_fdholder(resolve_service_t *res, uint32_t flag) s6_fdholder_t a = S6_FDHOLDER_ZERO ; tain deadline = tain_infinite_relative, limit = tain_infinite_relative ; - unsigned int fd ; char fdname[SS_FDHOLDER_PIPENAME_LEN + 2 + namelen + 1] ; char sock[socketlen + 3] ; @@ -70,17 +70,30 @@ void sanitize_fdholder(resolve_service_t *res, uint32_t flag) if (FLAGS_ISSET(flag, STATE_FLAGS_TRUE)) { + int fd[2] ; + if (pipe(fd) < 0) + log_dieu(LOG_EXIT_SYS, "pipe") ; + auto_strings(fdname, SS_FDHOLDER_PIPENAME, "r-", name) ; log_trace("store identifier: ", fdname) ; - if (!s6_fdholder_store_g(&a, fd, fdname, &limit, &deadline)) + if (!s6_fdholder_store_g(&a, fd[0], fdname, &limit, &deadline)) { + close(fd[0]) ; + close(fd[1]) ; log_dieusys(LOG_EXIT_SYS, "store fd: ", fdname) ; + } + + close(fd[0]) ; fdname[strlen(SS_FDHOLDER_PIPENAME)] = 'w' ; log_trace("store identifier: ", fdname) ; - if (!s6_fdholder_store_g(&a, fd, fdname, &limit, &deadline)) + if (!s6_fdholder_store_g(&a, fd[1], fdname, &limit, &deadline)) { + close(fd[1]) ; log_dieusys(LOG_EXIT_SYS, "store fd: ", fdname) ; + } + + close(fd[1]) ; } else if (FLAGS_ISSET(flag, STATE_FLAGS_FALSE)) { @@ -127,6 +140,8 @@ void sanitize_fdholder(resolve_service_t *res, uint32_t flag) if (!openwritenclose_unsafe(file, list.s, list.len)) log_dieusys(LOG_EXIT_SYS, "write file: ", file) ; + svc_send_fdholder(socket) ; + stralloc_free(&list) ; } } diff --git a/src/lib66/svc/svc_send_fdholder.c b/src/lib66/svc/svc_send_fdholder.c new file mode 100644 index 0000000000000000000000000000000000000000..63124b8e9c2158d8d4730dc6d429daaaed8a5701 --- /dev/null +++ b/src/lib66/svc/svc_send_fdholder.c @@ -0,0 +1,54 @@ +/* + * svc_send_fdholder.c + * + * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <stdlib.h> + +#include <oblibs/log.h> + +#include <skalibs/types.h> +#include <skalibs/djbunix.h> + +#include <66/svc.h> + + +void svc_send_fdholder(char const *socket) +{ + log_flow() ; + + char tfmt[UINT32_FMT] ; + tfmt[uint_fmt(tfmt, 3000)] = 0 ; + pid_t pid ; + int wstat ; + + char const *newargv[8] ; + unsigned int m = 0 ; + + newargv[m++] = "s6-svc" ; + newargv[m++] = "-twR" ; + newargv[m++] = "-T" ; + newargv[m++] = tfmt ; + newargv[m++] = "--" ; + newargv[m++] = socket ; + newargv[m++] = 0 ; + + log_trace("sending -twR signal to: ", socket) ; + + pid = child_spawn0(newargv[0], newargv, (char const *const *) environ) ; + + if (waitpid_nointr(pid, &wstat, 0) < 0) + log_dieusys(LOG_EXIT_SYS, "wait for reload of the fdholder daemon") ; + + if (wstat) + log_dieu(LOG_EXIT_SYS, "reload fdholder service; ", socket) ; +}