Re: GChildWatch source -- take two



Thus spake Jonathan Blandford:
> Here's another attempt at the GChildWatch source.  I incorporated most
> of the changes proposed, and hope it can now handle the single-threaded
> case better.  It now always writes down the pipe and doesn't count on
> poll being interrupted by the signal.
> 
> Comments?

I don't see any obvious races this time.

The fact that you can only install the signal handler after launching a
child still feels sort of like using uninitialized data.  I don't see
where this could be a problem, but then, I'm no Unix guru...

Two minor points:

> +static void
> +check_for_child_exited (GSource *source)
> +{
> +  GChildWatchSource *child_watch_source;
> +  volatile gint count;

I don't think this has to be volatile.

> +static void
> +g_child_watch_signal_handler (int signum)
> +{
> +  child_watch_count ++;
> +  /* guard against us modifying errno during the write */
> +  int old_errno = errno;

The declaration should be in the beginning of the block.

Now the bad news:  I'm afraid I wasn't able to run your child-test
correctly.  I don't really know the internals of GMainLoop, but if I
understood correctly, it was always the thread running in main that
called waitpid.  It always failed with ECHILD (No child processes).

Playing around a bit, strace -eclone showed that glibc was creating the
threads without passing CLONE_THREAD to clone(2).  This means that a
thread cannot wait for the child of another thread.  This is a bug in
LinuxThreads.

I'm using Debian unstable - glibc 2.3.1-17, linux 2.4.22-pre4.

Alexis



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]