--- libaitio/src/exec.c 2013/12/08 20:43:22 1.1.2.14 +++ libaitio/src/exec.c 2013/12/08 21:11:54 1.1.2.16 @@ -217,6 +217,7 @@ io_progOpen(prog_t * __restrict prg, u_int execNum) break; } else array_Set(prg->prog_fds, i, f); + clrbit(prg->prog_used, i); prg->prog_cnum++; ret++; } @@ -301,10 +302,11 @@ io_progVacuum(prog_t * __restrict prg, u_int toNum) * io_progCheck() - Check exit status of program pool * * @prg = program pool + * @re = resurrect program * return: -1 error or >-1 exited programs */ int -io_progCheck(prog_t * __restrict prg) +io_progCheck(prog_t * __restrict prg, int re) { int ret = 0; struct tagPIOPID *p; @@ -323,10 +325,21 @@ io_progCheck(prog_t * __restrict prg) #endif if (waitpid(p->pid, &p->stat, WNOHANG) > 0) { clrbit(prg->prog_used, i); +#ifdef POPEN_STREAM + e_pclose(array(prg->prog_fds, i, FILE*)); +#else + e_pclose((int) array(prg->prog_fds, i, intptr_t)); +#endif + array_Del(prg->prog_fds, i, 0); + prg->prog_cnum--; ret++; } pthread_mutex_unlock(&prg->prog_mtx); + /* resurrect */ + if (re && ret > 0) + io_progOpen(prg, ret); + return ret; } @@ -334,6 +347,7 @@ io_progCheck(prog_t * __restrict prg) * io_progAttach() - Attach to open program * * @prg = program pool + * @newOne = Execute new one program after attach * return: NULL error or !=NULL attached program handle */ #ifdef POPEN_STREAM @@ -341,7 +355,7 @@ FILE * #else int #endif -io_progAttach(prog_t * __restrict prg) +io_progAttach(prog_t * __restrict prg, int newOne) { #ifdef POPEN_STREAM FILE *f = NULL; @@ -369,6 +383,10 @@ io_progAttach(prog_t * __restrict prg) break; } pthread_mutex_unlock(&prg->prog_mtx); + + /* execute new one program */ + if (newOne && f) + io_progOpen(prg, 1); return f; }