github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/third_party/patches/goma/goma_subprocess.patch (about)

     1  --- client/client/subprocess.cc	2023-02-01 14:40:35
     2  +++ client/client/subprocess.cc.new	2023-02-03 15:44:27
     3  @@ -18,6 +18,7 @@
     4   #include <deque>
     5   #include <iostream>
     6   #include <memory>
     7  +#include <mutex>
     8   
     9   #include "absl/strings/str_join.h"
    10   #include "absl/strings/string_view.h"
    11  @@ -40,6 +41,8 @@
    12   
    13   namespace {
    14   
    15  +std::mutex popen_mutex;
    16  +
    17   #ifdef _WIN32
    18   std::string GetPathExt(const std::vector<std::string>& envs) {
    19     return GetEnvFromEnvIter(envs.begin(), envs.end(), "PATHEXT");
    20  @@ -179,7 +182,11 @@
    21     if (option == MERGE_STDOUT_STDERR)
    22       commandline += " 2>&1";
    23   
    24  -  FILE* p = popen(commandline.c_str(), "r");
    25  +  FILE* p = nullptr;
    26  +  {
    27  +    std::lock_guard<std::mutex> guard(popen_mutex);
    28  +    p = popen(commandline.c_str(), "r");
    29  +  }
    30     CHECK(p) << "popen for " << prog << " (" << commandline << ") failed";
    31   
    32     std::ostringstream strbuf;
    33  @@ -196,7 +203,11 @@
    34       strbuf.write(buf, len);
    35     }
    36   
    37  -  int exit_status = pclose(p);
    38  +  int exit_status;
    39  +  {
    40  +    std::lock_guard<std::mutex> guard(popen_mutex);
    41  +    exit_status = pclose(p);
    42  +  }
    43     if (status) {
    44       *status = exit_status;
    45     } else {