skaclient_startf_async.c (1350B)
1 /* ISC license. */ 2 3 #include <errno.h> 4 #include <signal.h> 5 6 #include <skalibs/cspawn.h> 7 #include <skalibs/djbunix.h> 8 #include <skalibs/kolbak.h> 9 #include <skalibs/skaclient.h> 10 #include "skaclient-internal.h" 11 12 int skaclient_startf_async ( 13 skaclient *a, 14 char *bufss, 15 size_t bufsn, 16 char *auxbufss, 17 size_t auxbufsn, 18 char *bufas, 19 size_t bufan, 20 char *auxbufas, 21 size_t auxbufan, 22 kolbak_closure *q, 23 size_t qlen, 24 char const *prog, 25 char const *const *argv, 26 char const *const *envp, 27 uint32_t options, 28 char const *before, 29 size_t beforelen, 30 char const *after, 31 size_t afterlen, 32 skaclient_cbdata *blah) 33 { 34 int fd ; 35 pid_t pid = child_spawn1_socket(prog, argv, envp, &fd) ; 36 if (!pid) return 0 ; 37 if (ndelay_on(fd) < 0 38 || coe(fd) < 0 39 || !skaclient_init(a, fd, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, before, beforelen)) 40 { 41 fd_close(fd) ; 42 if (options & SKACLIENT_OPTION_WAITPID) 43 { 44 int e = errno ; 45 int wstat ; 46 waitpid_nointr(a->pid, &wstat, 0) ; 47 errno = e ; 48 } 49 return 0 ; 50 } 51 a->pid = pid ; 52 a->options = options ; 53 if (!kolbak_enqueue(&a->kq, (unixmessage_handler_func_ref)&skaclient_start_cb, blah)) 54 { 55 skaclient_end(a) ; 56 return 0 ; 57 } 58 blah->a = a ; 59 blah->after = after ; 60 blah->afterlen = afterlen ; 61 return 1 ; 62 }