summaryrefslogtreecommitdiff
path: root/src/fdholder/s6-fdholder-store.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-07-03 12:43:13 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-07-03 12:43:13 +0000
commit1d69f26f58e72ceaab5aeda7df874faf7b46a5f3 (patch)
tree7c5551b0210f44de4e4b8188e20712edab505fab /src/fdholder/s6-fdholder-store.c
parentdaef3467ef868740c1dc8d89f11c04b91b3fdb47 (diff)
downloads6-1d69f26f58e72ceaab5aeda7df874faf7b46a5f3.tar.xz
Remove s6-fdholder-*c programs
The doc still needs to be updated.
Diffstat (limited to 'src/fdholder/s6-fdholder-store.c')
-rw-r--r--src/fdholder/s6-fdholder-store.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/fdholder/s6-fdholder-store.c b/src/fdholder/s6-fdholder-store.c
index 7404bac..75510d2 100644
--- a/src/fdholder/s6-fdholder-store.c
+++ b/src/fdholder/s6-fdholder-store.c
@@ -1,24 +1,22 @@
/* ISC license. */
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
-#include <skalibs/djbunix.h>
-#include <s6/config.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/tai.h>
+#include <s6/s6-fdholder.h>
#define USAGE "s6-fdholder-store [ -d fd ] [ -t timeout ] [ -T fdtimeout ] socket id"
#define dieusage() strerr_dieusage(100, USAGE)
-int main (int argc, char const *const *argv, char const *const *envp)
+int main (int argc, char const *const *argv)
{
- char const *newargv[12] ;
- unsigned int timeout = 0, limit = 0 ;
- unsigned int m = 0 ;
- char fmtt[UINT_FMT] ;
- char fmtl[UINT_FMT] ;
+ s6_fdholder_t a = S6_FDHOLDER_ZERO ;
+ tain_t deadline, limit ;
+ unsigned int fd = 0 ;
PROG = "s6-fdholder-store" ;
{
- unsigned int fd = 0 ;
+ unsigned int t = 0, T = 0 ;
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
@@ -27,36 +25,25 @@ int main (int argc, char const *const *argv, char const *const *envp)
switch (opt)
{
case 'd' : if (!uint0_scan(l.arg, &fd)) dieusage() ; break ;
- case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ;
- case 'T' : if (!uint0_scan(l.arg, &limit)) dieusage() ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ case 'T' : if (!uint0_scan(l.arg, &T)) dieusage() ; break ;
default : dieusage() ;
}
}
argc -= l.ind ; argv += l.ind ;
- if (argc < 2) dieusage() ;
- if (fd && fd_move(0, fd) < 0)
- strerr_diefu1sys(111, "move file descriptor") ;
+ if (t) tain_from_millisecs(&deadline, t) ;
+ else deadline = tain_infinite_relative ;
+ if (T) tain_from_millisecs(&limit, T) ;
+ else limit = tain_infinite_relative ;
}
+ if (argc < 2) dieusage() ;
- newargv[m++] = S6_BINPREFIX "s6-ipcclient" ;
- newargv[m++] = "-l0" ;
- newargv[m++] = "--" ;
- newargv[m++] = argv[0] ;
- newargv[m++] = S6_BINPREFIX "s6-fdholder-storec" ;
- if (timeout)
- {
- fmtt[uint_fmt(fmtt, timeout)] = 0 ;
- newargv[m++] = "-t" ;
- newargv[m++] = fmtt ;
- }
- if (limit)
- {
- fmtl[uint_fmt(fmtl, limit)] = 0 ;
- newargv[m++] = "-T" ;
- newargv[m++] = fmtl ;
- }
- newargv[m++] = "--" ;
- newargv[m++] = argv[1] ;
- newargv[m++] = 0 ;
- xpathexec_run(newargv[0], newargv, envp) ;
+ tain_now_g() ;
+ tain_add_g(&deadline, &deadline) ;
+ tain_add_g(&limit, &limit) ;
+ if (!s6_fdholder_start_g(&a, argv[0], &deadline))
+ strerr_diefu2sys(111, "connect to a fd-holder daemon at ", argv[0]) ;
+ if (!s6_fdholder_store_g(&a, fd, argv[1], &limit, &deadline))
+ strerr_diefu1sys(1, "store fd") ;
+ return 0 ;
}