skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

child_spawn1_internal.c (724B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/djbunix.h>
      4 #include <skalibs/cspawn.h>
      5 #include "cspawn-internal.h"
      6 
      7 pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to)
      8 {
      9   pid_t pid ;
     10   cspawn_fileaction fa[3] =
     11   {
     12     [0] = { .type = CSPAWN_FA_CLOSE, .x = { .fd = p[!(to & 1)]} },
     13     [1] = { .type = CSPAWN_FA_MOVE, .x = { .fd2 = { [0] = to & 1, [1] = p[to & 1] } } },
     14     [2] = { .type = CSPAWN_FA_COPY, .x = { .fd2 = { [0] = !(to & 1), [1] = to & 1 } } }
     15   } ;
     16 
     17   pid = cspawn(prog, argv, envp, CSPAWN_FLAGS_SIGBLOCKNONE, fa, 2 + !!(to & 2)) ;
     18   if (!pid) goto err ;
     19 
     20   fd_close(p[to & 1]) ;
     21   return pid ;
     22 
     23  err:
     24   fd_close(p[1]) ;
     25   fd_close(p[0]) ;
     26   return 0 ;
     27 }