* [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) [not found] ` <CALScVYmU7zEXbgdS21gGrq8iFvgVs0FWieKipRE9WtOM+PxeEg@mail.gmail.com> @ 2013-03-15 9:18 ` Florian Hars 2013-03-15 10:02 ` oliver 2013-03-15 11:38 ` Jeremie Dimino 0 siblings, 2 replies; 23+ messages in thread From: Florian Hars @ 2013-03-15 9:18 UTC (permalink / raw) To: ocsigen, caml-list Am 14.03.2013 18:53, schrieb Sebastien Mondet: > # Unix.system "date";; > Thu Mar 14 08:48:27 EST 2013 > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). > # That is just a bug in the unix library, Unix.system calls waitpid in caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l849 instead of waitpid_non_intr http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l1002 I get the same behaviour without lwt: OCaml version 4.00.1 # #load "unix.cma";; # Sys.set_signal 10 (Sys.Signal_handle (fun _ -> print_endline "A perfect ten"));; - : unit = () # Unix.system "sleep 20";; A perfect ten Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). # All I had to do is send a signal 10 to the ocaml process from another shell. It probably escaped notice so far because only lwt_unix does enough strange things with signals in the default config to trigger it reliably. - Florian. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 9:18 ` [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) Florian Hars @ 2013-03-15 10:02 ` oliver 2013-03-15 10:11 ` David House 2013-03-15 11:38 ` Jeremie Dimino 1 sibling, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 10:02 UTC (permalink / raw) To: caml-list; +Cc: ocsigen Hello, On Fri, Mar 15, 2013 at 10:18:56AM +0100, Florian Hars wrote: > Am 14.03.2013 18:53, schrieb Sebastien Mondet: > ># Unix.system "date";; > >Thu Mar 14 08:48:27 EST 2013 > >Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). > ># > > That is just a bug in the unix library, Unix.system calls waitpid in > > caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l849 > > instead of waitpid_non_intr > http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l1002 > > I get the same behaviour without lwt: > > OCaml version 4.00.1 > > # #load "unix.cma";; > # Sys.set_signal 10 (Sys.Signal_handle > (fun _ -> print_endline "A perfect ten"));; > - : unit = () > # Unix.system "sleep 20";; > A perfect ten > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). > # > > All I had to do is send a signal 10 to the ocaml process > from another shell. [...] I don't get such errors with normal OCaml-distribution 3.11.1 and also not with opam's ocaml and 4.00.1. So it seems to be lwt-problem. Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 10:02 ` oliver @ 2013-03-15 10:11 ` David House 0 siblings, 0 replies; 23+ messages in thread From: David House @ 2013-03-15 10:11 UTC (permalink / raw) To: oliver; +Cc: OCaml Mailing List, ocsigen FWIW, Core (and thus async) wraps all of its [waitpid] calls in a loop that restarts on EINTR. On 15 March 2013 10:02, oliver <oliver@first.in-berlin.de> wrote: > Hello, > > On Fri, Mar 15, 2013 at 10:18:56AM +0100, Florian Hars wrote: >> Am 14.03.2013 18:53, schrieb Sebastien Mondet: >> ># Unix.system "date";; >> >Thu Mar 14 08:48:27 EST 2013 >> >Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). >> ># >> >> That is just a bug in the unix library, Unix.system calls waitpid in >> >> caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l849 >> >> instead of waitpid_non_intr >> http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/version/4.00/otherlibs/unix/unix.ml?view=markup#l1002 >> >> I get the same behaviour without lwt: >> >> OCaml version 4.00.1 >> >> # #load "unix.cma";; >> # Sys.set_signal 10 (Sys.Signal_handle >> (fun _ -> print_endline "A perfect ten"));; >> - : unit = () >> # Unix.system "sleep 20";; >> A perfect ten >> Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). >> # >> >> All I had to do is send a signal 10 to the ocaml process >> from another shell. > [...] > > I don't get such errors with normal OCaml-distribution 3.11.1 > and also not with opam's ocaml and 4.00.1. > > So it seems to be lwt-problem. > > Ciao, > Oliver > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 9:18 ` [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) Florian Hars 2013-03-15 10:02 ` oliver @ 2013-03-15 11:38 ` Jeremie Dimino 2013-03-15 12:43 ` oliver 1 sibling, 1 reply; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 11:38 UTC (permalink / raw) To: caml-list; +Cc: ocsigen On Fri, Mar 15, 2013 at 9:18 AM, Florian Hars <florian@hars.de> wrote: > It probably escaped notice so far because only lwt_unix does enough strange > things with signals in the default config to trigger it reliably. Indeed. BTW the only "strange" thing lwt does by default with signals is to set a handler for SIGCHLD. Actually here is a way to reproduce this behavior without lwt on OSX and some other systems: # #load "unix.cma";; # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; - : unit = () # Unix.system "true";; Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). This will happen in any program setting a handler for SIGCHLD. To avoid this you can: - if you are using lwt, use Lwt_unix.system - block SIGCHLD in the current thread while calling Unix.system - write your own system function Maybe this should be the default behavior. Can you open a ticket on mantis about this? Cheers, Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 11:38 ` Jeremie Dimino @ 2013-03-15 12:43 ` oliver 2013-03-15 13:17 ` Jeremie Dimino 2013-03-15 13:24 ` Jeremie Dimino 0 siblings, 2 replies; 23+ messages in thread From: oliver @ 2013-03-15 12:43 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 11:38:06AM +0000, Jeremie Dimino wrote: > On Fri, Mar 15, 2013 at 9:18 AM, Florian Hars <florian@hars.de> wrote: > > It probably escaped notice so far because only lwt_unix does enough strange > > things with signals in the default config to trigger it reliably. > > Indeed. BTW the only "strange" thing lwt does by default with signals > is to set a handler for SIGCHLD. > > Actually here is a way to reproduce this behavior without lwt on OSX > and some other systems: > > # #load "unix.cma";; > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > - : unit = () > # Unix.system "true";; > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). [...] ========================================================= oliver@siouxsie:~$ ledit ocaml Objective Caml version 3.11.2 Unknown directive `require'. # #load "unix.cma";; # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; - : unit = () # Unix.system "true";; - : Unix.process_status = Unix.WEXITED 0 # ========================================================= ========================================================= oliver@siouxsie:~$ source ocamlbrew/ocaml-4.00.1/etc/ocamlbrew.bashrc oliver@siouxsie:~$ ledit ocaml OCaml version 4.00.1 Unknown directive `require'. # #load "unix.cma";; # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; - : unit = () # Unix.system "true";; - : Unix.process_status = Unix.WEXITED 0 # ========================================================= > > This will happen in any program setting a handler for SIGCHLD. I wonder if "any program setting a handler for SIGCHLD" means "program setting a handler for SIGCHLD", or only "program setting a handler for SIGCHLD, using lwt". Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 12:43 ` oliver @ 2013-03-15 13:17 ` Jeremie Dimino 2013-03-15 13:28 ` oliver 2013-03-15 13:24 ` Jeremie Dimino 1 sibling, 1 reply; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 13:17 UTC (permalink / raw) To: oliver; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 12:43 PM, oliver <oliver@first.in-berlin.de> wrote: > On Fri, Mar 15, 2013 at 11:38:06AM +0000, Jeremie Dimino wrote: >> Actually here is a way to reproduce this behavior without lwt on OSX >> and some other systems: What system are you using? I didn't say it but "some other systems" did't included Linux. >> This will happen in any program setting a handler for SIGCHLD. > > I wonder if "any program setting a handler for SIGCHLD" means > "program setting a handler for SIGCHLD", or only > "program setting a handler for SIGCHLD, using lwt". The first one. Cheers, Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 13:17 ` Jeremie Dimino @ 2013-03-15 13:28 ` oliver 2013-03-15 13:43 ` Jeremie Dimino 0 siblings, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 13:28 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 01:17:43PM +0000, Jeremie Dimino wrote: > On Fri, Mar 15, 2013 at 12:43 PM, oliver <oliver@first.in-berlin.de> wrote: > > On Fri, Mar 15, 2013 at 11:38:06AM +0000, Jeremie Dimino wrote: > >> Actually here is a way to reproduce this behavior without lwt on OSX > >> and some other systems: > > What system are you using? I didn't say it but "some other systems" > did't included Linux. I use Linux. No problems here. > > >> This will happen in any program setting a handler for SIGCHLD. > > > > I wonder if "any program setting a handler for SIGCHLD" means > > "program setting a handler for SIGCHLD", or only > > "program setting a handler for SIGCHLD, using lwt". > > The first one. So you mean, "any program", also with original OCaml's unix-module, but only on non-Linux? Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 13:28 ` oliver @ 2013-03-15 13:43 ` Jeremie Dimino 0 siblings, 0 replies; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 13:43 UTC (permalink / raw) To: oliver; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 1:28 PM, oliver <oliver@first.in-berlin.de> wrote: > So you mean, "any program", also with original OCaml's unix-module, > but only on non-Linux? For this particular example it is only on non-Linux. In the general case where the process receive a SIGCHLD for another process that the one it is waiting for (my second example) it is for any system and also with original OCaml's unix-module. Cheers, Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 12:43 ` oliver 2013-03-15 13:17 ` Jeremie Dimino @ 2013-03-15 13:24 ` Jeremie Dimino 2013-03-15 13:58 ` oliver 2013-03-15 14:17 ` oliver 1 sibling, 2 replies; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 13:24 UTC (permalink / raw) To: oliver; +Cc: caml-list, ocsigen BTW, here is an example that will work on all unix systems: # #load "unix.cma";; # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; - : unit = () # let ic = Unix.open_process_in "sleep 5";; val ic : in_channel = <abstr> # Unix.system "sleep 10";; Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). Jeremie On Fri, Mar 15, 2013 at 12:43 PM, oliver <oliver@first.in-berlin.de> wrote: > ========================================================= > oliver@siouxsie:~$ source ocamlbrew/ocaml-4.00.1/etc/ocamlbrew.bashrc > oliver@siouxsie:~$ ledit ocaml > OCaml version 4.00.1 > > Unknown directive `require'. > # #load "unix.cma";; > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > - : unit = () > # Unix.system "true";; > - : Unix.process_status = Unix.WEXITED 0 > # > ========================================================= ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 13:24 ` Jeremie Dimino @ 2013-03-15 13:58 ` oliver 2013-03-15 14:05 ` oliver 2013-03-15 14:17 ` oliver 1 sibling, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 13:58 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen Hi, On Fri, Mar 15, 2013 at 01:24:10PM +0000, Jeremie Dimino wrote: > BTW, here is an example that will work on all unix systems: > > # #load "unix.cma";; > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > - : unit = () > # let ic = Unix.open_process_in "sleep 5";; > val ic : in_channel = <abstr> > # Unix.system "sleep 10";; > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). [...] If you want to use Unix-module, you should use it consequently, not switching to Sys-module, when you want to handle signals. Try this one: open Unix;; let new_mask = sigprocmask SIG_BLOCK [10] in let ic = Unix.open_process_in "sleep 5" in Unix.system "sleep 10";; Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 13:58 ` oliver @ 2013-03-15 14:05 ` oliver 2013-03-15 14:16 ` Jeremie Dimino 0 siblings, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 14:05 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 02:58:23PM +0100, oliver wrote: > Hi, > > On Fri, Mar 15, 2013 at 01:24:10PM +0000, Jeremie Dimino wrote: > > BTW, here is an example that will work on all unix systems: > > > > # #load "unix.cma";; > > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > > - : unit = () > > # let ic = Unix.open_process_in "sleep 5";; > > val ic : in_channel = <abstr> > > # Unix.system "sleep 10";; > > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). > [...] > > > If you want to use Unix-module, you should use it consequently, > not switching to Sys-module, when you want to handle signals. > > > Try this one: > > open Unix;; > let new_mask = sigprocmask SIG_BLOCK [10] in > let ic = Unix.open_process_in "sleep 5" in > Unix.system "sleep 10";; Hahah... works even with empty list :-) Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 14:05 ` oliver @ 2013-03-15 14:16 ` Jeremie Dimino 2013-03-15 14:18 ` oliver 0 siblings, 1 reply; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 14:16 UTC (permalink / raw) To: oliver; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 2:05 PM, oliver <oliver@first.in-berlin.de> wrote: >> Try this one: >> >> open Unix;; >> let new_mask = sigprocmask SIG_BLOCK [10] in >> let ic = Unix.open_process_in "sleep 5" in >> Unix.system "sleep 10";; > > Hahah... works even with empty list :-) Of course. It works even without the sigprocmask. The default disposition for SIGCHLD is "ignore", so if there is no signal handler it will just be ignored... Cheers, Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 14:16 ` Jeremie Dimino @ 2013-03-15 14:18 ` oliver 0 siblings, 0 replies; 23+ messages in thread From: oliver @ 2013-03-15 14:18 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 02:16:01PM +0000, Jeremie Dimino wrote: > On Fri, Mar 15, 2013 at 2:05 PM, oliver <oliver@first.in-berlin.de> wrote: > >> Try this one: > >> > >> open Unix;; > >> let new_mask = sigprocmask SIG_BLOCK [10] in > >> let ic = Unix.open_process_in "sleep 5" in > >> Unix.system "sleep 10";; > > > > Hahah... works even with empty list :-) > > Of course. It works even without the sigprocmask. The default > disposition for SIGCHLD is "ignore", so if there is no signal handler > it will just be ignored... Yes. But why isn't the default active without calling sigprocmask? The default should be active by default. Otherwise, it's not the default. Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 13:24 ` Jeremie Dimino 2013-03-15 13:58 ` oliver @ 2013-03-15 14:17 ` oliver 2013-03-15 14:27 ` oliver 1 sibling, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 14:17 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 01:24:10PM +0000, Jeremie Dimino wrote: > BTW, here is an example that will work on all unix systems: > > # #load "unix.cma";; > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > - : unit = () > # let ic = Unix.open_process_in "sleep 5";; > val ic : in_channel = <abstr> > # Unix.system "sleep 10";; > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). [...] As far as I can see, Sys.signal uses signal(2), which is the unreliable C-style/-semantics signal handling function. You need to use sigprocmask to have reliable signals. Why sigprocmask was working with empty list, I'm explring now. This is a bit strange to me... Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 14:17 ` oliver @ 2013-03-15 14:27 ` oliver 2013-03-15 15:05 ` Jeremie Dimino 0 siblings, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 14:27 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 03:17:35PM +0100, oliver wrote: > On Fri, Mar 15, 2013 at 01:24:10PM +0000, Jeremie Dimino wrote: > > BTW, here is an example that will work on all unix systems: > > > > # #load "unix.cma";; > > # Sys.set_signal Sys.sigchld (Sys.Signal_handle ignore);; > > - : unit = () > > # let ic = Unix.open_process_in "sleep 5";; > > val ic : in_channel = <abstr> > > # Unix.system "sleep 10";; > > Exception: Unix.Unix_error (Unix.EINTR, "waitpid", ""). > [...] > > As far as I can see, Sys.signal uses signal(2), > which is the unreliable C-style/-semantics > signal handling function. > > You need to use sigprocmask to have reliable > signals. > > Why sigprocmask was working with empty list, > I'm explring now. This is a bit strange to me... [...] Crap. Anything works fine: open Unix;; let ic = Unix.open_process_in "sleep 5" in Unix.system "sleep 10";; No problems. Just by your activation of signal function - not blocking, but handling "Sys.Signal_handle" but with the unreliable signal semantics this has cause the problems. signal(2) opened the pandoras box. Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 14:27 ` oliver @ 2013-03-15 15:05 ` Jeremie Dimino 2013-03-15 15:11 ` oliver 2013-03-15 15:16 ` oliver 0 siblings, 2 replies; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 15:05 UTC (permalink / raw) To: oliver; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 2:27 PM, oliver <oliver@first.in-berlin.de> wrote: > Just by your activation of signal function > - not blocking, but handling "Sys.Signal_handle" but with the unreliable signal semantics > this has cause the problems. > > signal(2) opened the pandoras box. Actually OCaml is using sigaction(2). It is only using signal(2) when sigaction is not available. Actually there are two different things here: - signal disposition: this is a process-wide settings for each signal describing how to react when it is received. It can be changed with the [sigaction] system call (or the less portable [signal]). - signal mask: it is a per-thread set of signals that are blocked. It can be changed with sigprocmask. When a signal is received by a thread, if it is blocked it will be pending until it is unblocked. When it is not blocked and the threaded is waiting on an interruptible system call and the disposition of the signal is a user-defined handler, the system call will fail with EINTR and the handler will be invoked. So basically Sys.set_signal and Unix.sigprocmask are two different things. You should block signals when you are running some code that you don't want to be interrupted: # #load "unix.cma";; # Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun _ -> print_endline "signal!"));; - : unit = () # let old_mask = Unix.sigprocmask Unix.SIG_BLOCK [Sys.sigusr1];; val old_mask : int list = [] # Unix.kill (Unix.getpid ()) Sys.sigusr1;; - : unit = () # Unix.sigprocmask Unix.SIG_SETMASK old_mask;; signal! - : int list = [-12] The man page describing all this is signal(7). Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 15:05 ` Jeremie Dimino @ 2013-03-15 15:11 ` oliver 2013-03-15 15:44 ` Gabriel Kerneis 2013-03-15 15:16 ` oliver 1 sibling, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 15:11 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 03:05:51PM +0000, Jeremie Dimino wrote: > On Fri, Mar 15, 2013 at 2:27 PM, oliver <oliver@first.in-berlin.de> wrote: > > Just by your activation of signal function > > - not blocking, but handling "Sys.Signal_handle" but with the unreliable signal semantics > > this has cause the problems. > > > > signal(2) opened the pandoras box. > > Actually OCaml is using sigaction(2). It is only using signal(2) when > sigaction is not available. > > Actually there are two different things here: > > - signal disposition: this is a process-wide settings for each signal > describing how to react when it is received. It can be changed with > the [sigaction] system call (or the less portable [signal]). > - signal mask: it is a per-thread set of signals that are blocked. It > can be changed with sigprocmask. > > When a signal is received by a thread, if it is blocked it will be > pending until it is unblocked. When it is not blocked and the > threaded is waiting on an interruptible system call and the > disposition of the signal is a user-defined handler, the system call > will fail with EINTR and the handler will be invoked. > > So basically Sys.set_signal and Unix.sigprocmask are two different > things. You should block signals when you are running some code that > you don't want to be interrupted: > > # #load "unix.cma";; > # Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun _ -> > print_endline "signal!"));; > - : unit = () > # let old_mask = Unix.sigprocmask Unix.SIG_BLOCK [Sys.sigusr1];; > val old_mask : int list = [] > # Unix.kill (Unix.getpid ()) Sys.sigusr1;; > - : unit = () > # Unix.sigprocmask Unix.SIG_SETMASK old_mask;; > signal! > - : int list = [-12] > > The man page describing all this is signal(7). [...] I don't know why you are telling me this. i did not asked about it. But if you wish to explain it to yourself, go on. Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 15:11 ` oliver @ 2013-03-15 15:44 ` Gabriel Kerneis 2013-03-15 16:00 ` oliver 0 siblings, 1 reply; 23+ messages in thread From: Gabriel Kerneis @ 2013-03-15 15:44 UTC (permalink / raw) To: oliver; +Cc: Jeremie Dimino, caml-list, ocsigen Oliver, > I don't know why you are telling me this. > i did not asked about it. Jérémie is kindly trying to show you why you are mistaken. When you say: > > > Just by your activation of signal function - not blocking, but handling > > > "Sys.Signal_handle" but with the unreliable signal semantics this has > > > cause the problems. > > > > > > signal(2) opened the pandoras box. This is wrong. Because OCaml does not call signal(2). At all. So there is no "pandora box" to open, no "unreliable signal semantics" used. Sys.set_signal = sigaction(2) ≠ signal(2) (And sigprocmask(2) is irrelevant here: it is also part of the "reliable semantics", but does something different from sigaction(2), as Jérémie told you.) > But if you wish to explain it to yourself, go on. You are not only rude but also completely missing the point here. -- Gabriel ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 15:44 ` Gabriel Kerneis @ 2013-03-15 16:00 ` oliver 2013-03-15 16:12 ` Gabriel Kerneis 0 siblings, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 16:00 UTC (permalink / raw) To: Gabriel Kerneis; +Cc: Jeremie Dimino, caml-list, ocsigen On Fri, Mar 15, 2013 at 03:44:14PM +0000, Gabriel Kerneis wrote: > Oliver, > > > I don't know why you are telling me this. > > i did not asked about it. > > Jérémie is kindly trying to show you why you are mistaken. I did not see it from his explanation that signal(2) is not called. > When you say: > > > > > Just by your activation of signal function - not blocking, but handling > > > > "Sys.Signal_handle" but with the unreliable signal semantics this has > > > > cause the problems. > > > > > > > > signal(2) opened the pandoras box. > > This is wrong. Because OCaml does not call signal(2). At all. So there is no > "pandora box" to open, no "unreliable signal semantics" used. > > Sys.set_signal = sigaction(2) > ≠ signal(2) From this kind of explanation I see more. The problem occures when using the signal handler from Sys, not from unix module. It was stated that the unix module is doing things wrong. But the Unix signalling mechanism was not used. I wait for an example which uses Unix module for the signals and fails. have not seen it so far. So, then interaction of Sys- and Unix.-module may be a problem. But the Code did not used Unix-module. So it's also wrong to state Unix module makes problems and is buggy, if the example don't uses it for the signal handling. I had the assumption that Sys-module uses signal(2). It may be wrong (did not eplored the sources). But then there is the problem, not in Unix-module. Also I wonder why threads were mentioned. In the test code via the list was nothing from Thread-module involved. > > (And sigprocmask(2) is irrelevant here: it is also part of the "reliable > semantics", but does something different from sigaction(2), as Jérémie told > you.) I never said that sigrpocmask or sigactiona re non-reliable. signal(2) is non-reliable. That was my point, toigether with Assumption of signal(2) in Sys-sighandlers. > > > But if you wish to explain it to yourself, go on. > > You are not only rude but also completely missing the point here. You also missed my point. What I have overlooked at the beginning was, that Sys.* was used and not Unix.* and when I saw that later, I was a bit astouned and confused. So I removed the Sys.* signal stuff. Then there was no problem in the code. I'm still waiting for the code that shows that unix.ml is buggy. If Sys.<signalstuff> is also using sigprocmask/sigactio/sig[^nal]foobar then Sys.* is the problem. That was my point. Maybe I was not clear in explaining this. So... back to beginning of the Thread: where is Unix module failing on signals? Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 16:00 ` oliver @ 2013-03-15 16:12 ` Gabriel Kerneis 2013-03-15 16:25 ` oliver 0 siblings, 1 reply; 23+ messages in thread From: Gabriel Kerneis @ 2013-03-15 16:12 UTC (permalink / raw) To: oliver; +Cc: Jeremie Dimino, caml-list, ocsigen Oliver, On Fri, Mar 15, 2013 at 05:00:45PM +0100, oliver wrote: > The problem occures when using the signal handler from Sys, > not from unix module. Could you please (at least) read the documentation before contributing to this thread again? > It was stated that the unix module is doing things wrong. > But the Unix signalling mechanism was not used. Let me quote it for you: ### Signals ### Note: installation of signal handlers is performed via the functions Sys.signal and Sys.set_signal. -- http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html#6_Signals So the Unix module does not provide any way to setup a signal handler. You have to use Sys. Your requirement of demonstrating the issue using Unix only is silly. Period. -- Gabriel ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 16:12 ` Gabriel Kerneis @ 2013-03-15 16:25 ` oliver 2013-03-15 17:28 ` Jeremie Dimino 0 siblings, 1 reply; 23+ messages in thread From: oliver @ 2013-03-15 16:25 UTC (permalink / raw) To: Gabriel Kerneis; +Cc: Jeremie Dimino, caml-list, ocsigen On Fri, Mar 15, 2013 at 04:12:41PM +0000, Gabriel Kerneis wrote: > Oliver, > > On Fri, Mar 15, 2013 at 05:00:45PM +0100, oliver wrote: > > The problem occures when using the signal handler from Sys, > > not from unix module. > > Could you please (at least) read the documentation before contributing to this > thread again? > > > It was stated that the unix module is doing things wrong. > > But the Unix signalling mechanism was not used. > > Let me quote it for you: > > ### Signals ### > Note: installation of signal handlers is performed via the functions > Sys.signal and Sys.set_signal. > -- http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html#6_Signals OK, I was wrong here. I had in mind there was a sigaction-function in Unix module also. My fault, should better have looked it up again, after so long not using it. My apologies too Dimino. Didn't saw what you wanted to point me too. > > So the Unix module does not provide any way to setup a signal handler. You have > to use Sys. Your requirement of demonstrating the issue using Unix only is > silly. Period. Hahah, people say I'm rude and they are themselves. Welcome in the club. :) Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 16:25 ` oliver @ 2013-03-15 17:28 ` Jeremie Dimino 0 siblings, 0 replies; 23+ messages in thread From: Jeremie Dimino @ 2013-03-15 17:28 UTC (permalink / raw) To: oliver; +Cc: Gabriel Kerneis, caml-list, ocsigen On Fri, Mar 15, 2013 at 4:25 PM, oliver <oliver@first.in-berlin.de> wrote: > My apologies too Dimino. Apologies accepted ;) BTW, I opened a ticket about catching EINTR in Unix.system: http://caml.inria.fr/mantis/view.php?id=5953 Cheers, Jeremie ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) 2013-03-15 15:05 ` Jeremie Dimino 2013-03-15 15:11 ` oliver @ 2013-03-15 15:16 ` oliver 1 sibling, 0 replies; 23+ messages in thread From: oliver @ 2013-03-15 15:16 UTC (permalink / raw) To: Jeremie Dimino; +Cc: caml-list, ocsigen On Fri, Mar 15, 2013 at 03:05:51PM +0000, Jeremie Dimino wrote: [...] > Actually OCaml is using sigaction(2). It is only using signal(2) when > sigaction is not available. [...] Possibly on non-unixoid systems, e.g. Windows. > > Actually there are two different things here: > > - signal disposition: this is a process-wide settings for each signal > describing how to react when it is received. It can be changed with > the [sigaction] system call (or the less portable [signal]). > - signal mask: it is a per-thread set of signals that are blocked. It > can be changed with sigprocmask. sigprocmask and sigaction and so on all work on processes. Mixing processes and threads (especially involving signals) can be tricky. Using signal(2) is deprecated in general. If you use Windows, it might be necessary, because unix-moulde is for Unix. Don't know if cygwin and similar environments allow usage of unix-module. But even if they do, I'm not sure it works like in real unixoid systems. Ciao, Oliver ^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2013-03-15 17:28 UTC | newest] Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CAMu2m2Lt8oty_2mEQq8H1oV0-1Rjrf10ai543me9YxB1Nb5xfg@mail.gmail.com> [not found] ` <CALScVY=c1M=HAqMeM7x4QrxDTZsn0rB=HcTsQYheYUOBSBFRUQ@mail.gmail.com> [not found] ` <CALScVYnt-m-dRR41rBPo5R3xDx-81tMwBFbM3q+5p4gRqsQC9w@mail.gmail.com> [not found] ` <CALScVYmU7zEXbgdS21gGrq8iFvgVs0FWieKipRE9WtOM+PxeEg@mail.gmail.com> 2013-03-15 9:18 ` [Caml-list] BUG in unix.ml (was: strange errors when linking lwt.unix) Florian Hars 2013-03-15 10:02 ` oliver 2013-03-15 10:11 ` David House 2013-03-15 11:38 ` Jeremie Dimino 2013-03-15 12:43 ` oliver 2013-03-15 13:17 ` Jeremie Dimino 2013-03-15 13:28 ` oliver 2013-03-15 13:43 ` Jeremie Dimino 2013-03-15 13:24 ` Jeremie Dimino 2013-03-15 13:58 ` oliver 2013-03-15 14:05 ` oliver 2013-03-15 14:16 ` Jeremie Dimino 2013-03-15 14:18 ` oliver 2013-03-15 14:17 ` oliver 2013-03-15 14:27 ` oliver 2013-03-15 15:05 ` Jeremie Dimino 2013-03-15 15:11 ` oliver 2013-03-15 15:44 ` Gabriel Kerneis 2013-03-15 16:00 ` oliver 2013-03-15 16:12 ` Gabriel Kerneis 2013-03-15 16:25 ` oliver 2013-03-15 17:28 ` Jeremie Dimino 2013-03-15 15:16 ` oliver
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox