fix: inherit redirected console in SYS_SPAWN_CAPS

This commit is contained in:
2026-08-29 18:47:42 +02:00
parent f0bea7736d
commit f69f08acbb
2 changed files with 51 additions and 30 deletions
+1 -1
View File
@@ -12,4 +12,4 @@
#pragma once #pragma once
#define MONTAUK_BUILD_NUMBER 177 #define MONTAUK_BUILD_NUMBER 178
+36 -15
View File
@@ -43,19 +43,14 @@ namespace montauk::abi {
return Sched::LookupExitCode(pid); return Sched::LookupExitCode(pid);
} }
static int Sys_Spawn(const char* path, const char* args, // Hand a freshly spawned child the parent's redirected console. Both spawn
const char* environment = nullptr, uint32_t environmentLength = 0) { // syscalls need this: a console tool launched from a GUI terminal must read
char resolved[256]; // its keys from the terminal's mailbox and write its output back up the
if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1; // stream, whether or not it also carries a capability grant. The child is
// created suspended (startReady == false) so its first instruction cannot
auto* parent = Sched::GetCurrentProcessPtr(); // run before the channels exist, and is started here once they do.
int parentSlot = Ipc::CurrentSlot(); // Returns childPid, or kills the child and returns -1 on failure.
bool inheritRedirection = parent && parent->redirected; static int InheritRedirection(int childPid, Sched::Process* parent, int parentSlot) {
int childPid = Sched::Spawn(resolved, args, !inheritRedirection,
environment, environmentLength);
if (childPid < 0) return childPid;
if (inheritRedirection) {
auto* child = Sched::GetProcessByPid(childPid); auto* child = Sched::GetProcessByPid(childPid);
int childSlot = Ipc::SlotForPid(childPid); int childSlot = Ipc::SlotForPid(childPid);
if (child == nullptr || childSlot < 0 || parentSlot < 0) { if (child == nullptr || childSlot < 0 || parentSlot < 0) {
@@ -81,8 +76,25 @@ namespace montauk::abi {
Sched::KillProcess(childPid); Sched::KillProcess(childPid);
return -1; return -1;
} }
return childPid;
} }
static int Sys_Spawn(const char* path, const char* args,
const char* environment = nullptr, uint32_t environmentLength = 0) {
char resolved[256];
if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1;
auto* parent = Sched::GetCurrentProcessPtr();
int parentSlot = Ipc::CurrentSlot();
bool inheritRedirection = parent && parent->redirected;
int childPid = Sched::Spawn(resolved, args, !inheritRedirection,
environment, environmentLength);
if (childPid < 0) return childPid;
if (inheritRedirection)
return InheritRedirection(childPid, parent, parentSlot);
return childPid; return childPid;
} }
@@ -115,8 +127,17 @@ namespace montauk::abi {
char resolved[256]; char resolved[256];
if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1; if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1;
return Sched::Spawn(resolved, args, true, nullptr, 0, &copy,
userOverride); int parentSlot = Ipc::CurrentSlot();
bool inheritRedirection = parent->redirected;
int childPid = Sched::Spawn(resolved, args, !inheritRedirection,
nullptr, 0, &copy, userOverride);
if (childPid < 0) return childPid;
if (inheritRedirection)
return InheritRedirection(childPid, parent, parentSlot);
return childPid;
} }
// Copy the absolute path this process was spawned from (argv[0]). // Copy the absolute path this process was spawned from (argv[0]).