summaryrefslogtreecommitdiff
path: root/src/fdholder/s6-fdholder-retrieve.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fdholder/s6-fdholder-retrieve.c')
-rw-r--r--src/fdholder/s6-fdholder-retrieve.c52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/fdholder/s6-fdholder-retrieve.c b/src/fdholder/s6-fdholder-retrieve.c
index de98612..dacc072 100644
--- a/src/fdholder/s6-fdholder-retrieve.c
+++ b/src/fdholder/s6-fdholder-retrieve.c
@@ -1,21 +1,24 @@
/* ISC license. */
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
-#include <execline/config.h>
-#include <s6/config.h>
+#include <s6/s6-fdholder.h>
#define USAGE "s6-fdholder-retrieve [ -D ] [ -t timeout ] socket id prog..."
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv, char const *const *envp)
{
- unsigned int timeout = 0 ;
+ s6_fdholder_t a = S6_FDHOLDER_ZERO ;
+ tain_t deadline ;
+ int fd ;
int dodelete = 0 ;
PROG = "s6-fdholder-retrieve" ;
{
+ unsigned int t = 0 ;
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
@@ -24,38 +27,27 @@ int main (int argc, char const *const *argv, char const *const *envp)
switch (opt)
{
case 'D' : dodelete = 1 ; break ;
- case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ;
+ case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
default : dieusage() ;
}
}
argc -= l.ind ; argv += l.ind ;
- if (argc < 3) dieusage() ;
+ if (t) tain_from_millisecs(&deadline, t) ;
+ else deadline = tain_infinite_relative ;
}
+ if (argc < 3) dieusage() ;
+ tain_now_g() ;
+ tain_add_g(&deadline, &deadline) ;
+ if (!s6_fdholder_start_g(&a, argv[0], &deadline))
+ strerr_diefu2sys(111, "connect to a fd-holder daemon at ", argv[0]) ;
+ fd = s6_fdholder_retrieve_maybe_delete_g(&a, argv[1], dodelete, &deadline) ;
+ if (fd < 0) strerr_diefu2sys(1, "retrieve fd for id ", argv[1]) ;
+ s6_fdholder_end(&a) ;
+ if (!fd)
{
- char const *newargv[13 + argc] ;
- unsigned int m = 0 ;
- char fmtt[UINT_FMT] ;
- newargv[m++] = S6_BINPREFIX "s6-ipcclient" ;
- newargv[m++] = "-l0" ;
- newargv[m++] = "--" ;
- newargv[m++] = *argv++ ;
- newargv[m++] = S6_BINPREFIX "s6-fdholder-retrievec" ;
- if (dodelete) newargv[m++] = "-D" ;
- if (timeout)
- {
- fmtt[uint_fmt(fmtt, timeout)] = 0 ;
- newargv[m++] = "-t" ;
- newargv[m++] = fmtt ;
- }
- newargv[m++] = "--" ;
- newargv[m++] = *argv++ ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ;
- newargv[m++] = "6" ;
- newargv[m++] = EXECLINE_EXTBINPREFIX "fdclose" ;
- newargv[m++] = "7" ;
- while (*argv) newargv[m++] = *argv++ ;
- newargv[m++] = 0 ;
- xpathexec_run(newargv[0], newargv, envp) ;
+ if (uncoe(0) < 0) strerr_diefu1sys(111, "uncoe stdin") ;
}
+ else if (fd_move(0, fd) < 0) strerr_diefu1sys(111, "move fd") ;
+ xpathexec_run(argv[2], argv+2, envp) ;
}