Re: Glib.IO.add_watch HUP signal issues on Mac OS X
Adrien Nader <[email protected]> Sun, 17 Nov 2013 20:31:43 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
Hi, On Wed, Nov 13, 2013, Piotr Esden-Tempski wrote: > Hi everyone, > > I am trying to debug an issue on Mac OS X. I tried to describe as much as I could with a bunch of examples here: https://github.com/paparazzi/paparazzi/issues/290 > > TLDR: When watching a pipe connected to a child process, Linux machines send a IO_HUP signal when the child exits. On Darwin this is not happening. The alternative used to be to wait for the OUT signal instead that. Since 10.8 the OUT signal is arriving immediately when a process starts, which breaks the kludgy fix. > > I bet that waiting for the OUT signal was a kludge in the first place. It was surprising that it was working in the first place, but it did the job. According to http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html#GIOCondition , using OUT was indeed very kludgy. I'm copying the doc below: IN There is data to read. OUT Data can be written (without blocking). PRI There is urgent data to read. ERR Error condition. HUP Hung up (the connection has been broken, usually for pipes and sockets). NVAL Invalid request. The file descriptor is not open. Have you tried with ERR too? > Now my questions. > > 1) Did anyone of you guys encounter this problem too? (Maybe I am just missing something very obvious.) I'm not running Mac OS X: it behaves too weirdly for my tastes. :) > 2) If there is no way of fixing this in lablgtk or glib and it actually is a bug in Darwin itself, what alternatives would you guys propose? It's difficult to say. It's not very likely that it's in lablgtk although it can obviously happen. For such issues, you would typically use "strace" to check which signals your parent program receives. I often use the command like "strace -tt -f -o log" and then open the file "log" in vim where I ":set ft=strace" to get syntax highlighting. Strace's output can be difficult to read without some training though; you need to look for "HUP" but if you can't understand it, link us to the log file and I can check it (mail attachment if the file isn't too big [maybe use gzip -9] or some other way of hosting it]). You can also try to make a short C-only reproducer. > During my research I found the child_watch_add function in glib. From my understanding this would be a perfect candidate to replace the way and purpose we are using add_watch for currently. But as far as I can tell it is not available through lablgtk2 bindings. So let me know if there is another way of asynchronously monitoring child processes. This doesn't look very complicated to add. Like anything glib, it introduces new types however; one that might be annoying is GPid: an int on Linux and others but a HANDLE on Windows and that means it might not fit very well with your existing code since it would be an opaque type. I won't have time to work on that myself before quite some however. -- Adrien Nader