Skip to content
Snippets Groups Projects
Commit 434e4691 authored by tewk's avatar tewk
Browse files

Fixed the imfamous forward_io bug

parent 94990b9f
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ int forward_io ( task_start_t * task_start ) ...@@ -44,7 +44,7 @@ int forward_io ( task_start_t * task_start )
#define STDIN_OUT_SOCK 0 #define STDIN_OUT_SOCK 0
#define SIG_STDERR_SOCK 1 #define SIG_STDERR_SOCK 1
posix_signal_pipe_ignore ( ) ; //posix_signal_pipe_ignore ( ) ;
/* open stdout*/ /* open stdout*/
connect_io_stream ( task_start , STDIN_OUT_SOCK ) ; connect_io_stream ( task_start , STDIN_OUT_SOCK ) ;
...@@ -62,16 +62,7 @@ int forward_io ( task_start_t * task_start ) ...@@ -62,16 +62,7 @@ int forward_io ( task_start_t * task_start )
if ( pthread_create ( & task_start->io_pthread_id[STDERR_FILENO] , NULL , stderr_io_pipe_thread , task_start ) ) if ( pthread_create ( & task_start->io_pthread_id[STDERR_FILENO] , NULL , stderr_io_pipe_thread , task_start ) )
goto kill_stdout_thread; goto kill_stdout_thread;
/* threads have been detatched*/
pthread_join ( task_start->io_pthread_id[STDERR_FILENO] , NULL ) ;
info ( "errexit" ) ;
pthread_join ( task_start->io_pthread_id[STDOUT_FILENO] , NULL ) ;
info ( "outexit" ) ;
/*pthread_join ( task_start->io_pthread_id[STDIN_FILENO] , NULL ) ;*/
pthread_cancel ( task_start->io_pthread_id[STDIN_FILENO] );
info ( "inexit" ) ;
/* thread join on stderr or stdout signifies task termination we should kill the stdin thread */
goto return_label; goto return_label;
...@@ -83,6 +74,19 @@ int forward_io ( task_start_t * task_start ) ...@@ -83,6 +74,19 @@ int forward_io ( task_start_t * task_start )
return SLURM_SUCCESS ; return SLURM_SUCCESS ;
} }
int wait_on_io_threads ( task_start_t * task_start )
{
/* threads have been detatched*/
pthread_join ( task_start->io_pthread_id[STDERR_FILENO] , NULL ) ;
info ( "errexit" ) ;
pthread_join ( task_start->io_pthread_id[STDOUT_FILENO] , NULL ) ;
info ( "outexit" ) ;
/*pthread_join ( task_start->io_pthread_id[STDIN_FILENO] , NULL ) ;*/
pthread_cancel ( task_start->io_pthread_id[STDIN_FILENO] );
info ( "inexit" ) ;
/* thread join on stderr or stdout signifies task termination we should kill the stdin thread */
}
void * stdin_io_pipe_thread ( void * arg ) void * stdin_io_pipe_thread ( void * arg )
{ {
task_start_t * task_start = ( task_start_t * ) arg ; task_start_t * task_start = ( task_start_t * ) arg ;
...@@ -280,6 +284,8 @@ void * stderr_io_pipe_thread ( void * arg ) ...@@ -280,6 +284,8 @@ void * stderr_io_pipe_thread ( void * arg )
init_circular_buffer ( & cir_buf ) ; init_circular_buffer ( & cir_buf ) ;
posix_signal_pipe_ignore ( ) ;
while ( true ) while ( true )
{ {
if ( ( cir_buf->write_size == 0 ) ) if ( ( cir_buf->write_size == 0 ) )
......
...@@ -14,9 +14,17 @@ void setup_parent_pipes ( int * pipes ) ...@@ -14,9 +14,17 @@ void setup_parent_pipes ( int * pipes )
void cleanup_parent_pipes ( int * pipes ) void cleanup_parent_pipes ( int * pipes )
{ {
/*
close ( pipes[CHILD_IN_RD] ) ;
close ( pipes[CHILD_OUT_WR] ) ;
close ( pipes[CHILD_ERR_WR] ) ;
*/
// info ( " %i , %i , %i ", pipes[CHILD_IN_RD] , pipes[CHILD_OUT_WR] , pipes[CHILD_ERR_WR] ) ;
close ( pipes[CHILD_IN_WR] ) ; close ( pipes[CHILD_IN_WR] ) ;
close ( pipes[CHILD_OUT_RD] ) ; close ( pipes[CHILD_OUT_RD] ) ;
close ( pipes[CHILD_ERR_RD] ) ; close ( pipes[CHILD_ERR_RD] ) ;
// info ( " %i , %i , %i ", pipes[CHILD_IN_WR] , pipes[CHILD_OUT_RD] , pipes[CHILD_ERR_RD] ) ;
} }
int init_parent_pipes ( int * pipes ) int init_parent_pipes ( int * pipes )
......
...@@ -126,6 +126,7 @@ void * task_exec_thread ( void * arg ) ...@@ -126,6 +126,7 @@ void * task_exec_thread ( void * arg )
/* create pipes to read child stdin, stdout, sterr */ /* create pipes to read child stdin, stdout, sterr */
init_parent_pipes ( task_start->pipes ) ; init_parent_pipes ( task_start->pipes ) ;
forward_io ( arg ) ;
#define FORK_ERROR -1 #define FORK_ERROR -1
#define CHILD_PROCCESS 0 #define CHILD_PROCCESS 0
...@@ -190,8 +191,8 @@ void * task_exec_thread ( void * arg ) ...@@ -190,8 +191,8 @@ void * task_exec_thread ( void * arg )
default: /*parent proccess */ default: /*parent proccess */
task_start->exec_pid = cpid ; task_start->exec_pid = cpid ;
setup_parent_pipes ( task_start->pipes ) ; setup_parent_pipes ( task_start->pipes ) ;
forward_io ( arg ) ;
waitpid ( cpid , & task_return_code , 0 ) ; waitpid ( cpid , & task_return_code , 0 ) ;
wait_on_io_threads ( task_start ) ;
cleanup_parent_pipes ( task_start->pipes ) ; cleanup_parent_pipes ( task_start->pipes ) ;
send_task_exit_msg ( task_return_code , task_start ) ; send_task_exit_msg ( task_return_code , task_start ) ;
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment