version 1.1.2.2, 2013/12/05 15:04:20
|
version 1.1.2.4, 2013/12/05 15:38:14
|
Line 26 e_popen(const char *command, const char *type, pid_t *
|
Line 26 e_popen(const char *command, const char *type, pid_t *
|
int pdes[2], pid, twoway, cloexec; |
int pdes[2], pid, twoway, cloexec; |
char *argv[4]; |
char *argv[4]; |
|
|
|
if (!command || !type) |
|
return NULL; |
|
|
cloexec = strchr(type, 'e') != NULL; |
cloexec = strchr(type, 'e') != NULL; |
/* |
/* |
* Lite2 introduced two-way popen() pipes using _socketpair(). |
* Lite2 introduced two-way popen() pipes using _socketpair(). |
Line 140 e_pclose(FILE *iop)
|
Line 143 e_pclose(FILE *iop)
|
int pstat; |
int pstat; |
pid_t pid; |
pid_t pid; |
|
|
|
if (!iop) |
|
return -1; |
|
|
/* |
/* |
* Find the appropriate file pointer and remove it from the list. |
* Find the appropriate file pointer and remove it from the list. |
*/ |
*/ |
Line 168 e_pclose(FILE *iop)
|
Line 174 e_pclose(FILE *iop)
|
e_free(cur); |
e_free(cur); |
|
|
return (pid == -1 ? -1 : pstat); |
return (pid == -1 ? -1 : pstat); |
|
} |
|
|
|
/* |
|
* pio_pgetpid() - Get tagPIOPID structure from file handle |
|
* |
|
* @iop = popen handle |
|
* return: NULL error or !=NULL tagPIOPID structure |
|
*/ |
|
struct tagPIOPID * |
|
pio_pgetpid(FILE * __restrict iop) |
|
{ |
|
struct tagPIOPID *p; |
|
|
|
if (!iop) |
|
return NULL; |
|
|
|
THREAD_LOCK(); |
|
SLIST_FOREACH(p, &pio_pidlist, next) |
|
if (p->fp == iop) |
|
break; |
|
THREAD_UNLOCK(); |
|
|
|
return p; |
|
} |
|
|
|
/* |
|
* pio_pchkpid() - Check exit status of child programs |
|
* |
|
* @pids = return tagPIOPID structures of exited programs, |
|
* if !=NULL must call array_Destroy() |
|
* return: -1 error or >-1 exited programs |
|
*/ |
|
int |
|
pio_pchkpid(array_t ** __restrict pids) |
|
{ |
|
register int ret = 0; |
|
struct tagPIOPID *p; |
|
array_t *pa; |
|
|
|
if (pids) { |
|
if (!(pa = array_Init(0))) |
|
return -1; |
|
else |
|
*pids = pa; |
|
} |
|
|
|
THREAD_LOCK(); |
|
SLIST_FOREACH(p, &pio_pidlist, next) |
|
if (p->fp && waitpid(p->pid, &p->stat, WNOHANG) > 0) { |
|
if (pids) |
|
array_Push(pa, p, 0); |
|
ret++; |
|
} |
|
THREAD_UNLOCK(); |
|
|
|
return ret; |
} |
} |