--- parser3/src/main/pa_exec.C 2003/11/20 15:35:31 1.53 +++ parser3/src/main/pa_exec.C 2004/07/07 11:29:06 1.63 @@ -1,13 +1,13 @@ /** @file Parser: program executing for different OS-es. - Copyright(c) 2000,2001-2003 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2000,2001-2004 ArtLebedev Group(http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) @todo setrlimit */ -static const char* IDENT_EXEC_C="$Date: 2003/11/20 15:35:31 $"; +static const char * const IDENT_EXEC_C="$Date: 2004/07/07 11:29:06 $"; #include "pa_config_includes.h" @@ -271,7 +271,9 @@ static pid_t execve_piped(const char* fi static int get_exit_status(int pid) { int status; - if(!waitpid(pid, &status, 0)) + pid_t cid; + while ((cid=waitpid(pid, &status, WUNTRACED)) == -1 && errno == EINTR); + if(!cid) return -1; return WIFEXITED(status) ? WEXITSTATUS(status) : -2; @@ -293,8 +295,8 @@ static void read_pipe(String& result, in #ifndef DOXYGEN struct Append_env_pair_info { #ifdef WIN32 - String& string; - Append_env_pair_info(String& astring): string(astring) {} + String::Body& body; + Append_env_pair_info(String::Body& abody): body(abody) {} #else char **env_ref; #endif @@ -304,20 +306,19 @@ struct Append_env_pair_info { static void append_env_pair(HashStringString::key_type key, HashStringString::value_type value, Append_env_pair_info *info) { #ifdef WIN32 - info->string << key << "=" << value; - info->string.append_know_length("\1", 1, String::L_AS_IS); // placeholder for of zero byte + info->body << key << "=" << value; + info->body.append_know_length("\1", 1); // placeholder for of zero byte #else String::Body body; - body << key << "=" << value; + body << key << "=" << value.cstr(); *(info->env_ref++)=body.cstrm(); #endif } -/// @todonow unix part to smart_ptr PA_exec_result pa_exec( bool -#ifdef NO_PA_EXEC +#if defined(NO_PA_EXEC) || defined(PA_SAFE_MODE) forced_allow #endif , @@ -341,10 +342,10 @@ PA_exec_result pa_exec( const char* cmd=buildCommand(file_spec.cstr(String::L_FILE_SPEC), argv); char* env_cstr=0; if(env) { - String string; - Append_env_pair_info info(string); + String::Body body; + Append_env_pair_info info(body); env->for_each(append_env_pair, &info); - env_cstr=info.string.cstrm(String::L_UNSPECIFIED); + env_cstr=info.body.cstrm(); for(char* replacer=env_cstr; *replacer; replacer++) if(*replacer=='\1') *replacer=0; @@ -361,8 +362,8 @@ PA_exec_result pa_exec( throw Exception(0, &file_spec, - "exec failed - %s (%ld). Consider adding shbang line (#!x:\\interpreter\\command line)", - error_size?szErrorDesc:"", (long)error); + "exec failed - %s (%u). Consider adding shbang line (#!x:\\interpreter\\command line)", + error_size?szErrorDesc:"", error); } else { const char* in_cstr=in.cstr(); DWORD written_size; @@ -443,10 +444,12 @@ from http://www.apache.org/websrc/cvsweb close(pipe_err); result.status=get_exit_status(pid); // negative may mean "-errno[execl()]" - } else + } else { + const char* str=strerror(errno); throw Exception(0, &file_spec, - "%s error: %s (%d)", pid<0?"fork":"pipe", strerror(errno), errno); + "%s error: %s (%d)", pid<0?"fork":"pipe", str?str:"", errno); + } #endif return result;