1
1

orte/iof: Add app stderr to stdout redirection at source

* Add an MCA parameter to combine stdout and stderr at the source
   - `iof_base_redirect_app_stderr_to_stdout`
 * Aids in user debugging when using libraries that mix stderr with stdout

Signed-off-by: Joshua Hursey <jhursey@us.ibm.com>
Этот коммит содержится в:
Joshua Hursey 2016-09-20 12:29:46 -04:00
родитель dcd9801f7c
Коммит 0e9a06d2c3
3 изменённых файлов: 26 добавлений и 2 удалений

Просмотреть файл

@ -13,6 +13,7 @@
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -136,6 +137,7 @@ struct orte_iof_base_t {
char *input_files;
orte_iof_sink_t *iof_write_stdout;
orte_iof_sink_t *iof_write_stderr;
bool redirect_app_stderr_to_stdout;
};
typedef struct orte_iof_base_t orte_iof_base_t;

Просмотреть файл

@ -14,6 +14,7 @@
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -79,6 +80,15 @@ static int orte_iof_base_register(mca_base_register_flag_t flags)
MCA_BASE_VAR_SCOPE_READONLY,
&orte_iof_base.input_files);
/* Redirect application stderr to stdout (at source) */
orte_iof_base.redirect_app_stderr_to_stdout = false;
(void) mca_base_var_register("orte", "iof","base", "redirect_app_stderr_to_stdout",
"Redirect application stderr to stdout at source (default: false)",
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_iof_base.redirect_app_stderr_to_stdout);
return ORTE_SUCCESS;
}

Просмотреть файл

@ -68,6 +68,7 @@
#include "orte/runtime/orte_globals.h"
#include "orte/mca/iof/iof.h"
#include "orte/mca/iof/base/base.h"
#include "orte/mca/iof/base/iof_base_setup.h"
int
@ -153,11 +154,19 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
}
ret = dup2(opts->p_stdout[1], fileno(stdout));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
ret = dup2(opts->p_stdout[1], fileno(stderr));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
}
close(opts->p_stdout[1]);
} else {
if(opts->p_stdout[1] != fileno(stdout)) {
ret = dup2(opts->p_stdout[1], fileno(stdout));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
ret = dup2(opts->p_stdout[1], fileno(stderr));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
}
close(opts->p_stdout[1]);
}
}
@ -178,9 +187,12 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
close(fd);
}
}
if(opts->p_stderr[1] != fileno(stderr)) {
ret = dup2(opts->p_stderr[1], fileno(stderr));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
if( !orte_iof_base.redirect_app_stderr_to_stdout ) {
ret = dup2(opts->p_stderr[1], fileno(stderr));
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
}
close(opts->p_stderr[1]);
}