2004-01-11 00:18:25 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-11 07:37:28 +03:00
|
|
|
|
2004-01-11 00:18:25 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2004-03-19 00:35:28 +03:00
|
|
|
#include "include/constants.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "util/few.h"
|
2004-01-11 00:18:25 +03:00
|
|
|
|
2004-08-17 07:06:39 +04:00
|
|
|
int ompi_few(char *argv[], int *status)
|
2004-01-11 00:18:25 +03:00
|
|
|
{
|
2004-01-11 07:37:28 +03:00
|
|
|
pid_t pid, ret;
|
2004-01-11 00:18:25 +03:00
|
|
|
|
|
|
|
if ((pid = fork()) < 0) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERR_IN_ERRNO;
|
2004-01-11 07:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Child execs. If it fails to exec, exit. */
|
|
|
|
|
2004-01-11 00:18:25 +03:00
|
|
|
else if (0 == pid) {
|
2004-01-11 07:37:28 +03:00
|
|
|
execvp(argv[0], argv);
|
|
|
|
exit(errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parent loops waiting for the child to die. */
|
|
|
|
|
2004-01-11 00:18:25 +03:00
|
|
|
else {
|
2004-01-11 07:37:28 +03:00
|
|
|
do {
|
|
|
|
/* If the child exited, return */
|
|
|
|
|
|
|
|
if (pid == (ret = waitpid(pid, status, 0))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If waitpid was interrupted, loop around again */
|
|
|
|
|
|
|
|
else if (ret < 0) {
|
|
|
|
if (EINTR == errno) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, some bad juju happened -- need to quit */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERR_IN_ERRNO;
|
2004-01-11 07:37:28 +03:00
|
|
|
}
|
|
|
|
} while (true);
|
2004-01-11 00:18:25 +03:00
|
|
|
}
|
2004-01-11 07:37:28 +03:00
|
|
|
|
|
|
|
/* Return the status to the caller */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-01-11 00:18:25 +03:00
|
|
|
}
|