Skip to content

Commit 637d32e

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]> (cherry picked from commit 0e9a06d) Signed-off-by: Joshua Hursey <[email protected]>
1 parent 66ab9da commit 637d32e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

orte/mca/iof/base/base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct orte_iof_base_t {
131131
char *input_files;
132132
orte_iof_sink_t *iof_write_stdout;
133133
orte_iof_sink_t *iof_write_stderr;
134+
bool redirect_app_stderr_to_stdout;
134135
};
135136
typedef struct orte_iof_base_t orte_iof_base_t;
136137

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 Intel, Inc. All rights reserved.
1515
* Copyright (c) 2015 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
@@ -204,6 +205,15 @@ static int orte_iof_base_register(mca_base_register_flag_t flags)
204205
MCA_BASE_VAR_SCOPE_READONLY,
205206
&orte_iof_base.input_files);
206207

208+
/* Redirect application stderr to stdout (at source) */
209+
orte_iof_base.redirect_app_stderr_to_stdout = false;
210+
(void) mca_base_var_register("orte", "iof","base", "redirect_app_stderr_to_stdout",
211+
"Redirect application stderr to stdout at source (default: false)",
212+
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
213+
OPAL_INFO_LVL_9,
214+
MCA_BASE_VAR_SCOPE_READONLY,
215+
&orte_iof_base.redirect_app_stderr_to_stdout);
216+
207217
return ORTE_SUCCESS;
208218
}
209219

orte/mca/iof/base/iof_base_setup.c

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

6868
#include "orte/mca/iof/iof.h"
69+
#include "orte/mca/iof/base/base.h"
6970
#include "orte/mca/iof/base/iof_base_setup.h"
7071

7172
int
@@ -151,11 +152,19 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
151152
}
152153
ret = dup2(opts->p_stdout[1], fileno(stdout));
153154
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
155+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
156+
ret = dup2(opts->p_stdout[1], fileno(stderr));
157+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
158+
}
154159
close(opts->p_stdout[1]);
155160
} else {
156161
if(opts->p_stdout[1] != fileno(stdout)) {
157162
ret = dup2(opts->p_stdout[1], fileno(stdout));
158163
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
164+
if( orte_iof_base.redirect_app_stderr_to_stdout ) {
165+
ret = dup2(opts->p_stdout[1], fileno(stderr));
166+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
167+
}
159168
close(opts->p_stdout[1]);
160169
}
161170
}
@@ -176,9 +185,12 @@ orte_iof_base_setup_child(orte_iof_base_io_conf_t *opts, char ***env)
176185
close(fd);
177186
}
178187
}
188+
179189
if(opts->p_stderr[1] != fileno(stderr)) {
180-
ret = dup2(opts->p_stderr[1], fileno(stderr));
181-
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
190+
if( !orte_iof_base.redirect_app_stderr_to_stdout ) {
191+
ret = dup2(opts->p_stderr[1], fileno(stderr));
192+
if (ret < 0) return ORTE_ERR_PIPE_SETUP_FAILURE;
193+
}
182194
close(opts->p_stderr[1]);
183195
}
184196

0 commit comments

Comments
 (0)