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

Chris Maciejewski chris at wima.co.uk
Thu Apr 23 01:07:24 CDT 2009


Hi Michiel,

2009/4/22 Michiel van Baak <michiel at vanbaak.info>:
> On 22:33, Wed 22 Apr 09, Chris Maciejewski wrote:
>> Hi,
>>
>> Running in the asterisk source directory:
>>
>> $ find . -name "*.c" -exec grep -Hn 'chdir(' {} \;
>>
>> only produces:
>>
>> ./res/res_musiconhold.c:495:          if (strcasecmp(class->dir, "nodir") &&
>> chdir(class->dir) < 0) {
>> ./res/res_musiconhold.c:496:                  ast_log(LOG_WARNING, "chdir() failed:
>> %s\n", strerror(errno));
>> ./res/res_musiconhold.c:917:  if (chdir(class->dir) < 0) {
>> ./res/res_musiconhold.c:918:          ast_log(LOG_WARNING, "chdir() failed:
>> %s\n", strerror(errno));
>> ./res/res_musiconhold.c:957:  if (chdir(path) < 0) {
>> ./res/res_musiconhold.c:958:          ast_log(LOG_WARNING, "chdir() failed:
>> %s\n", strerror(errno));
>>
>> 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.
>
> We've had this patch in the OpenBSD port for years.
> Removing it did not change anything, so we also removed this patch from
> our port.
>
> Can you tell us what problem this fixes ?

It seems to me, changing working directory to "/" will fix this bug:
http://bugs.digium.com/view.php?id=14831

> We did not see any difference with or without this patch.
>
> --
>
> Michiel van Baak
> michiel at vanbaak.eu
> http://michiel.vanbaak.eu
> GnuPG key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x71C946BD
>

Regards,
Chris



More information about the asterisk-dev mailing list