@@ -36,8 +36,9 @@ char gridftp_file_name[PATH_MAX];
3636char gridftp_transfer_type [10 ];
3737
3838static globus_mutex_t g_hdfs_mutex ;
39- static pthread_t g_thread_id ;
40- static int g_thread_pipe_fd ;
39+ static pthread_t g_thread_id = 0 ;
40+ static int g_thread_pipe_fd = -1 ;
41+ static int g_thread_saved_stderr_fd = -1 ;
4142
4243static globus_result_t check_connection_limits (const hdfs_handle_t * , int , int );
4344static int dumb_sem_open (const char * fname , int flags , mode_t mode , int value );
5455hdfs_destroy (
5556 void * user_arg );
5657
57- void
58- hdfs_start (
59- globus_gfs_operation_t op ,
60- globus_gfs_session_info_t * session_info );
61-
62- void
63- hdfs_destroy (
64- void * user_arg );
65-
6658
6759/*
6860 * Interface definitions for HDFS
@@ -231,14 +223,22 @@ setup_hdfs_logging()
231223 globus_mutex_unlock (& g_hdfs_mutex );
232224 return ;
233225 }
234- if (-1 == dup3 (pipe_fds [1 ], 2 , O_CLOEXEC ))
226+
227+ if ((g_thread_saved_stderr_fd = dup (STDERR_FILENO )) == -1 )
228+ {
229+ globus_gfs_log_message (GLOBUS_GFS_LOG_ERR , "Failed to save stderr for HDFS logging: (errno=%d, %s).\n" , errno , strerror (errno ));
230+ globus_mutex_unlock (& g_hdfs_mutex );
231+ return ;
232+ }
233+
234+ if (-1 == dup3 (pipe_fds [1 ], STDERR_FILENO , O_CLOEXEC ))
235235 {
236236 globus_gfs_log_message (GLOBUS_GFS_LOG_ERR , "Failed to reopen stderr for HDFS logging: (errno=%d, %s).\n" , errno , strerror (errno ));
237237 globus_mutex_unlock (& g_hdfs_mutex );
238238 return ;
239239 }
240240 close (pipe_fds [1 ]);
241- g_thread_pipe_fd = 2 ;
241+ g_thread_pipe_fd = STDERR_FILENO ;
242242
243243 int * pipe_ptr = malloc (sizeof (int ));
244244 if (pipe_ptr == NULL )
@@ -266,13 +266,6 @@ setup_hdfs_logging()
266266int
267267hdfs_activate (void )
268268{
269- if (globus_mutex_init (& g_hdfs_mutex , GLOBUS_NULL )) {
270- globus_gfs_log_message (GLOBUS_GFS_LOG_ERR , "Unable to initialize global mutex" );
271- return 1 ;
272- }
273- g_thread_id = 0 ;
274- g_thread_pipe_fd = -1 ;
275-
276269 globus_extension_registry_add (
277270 GLOBUS_GFS_DSI_REGISTRY ,
278271 "hdfs" ,
@@ -289,23 +282,6 @@ hdfs_activate(void)
289282int
290283hdfs_deactivate (void )
291284{
292- if (g_thread_id > 0 )
293- {
294- if (g_thread_pipe_fd >= 0 )
295- {
296- fflush (stderr );
297- close (g_thread_pipe_fd );
298- }
299- void * retval ;
300- pthread_join (g_thread_id , & retval );
301- g_thread_id = 0 ;
302- g_thread_pipe_fd = -1 ;
303- }
304-
305- globus_mutex_destroy (& g_hdfs_mutex );
306- g_thread_id = 0 ;
307- g_thread_pipe_fd = -1 ;
308-
309285 globus_extension_registry_remove (
310286 GLOBUS_GFS_DSI_REGISTRY , "hdfs" );
311287
@@ -568,7 +544,7 @@ hdfs_start(
568544 globus_gfs_operation_t op ,
569545 globus_gfs_session_info_t * session_info )
570546{
571- hdfs_handle_t * hdfs_handle ;
547+ hdfs_handle_t * hdfs_handle = NULL ;
572548 globus_gfs_finished_info_t finished_info ;
573549 GlobusGFSName (hdfs_start );
574550 globus_result_t rc ;
@@ -581,6 +557,12 @@ hdfs_start(
581557 int user_transfer_limit = -1 ;
582558 int transfer_limit = -1 ;
583559
560+ if (globus_mutex_init (& g_hdfs_mutex , GLOBUS_NULL )) {
561+ SystemError (hdfs_handle , "Unable to initialize mutex" , rc );
562+ globus_gridftp_server_operation_finished (op , rc , & finished_info );
563+ return ;
564+ }
565+
584566 hdfs_handle = (hdfs_handle_t * )globus_malloc (sizeof (hdfs_handle_t ));
585567 memset (hdfs_handle , 0 , sizeof (hdfs_handle_t ));
586568
@@ -605,6 +587,7 @@ hdfs_start(
605587 globus_gridftp_server_operation_finished (op , rc , & finished_info );
606588 return ;
607589 }
590+
608591 if (globus_mutex_init (hdfs_handle -> mutex , GLOBUS_NULL )) {
609592 SystemError (hdfs_handle , "Unable to initialize mutex" , rc );
610593 globus_gridftp_server_operation_finished (op , rc , & finished_info );
@@ -846,9 +829,32 @@ hdfs_destroy(
846829 globus_mutex_destroy (hdfs_handle -> mutex );
847830 globus_free (hdfs_handle -> mutex );
848831 }
832+ if (hdfs_handle -> cvmfs_graft )
833+ free (hdfs_handle -> cvmfs_graft );
849834 globus_free (hdfs_handle );
850- free (hdfs_handle -> cvmfs_graft );
851835 }
836+
837+ if (g_thread_id > 0 )
838+ {
839+ if (g_thread_saved_stderr_fd >= 0 )
840+ {
841+ dup2 (g_thread_saved_stderr_fd , STDERR_FILENO );
842+ close (g_thread_saved_stderr_fd );
843+ }
844+
845+ if (g_thread_pipe_fd >= 0 )
846+ {
847+ close (g_thread_pipe_fd );
848+ }
849+
850+ void * retval ;
851+ pthread_join (g_thread_id , & retval );
852+ }
853+
854+ g_thread_id = 0 ;
855+ g_thread_pipe_fd = -1 ;
856+ g_thread_saved_stderr_fd = -1 ;
857+
852858 closelog ();
853859}
854860
@@ -915,18 +921,6 @@ set_close_done(
915921 if ((hdfs_handle -> done_status == GLOBUS_SUCCESS ) && (rc != GLOBUS_SUCCESS )) {
916922 hdfs_handle -> done_status = rc ;
917923 }
918- if (g_thread_id > 0 )
919- {
920- if (g_thread_pipe_fd >= 0 )
921- {
922- fflush (stderr );
923- close (g_thread_pipe_fd );
924- }
925- void * retval ;
926- pthread_join (g_thread_id , & retval );
927- g_thread_id = 0 ;
928- g_thread_pipe_fd = -1 ;
929- }
930924}
931925
932926/*************************************************************************
0 commit comments