Skip to content

Commit 0e9a06d

Browse files
committed
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 <[email protected]>
1 parent dcd9801 commit 0e9a06d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

orte/mca/iof/base/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
1414
* All rights reserved.
1515
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
16+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -136,6 +137,7 @@ struct orte_iof_base_t {
136137
char *input_files;
137138
orte_iof_sink_t *iof_write_stdout;
138139
orte_iof_sink_t *iof_write_stderr;
140+
bool redirect_app_stderr_to_stdout;
139141
};
140142
typedef struct orte_iof_base_t orte_iof_base_t;
141143

orte/mca/iof/base/iof_base_frame.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
1515
* Copyright (c) 2015-2017 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
17+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1718
* $COPYRIGHT$
1819
*
1920
* Additional copyrights may follow
@@ -79,6 +80,15 @@ static int orte_iof_base_register(mca_base_register_flag_t flags)
7980
MCA_BASE_VAR_SCOPE_READONLY,
8081
&orte_iof_base.input_files);
8182

83+
/* Redirect application stderr to stdout (at source) */
84+
orte_iof_base.redirect_app_stderr_to_stdout = false;
85+
(void) mca_base_var_register("orte", "iof","base", "redirect_app_stderr_to_stdout",
86+
"Redirect application stderr to stdout at source (default: false)",
87+
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
88+
OPAL_INFO_LVL_9,
89+
MCA_BASE_VAR_SCOPE_READONLY,
90+
&orte_iof_base.redirect_app_stderr_to_stdout);
91+
8292
return ORTE_SUCCESS;
8393
}
8494

orte/mca/iof/base/iof_base_setup.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "orte/runtime/orte_globals.h"
6969

7070
#include "orte/mca/iof/iof.h"
71+
#include "orte/mca/iof/base/base.h"
7172
#include "orte/mca/iof/base/iof_base_setup.h"
7273

7374
int
@@ -153,11 +154,19 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
153154
}
154155
ret = dup2(opts->p_stdout[1], fileno(stdout));
155156
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
157+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
158+
ret = dup2(opts->p_stdout[1], fileno(stderr));
159+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
160+
}
156161
close(opts->p_stdout[1]);
157162
} else {
158163
if(opts->p_stdout[1] != fileno(stdout)) {
159164
ret = dup2(opts->p_stdout[1], fileno(stdout));
160165
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
166+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
167+
ret = dup2(opts->p_stdout[1], fileno(stderr));
168+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
169+
}
161170
close(opts->p_stdout[1]);
162171
}
163172
}
@@ -178,9 +187,12 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
178187
close(fd);
179188
}
180189
}
190+
181191
if(opts->p_stderr[1] != fileno(stderr)) {
182-
ret = dup2(opts->p_stderr[1], fileno(stderr));
183-
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
192+
if( !orte_iof_base.redirect_app_stderr_to_stdout ) {
193+
ret = dup2(opts->p_stderr[1], fileno(stderr));
194+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
195+
}
184196
close(opts->p_stderr[1]);
185197
}
186198

0 commit comments

Comments
 (0)