aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-30 06:48:50 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-30 06:48:50 +0000
commit5a38b1c981e2b0c19438e5d439d053fb42addf4b (patch)
tree3bedcd247a3cd89f6e274fdc16d503daf9b4a134 /main/asterisk.c
parentf7b4235d897f98e36c5fbf4cd4a006fd3289d187 (diff)
Merged revisions 191283 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r191283 | tilghman | 2009-04-30 01:47:13 -0500 (Thu, 30 Apr 2009) | 11 lines Change working directory to / under certain conditions. If backgrounding and no core will be produced, then changing the directory won't break anything; likewise, if the CWD isn't accessible by the current user, then a core wasn't possible anyway. (closes issue #14831) Reported by: chris-mac Patches: 20090428__bug14831.diff.txt uploaded by tilghman (license 14) 20090430__bug14831.diff.txt uploaded by tilghman (license 14) Tested by: chris-mac ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@191285 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index e3c83f14a..2eafe61b4 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3279,6 +3279,23 @@ int main(int argc, char *argv[])
ast_log(LOG_WARNING, "Unable to set the process for core dumps after changing to a non-root user. %s\n", strerror(errno));
}
}
+
+ {
+ char dir[PATH_MAX];
+ if (!getcwd(dir, sizeof(dir)) || eaccess(dir, R_OK | X_OK | F_OK)) {
+ ast_log(LOG_ERROR, "Unable to access the running directory (%s). Changing to '/' for compatibility.\n", strerror(errno));
+ /* If we cannot access the CWD, then we couldn't dump core anyway,
+ * so chdir("/") won't break anything. */
+ if (chdir("/")) {
+ ast_log(LOG_ERROR, "chdir() failed?!! %s\n", strerror(errno));
+ }
+ } else if (!ast_opt_no_fork && !ast_opt_dump_core) {
+ /* Backgrounding, but no cores, so chdir won't break anything. */
+ if (chdir("/")) {
+ ast_log(LOG_ERROR, "Unable to chdir(\"/\") ?!! %s\n", strerror(errno));
+ }
+ }
+ }
#endif
ast_term_init();