Skip to content
Snippets Groups Projects
Commit f48ca627 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

add svc_send_fdholder function

parent 60454703
No related branches found
No related tags found
No related merge requests found
......@@ -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) ;
}
}
/*
* 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) ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment