34constexpr static pid_t INVALID_PID = -1;
41 pid_t pid = unix::INVALID_PID;
42 bool separatePG =
false;
43 int killSignal = SIGKILL;
44 std::chrono::milliseconds killTimeout;
45 std::thread killThread;
51 Pid(
const Pid &) =
delete;
52 Pid(Pid && other)
noexcept;
53 Pid & operator=(
const Pid &) =
delete;
54 Pid & operator=(Pid && other)
noexcept;
57 void operator=(pid_t pid);
58 operator pid_t()
const;
78 explicit operator bool()
const noexcept;
80 int kill(
bool allowInterrupts =
true);
81 int wait(
bool allowInterrupts =
true);
85 void setSeparatePG(
bool separatePG);
86 void setKillSignal(
int signal);
87 void setKillTimeout(std::chrono::milliseconds duration);
91 friend void swap(Pid & lhs, Pid & rhs)
noexcept
95 swap(lhs.pid, rhs.pid);
96 swap(lhs.separatePG, rhs.separatePG);
97 swap(lhs.killSignal, rhs.killSignal);
99 swap(lhs.pid, rhs.pid);
118 std::string errorPrefix =
"";
119 bool dieWithParent =
true;
134const std::filesystem::path &
shProgram();
141 std::filesystem::path program,
142 bool lookupPath =
false,
144 bool isInteractive =
false);
151 std::filesystem::path program;
152 bool lookupPath =
true;
155 std::optional<std::string> argv0;
156 std::optional<uid_t> uid;
157 std::optional<uid_t> gid;
159 std::optional<std::filesystem::path> chdir;
160 std::optional<OsStringMap> environment;
179 Sink * standardOut =
nullptr;
180 bool mergeStderrToStdout =
false;
181 bool isInteractive =
false;
192 static inline const Descriptor stdInput =
reinterpret_cast<HANDLE
>(
static_cast<LONG_PTR
>(STD_INPUT_HANDLE));
193 static inline const Descriptor stdOut =
reinterpret_cast<HANDLE
>(
static_cast<LONG_PTR
>(STD_OUTPUT_HANDLE));
194 static inline const Descriptor stdError =
reinterpret_cast<HANDLE
>(
static_cast<LONG_PTR
>(STD_ERROR_HANDLE));
196 static constexpr Descriptor stdInput = STDIN_FILENO;
197 static constexpr Descriptor stdOut = STDOUT_FILENO;
198 static constexpr Descriptor stdError = STDERR_FILENO;
217Pid spawnProgram(
const SpawnOptions & options, std::span<const FdRedirection> fdr);
221class ExecError final :
public CloneableError<ExecError, Error>
223 void anchor()
override;
228 template<
typename...
Args>
229 ExecError(
int status,
Args &&... args)
230 : CloneableError(std::forward<Args>(args)...)
242bool statusOk(
int status);
Some ANSI escape sequences.
Definition file-descriptor.hh:265
Definition processes.hh:39
This file defines two main structs/classes used in nix error handling.
File descriptor operations for almost arbitrary file descriptors.
int Descriptor
Definition file-descriptor.hh:36
std::list< OsString > OsStrings
Definition os-string.hh:51
const std::filesystem::path & shProgram()
Definition processes.cc:11
std::string statusToString(int status)
Definition processes.cc:393
std::string runProgram(std::filesystem::path program, bool lookupPath=false, const OsStrings &args=OsStrings(), bool isInteractive=false)
Definition processes.cc:39
void killUser(uid_t uid)
Definition processes.cc:175
Definition processes.hh:185
Definition processes.hh:117
int cloneFlags
Definition processes.hh:123
Definition processes.hh:177
Definition serialise.hh:18
Definition serialise.hh:95
Definition processes.hh:150
bool dieWithParent
(Linux-only) whether to have the process die when its parent (us) exists.
Definition processes.hh:166
bool restoreMounts
(Linux-only) whether to restore the mount ns in the child. Only set this to false if the child proces...
Definition processes.hh:173