Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
processes.hh
Go to the documentation of this file.
1#pragma once
3
4#include "types.hh"
5#include "error.hh"
6#include "file-descriptor.hh"
7#include "logging.hh"
8#include "ansicolor.hh"
9
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <dirent.h>
13#include <unistd.h>
14#include <signal.h>
15
16#include <atomic>
17#include <functional>
18#include <map>
19#include <sstream>
20#include <optional>
21
22namespace nix {
23
24struct Sink;
25struct Source;
26
27class Pid
28{
29#ifndef _WIN32
30 pid_t pid = -1;
31 bool separatePG = false;
32 int killSignal = SIGKILL;
33#else
34 AutoCloseFD pid = INVALID_DESCRIPTOR;
35#endif
36public:
37 Pid();
38#ifndef _WIN32
39 Pid(pid_t pid);
40 void operator =(pid_t pid);
41 operator pid_t();
42#else
43 Pid(AutoCloseFD pid);
44 void operator =(AutoCloseFD pid);
45#endif
46 ~Pid();
47 int kill();
48 int wait();
49
50 // TODO: Implement for Windows
51#ifndef _WIN32
52 void setSeparatePG(bool separatePG);
53 void setKillSignal(int signal);
54 pid_t release();
55#endif
56};
57
58
59#ifndef _WIN32
64void killUser(uid_t uid);
65#endif
66
67
73{
74 std::string errorPrefix = "";
75 bool dieWithParent = true;
76 bool runExitHandlers = false;
77 bool allowVfork = false;
81 int cloneFlags = 0;
82};
83
84#ifndef _WIN32
85pid_t startProcess(std::function<void()> fun, const ProcessOptions & options = ProcessOptions());
86#endif
87
92std::string runProgram(Path program, bool lookupPath = false,
93 const Strings & args = Strings(),
94 const std::optional<std::string> & input = {}, bool isInteractive = false);
95
97{
98 Path program;
99 bool lookupPath = true;
100 Strings args;
101#ifndef _WIN32
102 std::optional<uid_t> uid;
103 std::optional<uid_t> gid;
104#endif
105 std::optional<Path> chdir;
106 std::optional<std::map<std::string, std::string>> environment;
107 std::optional<std::string> input;
108 Source * standardIn = nullptr;
109 Sink * standardOut = nullptr;
110 bool mergeStderrToStdout = false;
111 bool isInteractive = false;
112};
113
114std::pair<int, std::string> runProgram(RunOptions && options);
115
116void runProgram2(const RunOptions & options);
117
118
119class ExecError : public Error
120{
121public:
122 int status;
123
124 template<typename... Args>
125 ExecError(int status, const Args & ... args)
126 : Error(args...), status(status)
127 { }
128};
129
134std::string statusToString(int status);
135
136bool statusOk(int status);
137
138}
Some ANSI escape sequences.
Definition args.hh:28
Definition file-descriptor.hh:152
This file defines two main structs/classes used in nix error handling.
std::function< void(Sink &)> fun
Definition lexer.l:3485
std::vector< Expr * > args
Definition lexer.l:6126
unsigned int status
Definition lexer.l:663
std::string statusToString(int status)
std::string runProgram(Path program, bool lookupPath=false, const Strings &args=Strings(), const std::optional< std::string > &input={}, bool isInteractive=false)
void killUser(uid_t uid)
Definition processes.hh:73
int cloneFlags
Definition processes.hh:81
Definition processes.hh:97
Definition serialise.hh:20
Definition serialise.hh:68
std::string Path
Definition types.hh:22