forked from lix-project/lix
Drop parentheses from thunks
This commit is contained in:
parent
1885d579db
commit
c924147c9d
|
@ -96,7 +96,7 @@ void drainFD(int fd, Sink & sink, bool block)
|
||||||
throw SysError("making file descriptor non-blocking");
|
throw SysError("making file descriptor non-blocking");
|
||||||
}
|
}
|
||||||
|
|
||||||
Finally finally([&]() {
|
Finally finally([&] {
|
||||||
if (!block) {
|
if (!block) {
|
||||||
if (fcntl(fd, F_SETFL, saved) == -1)
|
if (fcntl(fd, F_SETFL, saved) == -1)
|
||||||
throw SysError("making file descriptor blocking");
|
throw SysError("making file descriptor blocking");
|
||||||
|
|
|
@ -131,7 +131,7 @@ void killUser(uid_t uid)
|
||||||
users to which the current process can send signals. So we
|
users to which the current process can send signals. So we
|
||||||
fork a process, switch to uid, and send a mass kill. */
|
fork a process, switch to uid, and send a mass kill. */
|
||||||
|
|
||||||
Pid pid = startProcess([&]() {
|
Pid pid = startProcess([&] {
|
||||||
|
|
||||||
if (setuid(uid) == -1)
|
if (setuid(uid) == -1)
|
||||||
throw SysError("setting uid");
|
throw SysError("setting uid");
|
||||||
|
@ -197,7 +197,7 @@ static int childEntry(void * arg)
|
||||||
|
|
||||||
pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
|
pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
|
||||||
{
|
{
|
||||||
std::function<void()> wrapper = [&]() {
|
ChildWrapperFunction wrapper = [&] {
|
||||||
if (!options.allowVfork)
|
if (!options.allowVfork)
|
||||||
logger = makeSimpleLogger();
|
logger = makeSimpleLogger();
|
||||||
try {
|
try {
|
||||||
|
@ -229,7 +229,7 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
|
||||||
PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||||
if (stack == MAP_FAILED) throw SysError("allocating stack");
|
if (stack == MAP_FAILED) throw SysError("allocating stack");
|
||||||
|
|
||||||
Finally freeStack([&]() { munmap(stack, stackSize); });
|
Finally freeStack([&] { munmap(stack, stackSize); });
|
||||||
|
|
||||||
pid = clone(childEntry, stack + stackSize, options.cloneFlags | SIGCHLD, &wrapper);
|
pid = clone(childEntry, stack + stackSize, options.cloneFlags | SIGCHLD, &wrapper);
|
||||||
#else
|
#else
|
||||||
|
@ -308,7 +308,7 @@ void runProgram2(const RunOptions & options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fork. */
|
/* Fork. */
|
||||||
Pid pid = startProcess([&]() {
|
Pid pid = startProcess([&] {
|
||||||
if (options.environment)
|
if (options.environment)
|
||||||
replaceEnv(*options.environment);
|
replaceEnv(*options.environment);
|
||||||
if (options.standardOut && dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
if (options.standardOut && dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
||||||
|
@ -350,7 +350,7 @@ void runProgram2(const RunOptions & options)
|
||||||
|
|
||||||
std::promise<void> promise;
|
std::promise<void> promise;
|
||||||
|
|
||||||
Finally doJoin([&]() {
|
Finally doJoin([&] {
|
||||||
if (writerThread.joinable())
|
if (writerThread.joinable())
|
||||||
writerThread.join();
|
writerThread.join();
|
||||||
});
|
});
|
||||||
|
@ -358,7 +358,7 @@ void runProgram2(const RunOptions & options)
|
||||||
|
|
||||||
if (source) {
|
if (source) {
|
||||||
in.readSide.close();
|
in.readSide.close();
|
||||||
writerThread = std::thread([&]() {
|
writerThread = std::thread([&] {
|
||||||
try {
|
try {
|
||||||
std::vector<char> buf(8 * 1024);
|
std::vector<char> buf(8 * 1024);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ void bind(int fd, const std::string & path)
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
if (path.size() + 1 >= sizeof(addr.sun_path)) {
|
if (path.size() + 1 >= sizeof(addr.sun_path)) {
|
||||||
Pid pid = startProcess([&]() {
|
Pid pid = startProcess([&] {
|
||||||
Path dir = dirOf(path);
|
Path dir = dirOf(path);
|
||||||
if (chdir(dir.c_str()) == -1)
|
if (chdir(dir.c_str()) == -1)
|
||||||
throw SysError("chdir to '%s' failed", dir);
|
throw SysError("chdir to '%s' failed", dir);
|
||||||
|
@ -78,7 +78,7 @@ void connect(int fd, const std::string & path)
|
||||||
if (path.size() + 1 >= sizeof(addr.sun_path)) {
|
if (path.size() + 1 >= sizeof(addr.sun_path)) {
|
||||||
Pipe pipe;
|
Pipe pipe;
|
||||||
pipe.create();
|
pipe.create();
|
||||||
Pid pid = startProcess([&]() {
|
Pid pid = startProcess([&] {
|
||||||
try {
|
try {
|
||||||
pipe.readSide.close();
|
pipe.readSide.close();
|
||||||
Path dir = dirOf(path);
|
Path dir = dirOf(path);
|
||||||
|
|
|
@ -183,7 +183,7 @@ std::string base64Encode(std::string_view s)
|
||||||
std::string base64Decode(std::string_view s)
|
std::string base64Decode(std::string_view s)
|
||||||
{
|
{
|
||||||
constexpr char npos = -1;
|
constexpr char npos = -1;
|
||||||
constexpr std::array<char, 256> base64DecodeChars = [&]() {
|
constexpr std::array<char, 256> base64DecodeChars = [&] {
|
||||||
std::array<char, 256> result{};
|
std::array<char, 256> result{};
|
||||||
for (auto& c : result)
|
for (auto& c : result)
|
||||||
c = npos;
|
c = npos;
|
||||||
|
|
Loading…
Reference in a new issue