@@ -36,7 +36,7 @@ let ciphersuites = ref None
3636let xedebug = ref false
3737let xedebugonfail = ref false
3838
39- let stunnel_process = ref None
39+ let stunnel_processes = ref []
4040let debug_channel = ref None
4141let debug_file = ref None
4242
@@ -246,7 +246,7 @@ let open_tcp_ssl server =
246246 let x = Stunnel. connect ~use_fork_exec_helper: false
247247 ~write_to_log: (fun x -> debug " stunnel: %s\n %!" x)
248248 ~extended_diagnosis: (! debug_file <> None ) server port in
249- if ! stunnel_process = None then stunnel_process := Some x ;
249+ stunnel_processes := x :: ! stunnel_processes ;
250250 Unix. in_channel_of_descr x.Stunnel. fd, Unix. out_channel_of_descr x.Stunnel. fd
251251
252252let open_tcp server =
@@ -331,19 +331,7 @@ let main_loop ifd ofd =
331331 *)
332332 while (match Unix. select [ifd] [] [] 5.0 with
333333 | _ :: _ , _ , _ -> false
334- | _ ->
335- match ! stunnel_process with
336- | Some { Stunnel. pid = Stunnel. FEFork pid } -> begin
337- match Forkhelpers. waitpid_nohang pid with
338- | 0 , _ -> true
339- | i , e -> raise (Stunnel_exit (i, e))
340- end
341- | Some {Stunnel. pid = Stunnel. StdFork pid } -> begin
342- match Unix. waitpid [Unix. WNOHANG ] pid with
343- | 0 , _ -> true
344- | i , e -> raise (Stunnel_exit (i, e))
345- end
346- | _ -> true ) do ()
334+ | _ -> true ) do ()
347335 done ;
348336 let cmd =
349337 try unmarshal ifd
@@ -527,7 +515,6 @@ let main_loop ifd ofd =
527515 copy_with_heartbeat file_ch oc heartbeat_fun;
528516 marshal ofd (Response OK ))
529517 (fun () ->
530- (try close_in ic with _ -> () );
531518 (try close_in file_ch with _ -> () ))
532519 | 302 ->
533520 let newloc = List. assoc " location" headers in
@@ -673,8 +660,7 @@ let main () =
673660 | Unix. WSTOPPED c -> " stopped by signal " ^ string_of_int c)
674661 | e ->
675662 error " Unhandled exception\n %s\n " (Printexc. to_string e) in
676- begin match ! stunnel_process with
677- | Some p ->
663+ List. iter (fun p ->
678664 if Sys. file_exists p.Stunnel. logfile then
679665 begin
680666 if ! exit_status <> 0 then
@@ -683,9 +669,7 @@ let main () =
683669 with e -> debug " %s\n " (Printexc. to_string e));
684670 try Unix. unlink p.Stunnel. logfile with _ -> ()
685671 end ;
686- Stunnel. disconnect ~wait: false ~force: true p
687- | None -> ()
688- end ;
672+ Stunnel. disconnect ~wait: false ~force: true p) ! stunnel_processes;
689673 begin match ! debug_file, ! debug_channel with
690674 | Some f , Some ch -> begin
691675 close_out ch;
0 commit comments