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