[Asterisk-Dev] Bug 3203 "Get RT without runaway risk" revisited

Tzafrir Cohen tzafrir.cohen at xorcom.com
Fri Aug 5 08:46:13 MST 2005


On Fri, Aug 05, 2005 at 02:40:56PM +0200, Kristian Nielsen wrote:
> Kristian Nielsen <kn at sifira.dk> writes:
> 
> > This bug
> > 
> >     http://bugs.digium.com/view.php?id=3203
> > 
> > mentions several patches that implement a safeguard against running
> > Asterisk with realtime priority on Linux. Without such a solution, an
> > infinite loop anywhere in an Asterisk process running at realtime
> > priority can effectively kill the machine, locking out all other
> > processes (including root shells).
> > 
> > The bug has been suspended due to no activity, and we are now in the
> > need for this feature. So I just wanted to ask if anyone has some code
> > for this? Otherwise I will have a go at implementing it.
> 
> Ok, I wrote a simple wrapper script "asterisk_safe". This script forks
> two subprocesses, one running asterisk at realtime priority with the
> commandline specified, the other running a small watchdog loop at
> non-realtime priority. The parent then sets itself to a high realtime
> priority. Then if the parent detects cpu starvation for the watchdog
> process, it lowers asterisk to non-realtime priority. If it detects
> asterisk crash, the asterisk process is restarted.

But on a 100%cpu loop the watchdog process may never get a chance 
to run its code as Asterisk takes literally 100% of the CPU. The
watchdog should have real-time priority as well, right?

> 
> The wrapper is written in Perl, 

Which seems to support 'setpriority . see 'perldoc -f setpriority' .
Will only work for a process running as root. No need to re-implement it
yourself.

Also note that safe_asterisk is itself a wrapper. It has to execute
asterisk itself as root because Asterisk has to schedule itself with
real-time priority. Thus the thing to wrap around is really asterisk and
not safe_asterisk.

-- 
Tzafrir Cohen     icq#16849755  +972-50-7952406
tzafrir.cohen at xorcom.com  http://www.xorcom.com



More information about the asterisk-dev mailing list