2005-04-15 21:23:25 +00: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.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
* These symbols are in a file by themselves to provide nice linker
|
|
|
|
* semantics. Since linkers generally pull in symbols by object
|
|
|
|
* files, keeping these symbols as the only symbols in this file
|
|
|
|
* prevents utility programs such as "ompi_info" from having to import
|
|
|
|
* entire components just to query their version and parameters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2005-04-18 21:17:56 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-04-15 21:23:25 +00:00
|
|
|
#include <unistd.h>
|
2005-04-18 21:17:56 +00:00
|
|
|
#endif
|
2005-04-15 21:23:25 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
2005-04-18 21:17:56 +00:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2005-04-15 21:23:25 +00:00
|
|
|
#include <sys/wait.h>
|
2005-04-18 21:17:56 +00:00
|
|
|
#endif
|
2005-04-15 21:23:25 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#ifdef HAVE_UTIL_H
|
|
|
|
#include <util.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PTY_H
|
|
|
|
#include <pty.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-18 21:17:56 +00:00
|
|
|
#include "mca/iof/base/iof_base_setup.h"
|
2005-04-15 21:23:25 +00:00
|
|
|
|
|
|
|
#include "include/orte_constants.h"
|
|
|
|
#include "util/output.h"
|
|
|
|
#include "mca/errmgr/errmgr.h"
|
|
|
|
#include "mca/iof/iof.h"
|
|
|
|
#include "mca/ns/ns.h"
|
|
|
|
|
|
|
|
int
|
2005-04-17 17:50:39 +00:00
|
|
|
orte_iof_base_setup_prefork(orte_iof_base_io_conf_t *opts)
|
2005-04-15 21:23:25 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* first check to make sure we can do ptys */
|
|
|
|
#if (! defined(HAVE_OPENPTY)) || (OMPI_ENABLE_PTY_SUPPORT == 0)
|
|
|
|
opts->usepty = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
#if defined(HAVE_OPENPTY) && OMPI_ENABLE_PTY_SUPPORT
|
|
|
|
if (opts->usepty) {
|
|
|
|
ret = openpty(&(opts->p_stdout[0]), &(opts->p_stdout[1]),
|
|
|
|
NULL, NULL, NULL);
|
2005-04-15 21:36:32 +00:00
|
|
|
} else {
|
|
|
|
ret = -1;
|
2005-04-15 21:23:25 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
ret = -1;
|
|
|
|
#endif
|
2005-04-18 21:17:56 +00:00
|
|
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
/* Windows doesn't have a 'pipe' function.
|
|
|
|
* So we need to do something a bit more complex */
|
|
|
|
/* XXX Implement this properly JJH
|
|
|
|
* http://www-106.ibm.com/developerworks/linux/library/l-rt4/?open&t=grl,l=252,p=pipes
|
|
|
|
*/
|
|
|
|
#else
|
2005-04-15 21:23:25 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
if (pipe(opts->p_stdout) < 0) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
if (pipe(opts->p_stdin) < 0) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pipe(opts->p_stderr) < 0) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2005-04-18 21:17:56 +00:00
|
|
|
#endif
|
2005-04-15 21:23:25 +00:00
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-04-17 17:50:39 +00:00
|
|
|
orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts)
|
2005-04-15 21:23:25 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (! opts->usepty) {
|
|
|
|
close(opts->p_stdout[0]);
|
|
|
|
close(opts->p_stdin[0]);
|
|
|
|
}
|
|
|
|
close(opts->p_stderr[0]);
|
|
|
|
|
|
|
|
if (opts->usepty) {
|
|
|
|
ret = dup2(opts->p_stdout[1], fileno(stdin));
|
|
|
|
if (ret < 0) return OMPI_ERROR;
|
|
|
|
ret = dup2(opts->p_stdout[1], fileno(stdout));
|
|
|
|
if (ret < 0) return OMPI_ERROR;
|
|
|
|
} else {
|
|
|
|
if(opts->p_stdout[1] != fileno(stdout)) {
|
2005-04-15 21:36:32 +00:00
|
|
|
ret = dup2(opts->p_stdout[1], fileno(stdout));
|
2005-04-15 21:23:25 +00:00
|
|
|
if (ret < 0) return OMPI_ERROR;
|
|
|
|
close(opts->p_stdout[1]);
|
|
|
|
}
|
|
|
|
if(opts->p_stdin[1] != fileno(stdin)) {
|
2005-04-15 21:36:32 +00:00
|
|
|
ret = dup2(opts->p_stdin[1], fileno(stdin));
|
2005-04-15 21:23:25 +00:00
|
|
|
if (ret < 0) return OMPI_ERROR;
|
|
|
|
close(opts->p_stdin[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(opts->p_stderr[1] != fileno(stderr)) {
|
2005-04-15 21:36:32 +00:00
|
|
|
ret = dup2(opts->p_stderr[1], fileno(stderr));
|
2005-04-15 21:23:25 +00:00
|
|
|
if (ret < 0) return OMPI_ERROR;
|
|
|
|
close(opts->p_stderr[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-04-17 17:50:39 +00:00
|
|
|
orte_iof_base_setup_parent(const orte_process_name_t* name,
|
|
|
|
orte_iof_base_io_conf_t *opts)
|
2005-04-15 21:23:25 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (! opts->usepty) {
|
|
|
|
close(opts->p_stdout[1]);
|
|
|
|
close(opts->p_stdin[1]);
|
|
|
|
}
|
|
|
|
close(opts->p_stderr[1]);
|
|
|
|
|
|
|
|
/* connect read end to IOF */
|
|
|
|
ret = orte_iof.iof_publish(name, ORTE_IOF_SOURCE,
|
|
|
|
ORTE_IOF_STDOUT, opts->p_stdout[0]);
|
|
|
|
if(ORTE_SUCCESS != ret) {
|
|
|
|
ORTE_ERROR_LOG(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = orte_iof.iof_publish(name, ORTE_IOF_SOURCE,
|
|
|
|
ORTE_IOF_STDERR, opts->p_stderr[0]);
|
|
|
|
if(ORTE_SUCCESS != ret) {
|
|
|
|
ORTE_ERROR_LOG(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|