1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/// @file WASM stub for processes.cc
/// The WASM evaluator cannot fork/exec. Any call to these functions
/// during evaluation is a programming error and throws immediately.

#include "lix/libutil/processes.hh"
#include "lix/libutil/error.hh"
#include "lix/libutil/result.hh"

#include <kj/async.h>

namespace nix {

// Pid

Pid::Pid() : pid(-1) {}

Pid::Pid(Pid && other) : pid(other.pid)
{
    other.pid = -1;
}

Pid & Pid::operator=(Pid && other)
{
    pid = other.pid;
    other.pid = -1;
    return *this;
}

Pid::~Pid() noexcept(false) {}

int Pid::kill()
{
    return -1;
}

int Pid::wait()
{
    return -1;
}

pid_t Pid::release()
{
    pid_t p = pid;
    pid = -1;
    return p;
}

// ProcessGroup

int ProcessGroup::kill()
{
    return -1;
}

// killUser

void killUser(uid_t) {}

// runProgram

kj::Promise<Result<std::string>> runProgram(Path, bool, Strings, std::optional<std::string>, bool)
try {
    throw Error("runProgram: not supported in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

kj::Promise<Result<std::pair<int, std::string>>> runProgram(RunOptions)
try {
    throw Error("runProgram: not supported in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// statusToString / statusOk

std::string statusToString(int status)
{
    return "unknown";
}
bool statusOk(int status)
{
    return status == 0;
}

// RunningProgram / RunningHelper — not reachable from the evaluator

std::tuple<Pid, std::unique_ptr<AsyncFdIoStream>> RunningProgram::release()
{
    throw Error("RunningProgram::release: not supported in WASM evaluator");
}

int RunningProgram::kill()
{
    return -1;
}
int RunningProgram::wait()
{
    return -1;
}
void RunningProgram::waitAndCheck()
{
    throw Error("RunningProgram::waitAndCheck: not supported in WASM evaluator");
}

int RunningHelper::killProcessGroup()
{
    return -1;
}

void RunningHelper::check()
{
    throw Error("RunningHelper::check: not supported in WASM evaluator");
}

void RunningHelper::waitAndCheck()
{
    throw Error("RunningHelper::waitAndCheck: not supported in WASM evaluator");
}

} // namespace nix