Move logic to wait for a process in a noninterruptible manner to Subprocess.

The Subprocess class already had this functionality in it, but it was hidden
behind the destroyAndWait() method, which did two things. This change pulls
out the actual wait into a separate method and removes some duplication of
this functionality.

RELNOTES: None.
PiperOrigin-RevId: 275966801
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Subprocess.java b/src/main/java/com/google/devtools/build/lib/shell/Subprocess.java
index 8cb0988..d7ce117 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/Subprocess.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/Subprocess.java
@@ -72,13 +72,8 @@
   @Override
   void close();
 
-  /**
-   * Kills the subprocess and awaits for its termination so that we know it has released any
-   * resources it may have held.
-   */
-  default void destroyAndWait() {
-    destroy();
-
+  /** Waits for the process to finish in a non-interruptible manner. */
+  default void waitForUninterruptibly() {
     boolean wasInterrupted = false;
     try {
       while (true) {
@@ -96,4 +91,13 @@
       }
     }
   }
+
+  /**
+   * Kills the subprocess and awaits for its termination so that we know it has released any
+   * resources it may have held.
+   */
+  default void destroyAndWait() {
+    destroy();
+    waitForUninterruptibly();
+  }
 }