Making fork process more descriptive in the case of failure

This commit is contained in:
Ian Roddis
2022-01-10 13:12:19 -04:00
parent 7312776e39
commit 04e95cfcf3

View File

@@ -108,7 +108,7 @@ std::future<daggy::AttemptRecord> ForkingTaskExecutor::execute(
daggy::AttemptRecord ForkingTaskExecutor::runTask(const Task &task, daggy::AttemptRecord ForkingTaskExecutor::runTask(const Task &task,
std::atomic<bool> &running) std::atomic<bool> &running)
{ {
AttemptRecord rec; AttemptRecord rec{.rc = -1};
rec.startTime = Clock::now(); rec.startTime = Clock::now();
@@ -148,19 +148,20 @@ daggy::AttemptRecord ForkingTaskExecutor::runTask(const Task &task,
int stdoutPipe[2]; int stdoutPipe[2];
int pipeRC = pipe2(stdoutPipe, O_DIRECT); int pipeRC = pipe2(stdoutPipe, O_DIRECT);
if (pipeRC != 0) { if (pipeRC != 0) {
std::cerr << "Unable to create pipe for stdout: " << pipeRC << std::endl; rec.executorLog = "Unable to create pipe for stdout, check limits";
throw std::runtime_error("Unable to create pipe for stdout"); return rec;
} }
int stderrPipe[2]; int stderrPipe[2];
pipeRC = pipe2(stderrPipe, O_DIRECT); pipeRC = pipe2(stderrPipe, O_DIRECT);
if (pipeRC != 0) { if (pipeRC != 0) {
std::cerr << "Unable to create pipe for stderr" << std::endl; rec.executorLog = "Unable to create pipe for stderr, check limits";
throw std::runtime_error("Unable to create pipe for stderr"); return rec;
} }
pid_t child = fork(); pid_t child = fork();
if (child < 0) { if (child < 0) {
throw std::runtime_error("Unable to fork child"); rec.executorLog = "Unable to fork.";
return rec;
} }
else if (child == 0) { // child else if (child == 0) { // child
while ((dup2(stdoutPipe[1], STDOUT_FILENO) == -1) && (errno == EINTR)) { while ((dup2(stdoutPipe[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {