summaryrefslogtreecommitdiff
path: root/src/fdholder/s6-fdholder-transferdump.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fdholder/s6-fdholder-transferdump.c')
-rw-r--r--src/fdholder/s6-fdholder-transferdump.c73
1 files changed, 27 insertions, 46 deletions
diff --git a/src/fdholder/s6-fdholder-transferdump.c b/src/fdholder/s6-fdholder-transferdump.c
index 9cd7ca8..83d1e80 100644
--- a/src/fdholder/s6-fdholder-transferdump.c
+++ b/src/fdholder/s6-fdholder-transferdump.c
@@ -1,26 +1,23 @@
/* ISC license. */
-#include <sys/types.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/env.h>
#include <skalibs/strerr2.h>
-#include <skalibs/djbunix.h>
-#include <execline/config.h>
-#include <s6/config.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/tai.h>
+#include <skalibs/genalloc.h>
+#include <s6/s6-fdholder.h>
#define USAGE "s6-fdholder-transferdump [ -t timeoutfrom:timeoutto ] socketfrom socketto"
#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[24] ;
- unsigned int timeoutfrom = 0, timeoutto = 0 ;
- unsigned int m = 0 ;
- char fmtfrom[UINT_FMT] ;
- char fmtto[UINT_FMT] ;
- PROG = "s6-fdholder-setdump" ;
+ s6_fdholder_t a = S6_FDHOLDER_ZERO ;
+ genalloc dump = GENALLOC_ZERO ; /* array of s6_fdholder_fd_t */
+ tain_t deadline, totto ;
+ PROG = "s6-fdholder-transferdump" ;
{
+ unsigned int timeoutfrom = 0, timeoutto = 0 ;
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
@@ -49,40 +46,24 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
}
argc -= l.ind ; argv += l.ind ;
+ if (timeoutfrom) tain_from_millisecs(&deadline, timeoutfrom) ;
+ else deadline = tain_infinite_relative ;
+ if (timeoutto) tain_from_millisecs(&totto, timeoutto) ;
+ else totto = tain_infinite_relative ;
}
if (argc < 2) dieusage() ;
- newargv[m++] = S6_BINPREFIX "s6-ipcclient" ;
- newargv[m++] = "-l0" ;
- newargv[m++] = "--" ;
- newargv[m++] = argv[0] ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ;
- newargv[m++] = "7" ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdmove" ;
- newargv[m++] = "0" ;
- newargv[m++] = "6" ;
- newargv[m++] = S6_BINPREFIX "s6-ipcclient" ;
- newargv[m++] = "-l0" ;
- newargv[m++] = "--" ;
- newargv[m++] = argv[1] ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ;
- newargv[m++] = "6" ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdmove" ;
- newargv[m++] = "1" ;
- newargv[m++] = "7" ;
- newargv[m++] = S6_BINPREFIX "s6-fdholder-transferdumpc" ;
- if (timeoutfrom)
- {
- fmtfrom[uint_fmt(fmtfrom, timeoutfrom)] = 0 ;
- newargv[m++] = "-t" ;
- newargv[m++] = fmtfrom ;
- }
- if (timeoutto)
- {
- fmtto[uint_fmt(fmtto, timeoutto)] = 0 ;
- newargv[m++] = "-T" ;
- newargv[m++] = fmtto ;
- }
- newargv[m++] = 0 ;
- xpathexec_run(newargv[0], newargv, envp) ;
+ tain_now_g() ;
+ tain_add_g(&deadline, &deadline) ;
+ if (!s6_fdholder_start_g(&a, argv[0], &deadline))
+ strerr_diefu2sys(111, "connect to a source fd-holder daemon at ", argv[0]) ;
+ if (!s6_fdholder_getdump_g(&a, &dump, &deadline))
+ strerr_diefu1sys(1, "get dump") ;
+ s6_fdholder_end(&a) ;
+ tain_add_g(&deadline, &totto) ;
+ if (!s6_fdholder_start_g(&a, argv[1], &deadline))
+ strerr_diefu2sys(111, "connect to a destination fd-holder daemon at ", argv[1]) ;
+ if (!s6_fdholder_setdump_g(&a, genalloc_s(s6_fdholder_fd_t, &dump), genalloc_len(s6_fdholder_fd_t, &dump), &deadline))
+ strerr_diefu1sys(1, "set dump") ;
+ return 0 ;
}