Summary:ASTERISK-20831: [patch] Restarted Asterisk process remains in original directory despite symlink change
Reporter:James Le Cuirot (chewi)Labels:
Date Opened:2012-12-19 07:32:38.000-0600Date Closed:2014-08-21 05:06:38
Versions:10.10.1 Frequency of
Environment:Fedora 17, Linux kernel 3.6.10-2.fc17.x86_64Attachments:( 0) chdir-pwd-on-restart.patch
Description:As noted in a previous bug report, I have successfully been running Asterisk configured with relative directories for easier deployment. This has been working well in itself but I have spotted a problem when combined with a Capistrano-style of deployment. New releases are checked out into a fresh directory and a "current" symlink is then updated to point to this directory before the application is restarted. In the case of Asterisk, I issue "core restart when convenient". The problem is that Asterisk remains pinned to the original release it was started from and any new configuration is therefore not picked up.

I have written a patch against trunk that issues a chdir to $PWD before the final execvp, which allows the symlink to be re-evaluated before the new instance comes up. $PWD is the only place where the symlinked path is stored as the kernel only holds a file descriptor to the real path. $PWD is not guaranteed to be present so obviously this is checked first. I was aware that Asterisk chdirs to / on startup in some cases so I thought maybe I'd also have to check whether this had happened but then I figured it would simply re-execute this code when starting up again anyway. I wasn't sure what to do if chdir fails so I ignored the result. At worst, it'll remain pinned to the old directory if the new one doesn't exist. That seems like a better and more backwards-compatible option than simply dying.
Comments:By: Michael L. Young (elguero) 2012-12-19 10:45:22.404-0600

What is the previous bug report that you refer to in the description?

Also, please review the Coding Guidelines, https://wiki.asterisk.org/wiki/display/AST/Coding+Guidelines, as there are some problems with your patch in regards to the lack of use of brackets and new lines.

By: James Le Cuirot (chewi) 2012-12-19 11:10:17.427-0600

Apologies for the formatting, I believe this is now correct. I added "const" as well.

The other bug report is ASTERISK-20593. I only mentioned it to add weight to the fact that I've been running Asterisk this way for a while and it generally works, despite it most likely not being intentionally supported.

By: Walter Doekes (wdoekes) 2014-08-11 03:50:00.142-0500

You should use getcwd() instead of getenv("PWD").

By: James Le Cuirot (chewi) 2014-08-11 04:01:47.751-0500

It's been a very long time since I looked at this but I given what I wrote before, I suspect I didn't use getcwd() either because it returns the real path or because Asterisk chdirs to /. Personally I'm moving away from Asterisk now but I still have some older systems on it.

By: Walter Doekes (wdoekes) 2014-08-21 05:06:11.699-0500

Ok. Thanks for the feedback.

Then I guess I can close it, since old versions won't be patched and no one else has been demanding this feature.