Gracefully handle the lack of subreaper support in Linux.

PR_SET_CHILD_SUBREAPER was introduced in Linux 3.4, but CentOS 6.x and RHEL 7.6 apparently do not support this yet. By detecting this at runtime, we can gracefully fallback to our previous, not as robust way of waiting for subprocesses to exit.

Fixes #11637.

RELNOTES: None.
PiperOrigin-RevId: 319377918
diff --git a/src/main/tools/process-wrapper-legacy.cc b/src/main/tools/process-wrapper-legacy.cc
index 60a01e6..92cf6ef 100644
--- a/src/main/tools/process-wrapper-legacy.cc
+++ b/src/main/tools/process-wrapper-legacy.cc
@@ -34,6 +34,11 @@
 #include "src/main/tools/process-wrapper-options.h"
 #include "src/main/tools/process-wrapper.h"
 
+#if defined(__linux__) && !defined(PR_SET_CHILD_SUBREAPER)
+// https://github.com/torvalds/linux/blob/v5.7/tools/include/uapi/linux/prctl.h#L158
+#define PR_SET_CHILD_SUBREAPER 36
+#endif
+
 pid_t LegacyProcessWrapper::child_pid = 0;
 volatile sig_atomic_t LegacyProcessWrapper::last_signal = 0;
 
diff --git a/src/main/tools/process-wrapper-options.cc b/src/main/tools/process-wrapper-options.cc
index 0c0e97e..8f6a782 100644
--- a/src/main/tools/process-wrapper-options.cc
+++ b/src/main/tools/process-wrapper-options.cc
@@ -18,6 +18,9 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#if defined(__linux__)
+#include <sys/prctl.h>
+#endif
 #include <unistd.h>
 
 #include <cstring>
@@ -27,6 +30,11 @@
 
 #include "src/main/tools/logging.h"
 
+#if defined(__linux__) && !defined(PR_GET_CHILD_SUBREAPER)
+// https://github.com/torvalds/linux/blob/v5.7/tools/include/uapi/linux/prctl.h#L159
+#define PR_GET_CHILD_SUBREAPER 37
+#endif
+
 struct Options opt;
 
 // Print out a usage error. argc and argv are the argument counter and vector,
@@ -117,6 +125,15 @@
         opt.debug = true;
         break;
       case 'W':
+#if defined(__linux__)
+        unsigned long result;  // NOLINT(runtime/int) - interface requires long
+        if (prctl(PR_GET_CHILD_SUBREAPER, &result, 0, 0, 0) == EINVAL) {
+          fprintf(stderr,
+                  "warning: The \"wait for subprocesses\" feature requires "
+                  "Linux kernel version 3.4 or later.\n");
+          break;
+        }
+#endif
         opt.wait_fix = true;
         break;
       case '?':