[asterisk-dev] Shouldn't Asterisk call chdir("/") when becoming a daemon?

Tzafrir Cohen tzafrir.cohen at xorcom.com
Fri Apr 24 11:11:19 CDT 2009


On Fri, Apr 24, 2009 at 09:11:52AM +0100, Chris Maciejewski wrote:
> Hi Tzafrir,
> 
> 2009/4/23 Tzafrir Cohen <tzafrir.cohen at xorcom.com>:
> > On Wed, Apr 22, 2009 at 10:33:44PM +0100, Chris Maciejewski wrote:
> >
> >> so looks like asterisk is not calling chdir("/") anywhere, apart from
> >> res/res_musiconhold.c .
> >> AFAIK it is a recommended for all linux daemon processes to call
> >> chdir("/") when forking.
> >
> > It originally did. But daemon(3) is now explicitly called with nochdir=1
> > to simplify dumping cores.
> 
> I think the better idea is to manage core dumps location by:
> 
> echo "/tmp/corefiles/core" > /proc/sys/kernel/core_pattern

This is a global setting. I don't think Asterisk can rely on it.
Oh, and while you're at it:

echo "/tmp/corefiles/core-%e-%t" > /proc/sys/kernel/core_pattern

> 
> (See 'man core')
> 
> and set working directory to "/".
> 
> At the moment a working directory is wherever Asterisk was started.
> This introduces the following bug:
> 
> 1. Asterisk is started with "-G asterisk -U asterisk" options in
> "/root" directory owned by 'root' user with permissions: "drwx------"
> 2. Current working directory is set to "/root".
> 3. When scanning MoH files, Asterisk tries to change directory to
> "current_working_dir" (res_musiconhold.c line 967) which fails because
> 'asterisk' user is lacking permission to do so.

This is a bug, IMHO. The test there is pointless (it is duplicated
below). And I find it strange to see a process-wide chdir() . I wonder
what happes if two such "save working directory; cd somewhere; restore
working directory" routines run concurrently.

> 
> Setting working directory to "/" when demonizing would prevent the above issue.

I do agree that it is a good idea nevertheless.

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



More information about the asterisk-dev mailing list