Merge pull request #8868 from markdroth/fixit_qps

Improve subproccess cleanup in json_run_localhost.
pull/8898/head
Mark D. Roth 8 years ago committed by GitHub
commit 0d8c9cf1d5
  1. 4
      src/core/lib/support/subprocess_posix.c
  2. 22
      test/cpp/qps/json_run_localhost.cc

@ -40,6 +40,7 @@
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -52,7 +53,7 @@
struct gpr_subprocess {
int pid;
int joined;
bool joined;
};
const char *gpr_subprocess_binary_extension() { return ""; }
@ -100,6 +101,7 @@ retry:
gpr_log(GPR_ERROR, "waitpid failed: %s", strerror(errno));
return -1;
}
p->joined = true;
return status;
}

@ -50,6 +50,18 @@ std::string as_string(const T& val) {
return out.str();
}
static void LogStatus(int status, const char* label) {
if (WIFEXITED(status)) {
gpr_log(GPR_INFO, "%s: subprocess exited with status %d", label,
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
gpr_log(GPR_INFO, "%s: subprocess terminated with signal %d", label,
WTERMSIG(status));
} else {
gpr_log(GPR_INFO, "%s: unknown subprocess status: %d", label, status);
}
}
int main(int argc, char** argv) {
typedef std::unique_ptr<SubProcess> SubProcessPtr;
std::vector<SubProcessPtr> jobs;
@ -75,12 +87,18 @@ int main(int argc, char** argv) {
for (int i = 1; i < argc; i++) {
args.push_back(argv[i]);
}
GPR_ASSERT(SubProcess(args).Join() == 0);
int status = SubProcess(args).Join();
if (status != 0) {
LogStatus(status, "driver");
}
for (auto it = jobs.begin(); it != jobs.end(); ++it) {
(*it)->Interrupt();
}
for (auto it = jobs.begin(); it != jobs.end(); ++it) {
(*it)->Join();
status = (*it)->Join();
if (status != 0) {
LogStatus(status, "worker");
}
}
}

Loading…
Cancel
Save