2004-01-11 00:18:25 +03:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-11 00:18:25 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-01-11 07:37:28 +03:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#include "ompi_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
|
|
|
|
2004-03-19 00:35:28 +03:00
|
|
|
#include "include/constants.h"
|
2005-07-04 04:13:44 +04:00
|
|
|
#include "opal/util/few.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
|
|
|
{
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
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) {
|
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;
|
2005-07-14 22:05:30 +04:00
|
|
|
#else
|
|
|
|
return OMPI_ERR_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Welcome to windows land. This is apparently a simple fork() exec()
|
|
|
|
procedure and hence should not be too difficult to implement */
|
|
|
|
HANDLE new_process;
|
|
|
|
STARTUPINFO si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
DWORD process_stat;
|
|
|
|
|
|
|
|
/* it does seem as if the environment is getting propogated, so I
|
|
|
|
will follow the same procedure in my code */
|
|
|
|
|
|
|
|
/* ANJU: Have to implement signal handling */
|
|
|
|
|
|
|
|
ZeroMemory (&si, sizeof(si));
|
|
|
|
ZeroMemory (&pi, sizeof(pi));
|
|
|
|
|
|
|
|
GetStartupInfo (&si);
|
|
|
|
if (!CreateProcess (argv[0],
|
|
|
|
argv,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi)){
|
|
|
|
/* actual error can be got by simply calling GetLastError() */
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for child to die */
|
|
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
|
GetExitCodeProcess(pi.hProcess, &process_stat);
|
|
|
|
|
|
|
|
SetLastError(process_stat);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
#endif
|
2004-01-11 00:18:25 +03:00
|
|
|
}
|