[asterisk-dev] no panic [was: Re: [svn-commits] tilghman: trunk r191283 - /trunk/main/asterisk.c]

Tzafrir Cohen tzafrir.cohen at xorcom.com
Thu Apr 30 02:39:18 CDT 2009


On Thu, Apr 30, 2009 at 06:47:31AM -0000, SVN commits to the Digium repositories wrote:
> 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));

To reduce panic level and be slightly more informative:

+				ast_log(LOG_WARNING, "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();

-- 
               Tzafrir Cohen
icq#16849755              jabber:tzafrir.cohen at xorcom.com
+972-50-7952406           mailto:tzafrir.cohen at xorcom.com
http://www.xorcom.com  iax:guest at local.xorcom.com/tzafrir



More information about the asterisk-dev mailing list