In ExecWait(), made the child process exit if it can't execve() the new

program.
Added the use of const (which compiles and is hopefully correct).
Added comments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8585 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John Criswell 2003-09-17 19:02:49 +00:00
parent f1d01fb6a4
commit e5b3e1559b
4 changed files with 48 additions and 28 deletions

View File

@ -41,5 +41,5 @@ int RunProgramWithTimeout(const std::string &ProgramPath, const char **Args,
/// Execute a program with the given arguments and environment and /// Execute a program with the given arguments and environment and
/// wait for it to terminate. /// wait for it to terminate.
/// ///
int ExecWait (char ** argv, char ** envp); int ExecWait (const char * const argv[], const char * const envp[]);
#endif #endif

View File

@ -41,5 +41,5 @@ int RunProgramWithTimeout(const std::string &ProgramPath, const char **Args,
/// Execute a program with the given arguments and environment and /// Execute a program with the given arguments and environment and
/// wait for it to terminate. /// wait for it to terminate.
/// ///
int ExecWait (char ** argv, char ** envp); int ExecWait (const char * const argv[], const char * const envp[]);
#endif #endif

View File

@ -192,8 +192,10 @@ int RunProgramWithTimeout(const std::string &ProgramPath, const char **Args,
// a generic library function. The caller or executed program should report // a generic library function. The caller or executed program should report
// errors in the way it sees fit. // errors in the way it sees fit.
// //
// This function does not use $PATH to find programs.
//
int int
ExecWait (char ** argv, char **envp) ExecWait (const char * const old_argv[], const char * const old_envp[])
{ {
// Child process ID // Child process ID
register int child; register int child;
@ -202,32 +204,40 @@ ExecWait (char ** argv, char **envp)
int status; int status;
// //
// Because UNIX is sometimes less than convenient, we need to use // Create local versions of the parameters that can be passed into execve()
// FindExecutable() to find the full pathname to the file to execute. // without creating const problems.
// //
// This is becausse execvp() doesn't use PATH, and we want to look for char ** const argv = (char ** const) old_argv;
// programs in the LLVM binary directory first anyway. char ** const envp = (char ** const) old_envp;
//
std::string Program = FindExecutable (argv[0], "");
if (Program.empty())
{
return 1;
}
// //
// Create a child process. // Create a child process.
// //
switch (child=fork()) switch (child=fork())
{ {
//
// An error occured: Return to the caller.
//
case -1: case -1:
return 1; return 1;
break; break;
//
// Child process: Execute the program.
//
case 0: case 0:
execve (Program.c_str(), argv, envp); execve (argv[0], argv, envp);
return 1;
//
// If the execve() failed, we should exit and let the parent pick up
// our non-zero exit status.
//
exit (1);
break; break;
//
// Parent process: Break out of the switch to do our processing.
//
default: default:
break; break;
} }

View File

@ -192,8 +192,10 @@ int RunProgramWithTimeout(const std::string &ProgramPath, const char **Args,
// a generic library function. The caller or executed program should report // a generic library function. The caller or executed program should report
// errors in the way it sees fit. // errors in the way it sees fit.
// //
// This function does not use $PATH to find programs.
//
int int
ExecWait (char ** argv, char **envp) ExecWait (const char * const old_argv[], const char * const old_envp[])
{ {
// Child process ID // Child process ID
register int child; register int child;
@ -202,32 +204,40 @@ ExecWait (char ** argv, char **envp)
int status; int status;
// //
// Because UNIX is sometimes less than convenient, we need to use // Create local versions of the parameters that can be passed into execve()
// FindExecutable() to find the full pathname to the file to execute. // without creating const problems.
// //
// This is becausse execvp() doesn't use PATH, and we want to look for char ** const argv = (char ** const) old_argv;
// programs in the LLVM binary directory first anyway. char ** const envp = (char ** const) old_envp;
//
std::string Program = FindExecutable (argv[0], "");
if (Program.empty())
{
return 1;
}
// //
// Create a child process. // Create a child process.
// //
switch (child=fork()) switch (child=fork())
{ {
//
// An error occured: Return to the caller.
//
case -1: case -1:
return 1; return 1;
break; break;
//
// Child process: Execute the program.
//
case 0: case 0:
execve (Program.c_str(), argv, envp); execve (argv[0], argv, envp);
return 1;
//
// If the execve() failed, we should exit and let the parent pick up
// our non-zero exit status.
//
exit (1);
break; break;
//
// Parent process: Break out of the switch to do our processing.
//
default: default:
break; break;
} }