Update ExecUtils to support artd use cases.

- Use pidfd_open/poll instaed of sigprocmask/sigtimedwait to implement
  executing a command with a timeout because sigprocmask/sigtimedwait
  does not support multithreaded program, while artd is multithreaded.
  The same approach is used in installd in
  https://r.android.com/1993670.
- Add "const" to the `std::vector<std::string>& arg_vector` parameter.
- Use "int" instead of "time_t" for the "timeout_sec" parameter because
  "time_t" represents the time since epoch rather than a duration.
- Set an error message with the signal number when the subprocess is
  terminated by a signal.
- Crash the subprocess instead of exiting it with an exit code when
  execv fails.

The behavior does not change. ExecUtilsTest is still passing.

Bug: 229268202
Test: m test-art-host-gtest-art_runtime_tests
Test: atest ArtGtestsTargetChroot:ExecUtilsTest
Ignore-AOSP-First: Will cherry-pick later.
Change-Id: I375034162cded6fdf09ee4d4cd783a0d3987af49
diff --git a/runtime/exec_utils.h b/runtime/exec_utils.h
index 7ce0a9c..ff90ebd 100644
--- a/runtime/exec_utils.h
+++ b/runtime/exec_utils.h
@@ -29,13 +29,13 @@
 // of the runtime (Runtime::Current()) was started.  If no instance of the runtime was started, it
 // will use the current environment settings.
 
-bool Exec(std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg);
-int ExecAndReturnCode(std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg);
+bool Exec(const std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg);
+int ExecAndReturnCode(const std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg);
 
 // Execute the command specified in `argv_vector` in a subprocess with a timeout.
 // Returns the process exit code on success, -1 otherwise.
-int ExecAndReturnCode(std::vector<std::string>& arg_vector,
-                      time_t timeout_secs,
+int ExecAndReturnCode(const std::vector<std::string>& arg_vector,
+                      int timeout_sec,
                       /*out*/ bool* timed_out,
                       /*out*/ std::string* error_msg);
 
@@ -44,20 +44,21 @@
  public:
   virtual ~ExecUtils() = default;
 
-  virtual bool Exec(std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg) const {
+  virtual bool Exec(const std::vector<std::string>& arg_vector,
+                    /*out*/ std::string* error_msg) const {
     return art::Exec(arg_vector, error_msg);
   }
 
-  virtual int ExecAndReturnCode(std::vector<std::string>& arg_vector,
+  virtual int ExecAndReturnCode(const std::vector<std::string>& arg_vector,
                                 /*out*/ std::string* error_msg) const {
     return art::ExecAndReturnCode(arg_vector, error_msg);
   }
 
-  virtual int ExecAndReturnCode(std::vector<std::string>& arg_vector,
-                                time_t timeout_secs,
+  virtual int ExecAndReturnCode(const std::vector<std::string>& arg_vector,
+                                int timeout_sec,
                                 /*out*/ bool* timed_out,
                                 /*out*/ std::string* error_msg) const {
-    return art::ExecAndReturnCode(arg_vector, timeout_secs, timed_out, error_msg);
+    return art::ExecAndReturnCode(arg_vector, timeout_sec, timed_out, error_msg);
   }
 };