[svn-commits] tilghman: trunk r191283 - /trunk/main/asterisk.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Apr 30 01:47:31 CDT 2009


Author: tilghman
Date: Thu Apr 30 01:47:13 2009
New Revision: 191283

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=191283
Log:
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

Modified:
    trunk/main/asterisk.c

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/asterisk.c?view=diff&rev=191283&r1=191282&r2=191283
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu Apr 30 01:47:13 2009
@@ -3435,6 +3435,23 @@
 			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();




More information about the svn-commits mailing list