2015-06-24 06:59:57 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-01-11 00:18:25 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-01-11 07:37:28 +03:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2005-07-04 04:13:44 +04:00
|
|
|
|
2004-01-11 00:18:25 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2004-01-11 00:18:25 +03:00
|
|
|
#include <sys/wait.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-01-11 00:18:25 +03:00
|
|
|
#include <stdlib.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-01-11 00:18:25 +03:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-01-11 00:18:25 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#include "opal/util/few.h"
|
2006-08-26 03:22:35 +04:00
|
|
|
#include "opal/util/basename.h"
|
|
|
|
#include "opal/util/argv.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/constants.h"
|
2004-01-11 00:18:25 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
int opal_few(char *argv[], int *status)
|
2004-01-11 00:18:25 +03:00
|
|
|
{
|
2005-07-14 22:05:30 +04:00
|
|
|
#if defined(HAVE_FORK) && defined(HAVE_EXECVE) && defined(HAVE_WAITPID)
|
2004-01-11 07:37:28 +03:00
|
|
|
pid_t pid, ret;
|
2004-01-11 00:18:25 +03:00
|
|
|
|
|
|
|
if ((pid = fork()) < 0) {
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_ERR_IN_ERRNO;
|
2004-01-11 07:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Child execs. If it fails to exec, exit. */
|
|
|
|
|
2015-06-24 06:59:57 +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. */
|
|
|
|
|
2015-06-24 06:59:57 +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;
|
2015-06-24 06:59:57 +03:00
|
|
|
}
|
2004-01-11 07:37:28 +03:00
|
|
|
|
|
|
|
/* If waitpid was interrupted, loop around again */
|
|
|
|
|
|
|
|
else if (ret < 0) {
|
|
|
|
if (EINTR == errno) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, some bad juju happened -- need to quit */
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_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 */
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_SUCCESS;
|
2005-07-14 22:05:30 +04:00
|
|
|
#else
|
2006-02-12 04:33:29 +03:00
|
|
|
return OPAL_ERR_NOT_SUPPORTED;
|
2005-07-14 22:05:30 +04:00
|
|
|
#endif
|
2004-01-11 00:18:25 +03:00
|
|
|
}
|