fix: inherit process environment and untrack libc objects
This commit is contained in:
1 parent
0a91131cb0
commit
3ef98a9fd5
26 files changed
+254
-36
No files matched your search
@@ -294,6 +294,8 @@ namespace Sched {
|
||||
processTable[i].heapNext = 0;
|
||||
processTable[i].readdirCursor = 0;
|
||||
processTable[i].args[0] = '\0';
|
||||
processTable[i].environment[0] = '\0';
|
||||
processTable[i].environmentLength = 1;
|
||||
processTable[i].user[0] = '\0';
|
||||
processTable[i].cwd[0] = '\0';
|
||||
processTable[i].runningOnCpu = -1;
|
||||
@@ -337,7 +339,8 @@ namespace Sched {
|
||||
<< " process slots, " << (uint64_t)TimeSliceMs << " ms time slice)";
|
||||
}
|
||||
|
||||
int Spawn(const char* vfsPath, const char* args, bool startReady) {
|
||||
int Spawn(const char* vfsPath, const char* args, bool startReady,
|
||||
const char* environment, uint32_t environmentLength) {
|
||||
schedLock.Acquire();
|
||||
|
||||
int slot = -1;
|
||||
@@ -511,6 +514,9 @@ namespace Sched {
|
||||
|
||||
auto* currentCpu = Smp::GetCurrentCpuData();
|
||||
int parentSlot = currentCpu ? currentCpu->currentSlot : -1;
|
||||
int parentPrimarySlot = parentSlot;
|
||||
if (parentPrimarySlot >= 0 && processTable[parentPrimarySlot].primarySlot >= 0)
|
||||
parentPrimarySlot = processTable[parentPrimarySlot].primarySlot;
|
||||
|
||||
// Copy arguments string into process
|
||||
proc.args[0] = '\0';
|
||||
@@ -522,6 +528,23 @@ namespace Sched {
|
||||
proc.args[i] = '\0';
|
||||
}
|
||||
|
||||
// posix_spawn(envp) supplies an explicit snapshot. Plain spawn calls
|
||||
// omit it and inherit the environment stored on the parent process.
|
||||
if (environment != nullptr && environmentLength > 0 &&
|
||||
environmentLength <= Process::EnvironmentBytes) {
|
||||
for (uint32_t i = 0; i < environmentLength; i++)
|
||||
proc.environment[i] = environment[i];
|
||||
proc.environmentLength = environmentLength;
|
||||
} else if (parentPrimarySlot >= 0) {
|
||||
auto& parent = processTable[parentPrimarySlot];
|
||||
for (uint32_t i = 0; i < parent.environmentLength; i++)
|
||||
proc.environment[i] = parent.environment[i];
|
||||
proc.environmentLength = parent.environmentLength;
|
||||
} else {
|
||||
proc.environment[0] = '\0';
|
||||
proc.environmentLength = 1;
|
||||
}
|
||||
|
||||
// Inherit user string from parent, or default to "system" if no parent
|
||||
{
|
||||
if (parentSlot >= 0) {
|
||||
|
||||
Reference in new issue
Block a user