static int nto_create_inferior (char *program, char **allargs) { struct inheritance inherit; pid_t pid; sigset_t set; TRACE ("%s %s\n", __func__, program); /* Clear any pending SIGUSR1's but keep the behavior the same. */ signal (SIGUSR1, signal (SIGUSR1, SIG_IGN)); sigemptyset (&set); sigaddset (&set, SIGUSR1); sigprocmask (SIG_UNBLOCK, &set, NULL); memset (&inherit, 0, sizeof (inherit)); inherit.flags |= SPAWN_SETGROUP | SPAWN_HOLD; inherit.pgroup = SPAWN_NEWPGROUP; pid = spawnp (program, 0, NULL, &inherit, allargs, 0); sigprocmask (SIG_BLOCK, &set, NULL); if (pid == -1) return -1; if (do_attach (pid) != pid) return -1; return pid; }
int do_aspawn(SV* really, SV **mark, SV **sp) { char **a, *tmps; struct inheritance inherit; pid_t pid; int status, fd, nFd, fdMap[3]; SV *sv, **p_sv; STRLEN n_a; status = FAIL; if (sp > mark) { Newx(PL_Argv, sp - mark + 1, char*); a = PL_Argv; while (++mark <= sp) { if (*mark) *a++ = SvPVx(*mark, n_a); else *a++ = ""; } inherit.flags = SPAWN_SETGROUP; inherit.pgroup = SPAWN_NEWPGROUP; fdMap[STDIN_FILENO] = Perl_stdin_fd; fdMap[STDOUT_FILENO] = Perl_stdout_fd; fdMap[STDERR_FILENO] = STDERR_FILENO; nFd = 3; *a = NULL; /*-----------------------------------------------------*/ /* Will execvp() use PATH? */ /*-----------------------------------------------------*/ if (*PL_Argv[0] != '/') TAINT_ENV(); if (really && *(tmps = SvPV(really, n_a))) pid = spawnp(tmps, nFd, fdMap, &inherit, (const char **) PL_Argv, (const char **) environ); else pid = spawnp(PL_Argv[0], nFd, fdMap, &inherit, (const char **) PL_Argv, (const char **) environ); if (pid < 0) { status = FAIL; if (ckWARN(WARN_EXEC)) warner(WARN_EXEC,"Can't exec \"%s\": %s", PL_Argv[0], Strerror(errno)); } else { /*------------------------------------------------*/ /* If the file descriptors have been remapped then*/ /* we've been called following a my_popen request */ /* therefore we don't want to wait for spawnned */ /* program to complete. We need to set the fdpid */ /* value to the value of the spawnned process' pid*/ /*------------------------------------------------*/ fd = 0; if (Perl_stdin_fd != STDIN_FILENO) fd = Perl_stdin_fd; else if (Perl_stdout_fd != STDOUT_FILENO) fd = Perl_stdout_fd; if (fd != 0) { /*---------------------------------------------*/ /* Get the fd of the other end of the pipe, */ /* use this to reference the fdpid which will */ /* be used by my_pclose */ /*---------------------------------------------*/ close(fd); MUTEX_LOCK(&PL_fdpid_mutex); p_sv = av_fetch(PL_fdpid,fd,TRUE); fd = (int) SvIVX(*p_sv); SvREFCNT_dec(*p_sv); *p_sv = &PL_sv_undef; sv = *av_fetch(PL_fdpid,fd,TRUE); MUTEX_UNLOCK(&PL_fdpid_mutex); (void) SvUPGRADE(sv, SVt_IV); SvIVX(sv) = pid; status = 0; } else wait4pid(pid, &status, 0); } do_execfree(); }
void init( void ) { int16_t pid; write( FD_CONSOLE, "Init started\n", 0 ); write( FD_SIO, "$", 1 ); #ifdef SPAWN_A pid = spawnp( user_a, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user A failed\n", 0 ); exit(); } #endif #ifdef SPAWN_B pid = spawnp( user_b, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user B failed\n", 0 ); exit(); } #endif #ifdef SPAWN_C pid = spawnp( user_c, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user C failed\n", 0 ); exit(); } #endif #ifdef SPAWN_D pid = spawnp( user_d, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user D failed\n", 0 ); exit(); } #endif #ifdef SPAWN_E pid = spawnp( user_e, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user E failed\n", 0 ); exit(); } #endif #ifdef SPAWN_F pid = spawnp( user_f, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user F failed\n", 0 ); exit(); } #endif #ifdef SPAWN_G pid = spawnp( user_g, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user G failed\n", 0 ); exit(); } #endif #ifdef SPAWN_H pid = spawnp( user_h, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user H failed\n", 0 ); exit(); } #endif #ifdef SPAWN_J pid = spawnp( user_j, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user J failed\n", 0 ); exit(); } #endif #ifdef SPAWN_K pid = spawnp( user_k, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user K failed\n", 0 ); exit(); } #endif #ifdef SPAWN_L pid = spawnp( user_l, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user L failed\n", 0 ); exit(); } #endif #ifdef SPAWN_M pid = spawnp( user_m, PRIO_USER_LOW ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user M failed\n", 0 ); exit(); } #endif #ifdef SPAWN_N pid = spawnp( user_n, PRIO_USER_HIGH ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user N failed\n", 0 ); exit(); } #endif #ifdef SPAWN_P pid = spawnp( user_p, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user P failed\n", 0 ); exit(); } #endif #ifdef SPAWN_Q pid = spawnp( user_q, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user Q failed\n", 0 ); exit(); } #endif #ifdef SPAWN_R pid = spawnp( user_r, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user R failed\n", 0 ); exit(); } #endif #ifdef SPAWN_S pid = spawnp( user_s, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user S failed\n", 0 ); exit(); } #endif #ifdef SPAWN_T pid = spawnp( user_t, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user T failed\n", 0 ); exit(); } #endif #ifdef SPAWN_U pid = spawnp( user_u, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user U failed\n", 0 ); exit(); } #endif #ifdef SPAWN_V pid = spawnp( user_v, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user V failed\n", 0 ); exit(); } #endif #ifdef SPAWN_NET pid = spawnp( user_net, PRIO_USER_STD ); if( pid < 0 ) { write( FD_CONSOLE, "init, spawnp() user net failed\n", 0 ); exit(); } #endif write( FD_SIO, "!", 1 ); exit(); }