static pid_t _spawnveg(Shell_t *shp,const char *path, char* const argv[], char* const envp[], pid_t pgid) { pid_t pid; while(1) { sh_stats(STAT_SPAWN); pid = spawnveg(path,argv,envp,pgid); if(pid>=0 || errno!=EAGAIN) break; } return(pid); }
static int initiate(Cs_t* state, const char* svc, char* cmd) { pid_t pid; pid_t n; char* av[3]; #ifdef SIGCHLD Handler_t fun; children = 0; if ((fun = signal(SIGCHLD, child)) == SIG_DFL) signal(SIGCHLD, fun); else if (children) children++; #endif pathcanon(cmd, 0, 0); av[0] = cmd; av[1] = (char*)svc; av[2] = 0; if ((pid = spawnveg(av[0], av, environ, 0)) == -1) { messagef((state->id, NiL, -1, "local: %s: cannot initiate %s", svc, cmd)); return -1; } while ((n = waitpid(pid, NiL, 0)) == -1 && errno == EINTR); #ifdef SIGCHLD if (fun != SIG_DFL) { signal(SIGCHLD, fun); if (fun != SIG_IGN) while (--children > 0) (*fun)(SIGCHLD); } #endif /* * yuk: looks like we have to give fdp services time * to start up -- a few seconds shouldn't hurt */ sleep(2); return n; }
static pid_t _spawnveg(Shell_t *shp,const char *path, char* const argv[], char* const envp[], pid_t pgid) { pid_t pid; #ifdef SIGTSTP if(job.jobcontrol) { signal(SIGTTIN,SIG_DFL); signal(SIGTTOU,SIG_DFL); } #endif /* SIGTSTP */ while(1) { sh_stats(STAT_SPAWN); #ifdef SPAWN_cwd { char *arg0 = argv[0], **av0= (char**)&argv[0]; int fd; pid = spawnvex(path,argv,envp,shp->vex); *av0 = arg0; if(pid>0 && shp->comsub && (fd=sffileno(sfstdout))!=1 && fd>=0) spawnvex_add(shp->vex, fd, 1,0,0); } #else pid = spawnveg(path,argv,envp,pgid); #endif /* SPAWN_cwd */ if(pid>=0 || errno!=EAGAIN) break; } #ifdef SIGTSTP if(job.jobcontrol) { signal(SIGTTIN,SIG_IGN); signal(SIGTTOU,SIG_IGN); } #endif /* SIGTSTP */ return(pid); }