feat: add inherited sessions and desktop session teardown
This commit is contained in:
1 parent
f8ded3c30e
commit
0f81276efc
17 files changed
+165
No files matched your search
@@ -297,6 +297,7 @@ namespace Sched {
|
||||
processTable[i].environment[0] = '\0';
|
||||
processTable[i].environmentLength = 1;
|
||||
processTable[i].user[0] = '\0';
|
||||
processTable[i].sessionId = -1;
|
||||
processTable[i].cwd[0] = '\0';
|
||||
processTable[i].runningOnCpu = -1;
|
||||
processTable[i].killPending = false;
|
||||
@@ -560,6 +561,13 @@ namespace Sched {
|
||||
}
|
||||
}
|
||||
|
||||
// Process sessions are explicit groups used by supervisors such as
|
||||
// login.elf. A session leader opts in with CreateSession(); all of its
|
||||
// subsequently spawned descendants inherit the same stable ID.
|
||||
proc.sessionId = (parentPrimarySlot >= 0)
|
||||
? processTable[parentPrimarySlot].sessionId
|
||||
: -1;
|
||||
|
||||
{
|
||||
if (parentSlot >= 0 && processTable[parentSlot].cwd[0]) {
|
||||
int i = 0;
|
||||
@@ -1747,6 +1755,68 @@ namespace Sched {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreateSession() {
|
||||
schedLock.Acquire();
|
||||
Process* proc = GetCurrentProcessPtr();
|
||||
if (proc == nullptr) {
|
||||
schedLock.Release();
|
||||
return -1;
|
||||
}
|
||||
proc->sessionId = proc->pid;
|
||||
int sessionId = proc->sessionId;
|
||||
schedLock.Release();
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
int KillSession(int sessionId) {
|
||||
if (sessionId < 0) return -1;
|
||||
|
||||
int callerPid = GetCurrentPid();
|
||||
int killed = 0;
|
||||
|
||||
// Mark the complete group in one scheduler-lock transaction. New
|
||||
// children inherit sessionId, so a supervisor can repeat this call
|
||||
// until zero is returned to close the small spawn/exit race cleanly.
|
||||
schedLock.Acquire();
|
||||
for (int i = 0; i < MaxProcesses; i++) {
|
||||
Process& primary = processTable[i];
|
||||
if (primary.primarySlot != i || primary.pid == callerPid ||
|
||||
primary.sessionId != sessionId) {
|
||||
continue;
|
||||
}
|
||||
auto state = primary.state;
|
||||
if (state != ProcessState::Ready && state != ProcessState::Running &&
|
||||
state != ProcessState::Blocked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
primary.exitCode = 256 + 9; /* killed (SIGKILL) */
|
||||
primary.killPending = true;
|
||||
if (primary.state == ProcessState::Blocked) {
|
||||
primary.state = ProcessState::Ready;
|
||||
readyCount++;
|
||||
primary.waitingForPid = -1;
|
||||
primary.waitingOnObject = nullptr;
|
||||
primary.sleepUntilTick = 0;
|
||||
}
|
||||
|
||||
for (int j = 0; j < MaxProcesses; j++) {
|
||||
if (j == i || processTable[j].primarySlot != i) continue;
|
||||
if (processTable[j].state == ProcessState::Running) {
|
||||
processTable[j].killPending = true;
|
||||
}
|
||||
}
|
||||
killed++;
|
||||
}
|
||||
schedLock.Release();
|
||||
|
||||
if (killed > 0) {
|
||||
KickOneIdleCpu(Smp::GetCurrentCpuData()
|
||||
? Smp::GetCurrentCpuData()->cpuIndex : -1);
|
||||
}
|
||||
return killed;
|
||||
}
|
||||
|
||||
int LookupExitCode(int pid) {
|
||||
schedLock.Acquire();
|
||||
int code = 0;
|
||||
|
||||
Reference in new issue
Block a user