LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
subprocess.h File Reference

Running an external command and capturing its output, with a deadline. More...

#include <cerrno>
#include <csignal>
#include <cstddef>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <fcntl.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for subprocess.h:

Go to the source code of this file.

Classes

struct  line::util::ProcResult
 Outcome of a captured command. More...

Namespaces

namespace  line
namespace  line::util

Functions

ProcResult line::util::capture (const std::vector< std::string > &argv, int timeoutSeconds, bool mergeStderr=false)
 Runs a command, capturing stdout and discarding stderr.
int line::util::run_inherit (const std::vector< std::string > &argv)
 Runs a command with the parent's stdout and stderr, e.g.
std::string line::util::trim (const std::string &s)
 Trims ASCII whitespace from both ends, as Java's String.trim() does.

Detailed Description

Running an external command and capturing its output, with a deadline.

The port needs this for the Docker orchestration behind the symbolic backend, where the JAR uses ProcessBuilder. popen() is not enough: it offers no timeout and runs the command through a shell, so an image tag would be word-split and glob-expanded. This forks and execs an argv vector directly, so no shell ever sees the arguments, and enforces the deadline by polling the pipe and killing the child when it expires.

A TIMED-OUT CHILD IS KILLED AND REAPED, never merely abandoned: an orphaned docker run would keep a container alive that nobody holds the name of.

Definition in file subprocess.h.