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

Chris Maciejewski chris at wima.co.uk
Fri Apr 24 03:11:52 CDT 2009


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

(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.

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

> --
>               Tzafrir Cohen

Regards,
Chris



More information about the asterisk-dev mailing list