11open Picos
22open Picos_sync
33
4- let handle_sigchld_bit = 0b01
5- let select_thread_running_on_main_domain_bit = 0b10
4+ let handle_sigchld_bit = 0b001
5+ let select_thread_running_on_main_domain_bit = 0b010
6+ let ignore_sigpipe_bit = 0b100
67
78type config = {
89 mutable bits : int ;
@@ -267,10 +268,12 @@ let select_thread s =
267268 if s.pipe_out != Unix. stdin then Unix. close s.pipe_out
268269
269270let [@ poll error] [@ inline never] try_configure ~intr_sig ~intr_sigs
270- ~handle_sigchld =
271+ ~handle_sigchld ~ignore_sigpipe =
271272 config.intr_sigs == []
272273 && begin
273- config.bits < - Bool. to_int handle_sigchld;
274+ config.bits < -
275+ Bool. to_int handle_sigchld
276+ lor (ignore_sigpipe_bit land - Bool. to_int ignore_sigpipe);
274277 config.intr_sig < - intr_sig;
275278 config.intr_sigs < - intr_sigs;
276279 true
@@ -296,17 +299,24 @@ let reconfigure_signal_handlers () =
296299 if config.bits land handle_sigchld_bit <> 0 then begin
297300 Sys. signal Sys. sigchld (Sys. Signal_handle handle_signal) |> ignore;
298301 Thread. sigmask SIG_BLOCK [ Sys. sigchld ] |> ignore
302+ end ;
303+ if config.bits land ignore_sigpipe_bit <> 0 then begin
304+ Sys. signal Sys. sigpipe Signal_ignore |> ignore
299305 end
300306 end
301307
302- let configure ?(intr_sig = Sys. sigusr2) ?(handle_sigchld = true ) () =
308+ let configure ?(intr_sig = Sys. sigusr2) ?(handle_sigchld = true )
309+ ?(ignore_sigpipe = true ) () =
303310 if not (Picos_thread. is_main_thread () ) then
304311 invalid_arg " must be called from the main thread on the main domain" ;
305312 assert (Sys. sigabrt = - 1 && Sys. sigxfsz < Sys. sigabrt);
306313 if intr_sig < Sys. sigxfsz || 0 < = intr_sig || intr_sig = Sys. sigchld then
307314 invalid_arg " invalid interrupt signal number" ;
308- if not (try_configure ~intr_sig ~intr_sigs: [ intr_sig ] ~handle_sigchld ) then
309- invalid_arg " already configured" ;
315+ if
316+ not
317+ (try_configure ~intr_sig ~intr_sigs: [ intr_sig ] ~handle_sigchld
318+ ~ignore_sigpipe )
319+ then invalid_arg " already configured" ;
310320
311321 reconfigure_signal_handlers ()
312322
0 commit comments