From f0f83f5c4efa25ba2cc78d0276ecb89182f3be3e Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 19 Nov 2016 18:30:51 -0500 Subject: [PATCH] src/tests/inpty.cc: Send the inner stderr to the outer stderr Signed-off-by: Anders Kaseorg --- src/tests/inpty.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tests/inpty.cc b/src/tests/inpty.cc index 09cb619..100aee4 100644 --- a/src/tests/inpty.cc +++ b/src/tests/inpty.cc @@ -66,6 +66,13 @@ int main( int argc, char *argv[] ) memset( &winsize, 0, sizeof( winsize ) ); winsize.ws_col = 80; winsize.ws_row = 24; + + int saved_stderr = dup(STDERR_FILENO); + if ( saved_stderr < 0 ) { + perror( "dup" ); + return 1; + } + int master; pid_t child = forkpty( &master, NULL, NULL, &winsize ); if ( child == -1 ) { @@ -77,6 +84,14 @@ int main( int argc, char *argv[] ) */ return 77; } else if ( child == 0 ) { + if ( dup2( saved_stderr, STDERR_FILENO ) < 0 ) { + perror( "dup2" ); + exit( 1 ); + } + if ( close( saved_stderr ) < 0 ) { + perror( "close" ); + exit( 1 ); + } if ( execvp( argv[1], argv + 1 ) < 0 ) { perror( "execve" ); exit( 1 );