This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: Expect goes crazy... spinning cpu in kill_pgrp
- From: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- To: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- Cc: cygwin-developers at cygwin dot com
- Date: Wed, 21 Oct 2009 21:23:46 +0100
- Subject: Re: Expect goes crazy... spinning cpu in kill_pgrp
- References: <4ADD6D96.8040604@gmail.com> <4ADF21CC.8030408@gmail.com>
Dave Korn wrote:
> I'm experimenting with this. It's not a full solution, it needs to do
> something a bit cleverer about /proc, but it should avoid the crashes.
No, not quite of course: there's still a trival TOCTOU race in, e.g.:
> _pinfo *p = pids[i];
>
> if (!p->exists () || ISSTATE(p, PID_EXECED))
> continue;
^^^^^^
here
vvvvvv
> /* Is it a process we want to kill? */
> if ((pid == 0 && (p->pgid != myself->pgid || p->ctty != myself->ctty)) ||
> (pid > 1 && p->pgid != pid) ||
> (si.si_signo < 0 && NOTSTATE (p, PID_STOPPED)))
> continue;
Argh. We could move those data members into the redir stub so it won't
crash if it touches them. But there are still likely to be race conditions
anyway, e.g. if we decide in that if() condition to kill the pid, then it
might still go to state PID_EXECED between the if() and when kill() gets to do
its stuff anyway. Hmm.
cheers,
DaveK