0

I need to be able to collect core dumps, but since Asterisk's CWD is / (so claims procfs), it'll never be able to write them. I've confirmed my suspicions by allowing world write to / and SIGABRT the process, lo and behold, I had a core.

I can obviously use core_pattern to override system-wide, but I rather like the default behavior of dumping core to the cwd. Every other Asterisk install I've worked on, the cwd is /tmp, but for some reason this new one it's /. I tried to `cd /tmp' in the Asterisk service start script, but that was uneventful.

This is Asterisk C.3.7.2 on Debian 7.1, there is no chdir() in the source that specifically sets it to /.

Chris S
  • 93
  • 4

1 Answers1

1

Asterisk, like many daemons, does a chdir('/') when turning itself into a daemon.

main/asterisk.c
3675:           if (chdir("/")) {

This is to make sure it doesn't keep a directory open that you may want to delete later. To prevent asterisk from doing this, you will need to run asterisk in the foreground using asterisk -f.

Though not documented, the -g flag also has the effect of not changing directory. Its documentation says:

   -g     Remove  resource  limit  on  core size, thus forcing Asterisk to
          dump core in the unlikely event of a segmentation fault or abort
          signal.   NOTE:  in some cases this may be incompatible with the
          -U or -G flags.

And reading the source code tells me that it also prevents the chdir("/")

Dennis Kaarsemaker
  • 19,277
  • 2
  • 44
  • 70
  • Thank you for pointing me in the right direction. While my version of asterisk.c does not chdir at all, the -f was the key. Every single asterisk server in my environment, except for this new one, uses safe_asterisk. safe_asterisk provides the foreground operation and changing to /tmp before executing asterisk. – Chris S Aug 19 '13 at 18:52
  • It's a shame I didn't reload the page before posting my commend, or I would have seen your edit. The function of the `-g` flag must have changed between my version, Asterisk Business Edition (ABE) C3.7.2 (rel Nov 2012), and the revision you're looking at. In mine, -g is required for core dumps to work at all and the only `chdir()`s in the entire source tree are in `res/res_musiconhold.c` and `utils/smsq.c`. Again, thank you for the time you've spent. – Chris S Aug 19 '13 at 19:05