In ExecWait(), made the child process exit if it can't execve() the new
authorJohn Criswell <criswell@uiuc.edu>
Wed, 17 Sep 2003 19:02:49 +0000 (19:02 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Wed, 17 Sep 2003 19:02:49 +0000 (19:02 +0000)
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

include/Support/SystemUtils.h
include/llvm/Support/SystemUtils.h
lib/Support/SystemUtils.cpp
support/lib/Support/SystemUtils.cpp

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