diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp index 3e55d1d1..1fae8509 100644 --- a/sortix/kernel.cpp +++ b/sortix/kernel.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -266,6 +267,9 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo) addr_t systemaddrspace = Memory::GetAddressSpace(); system->addrspace = systemaddrspace; + if ( !(system->program_image_path = String::Clone("")) ) + Panic("Unable to clone string for system process name"); + // We construct this thread manually for bootstrap reasons. We wish to // create a kernel thread that is the current thread and isn't put into the // scheduler's set of runnable threads, but rather run whenever there is diff --git a/sortix/process.cpp b/sortix/process.cpp index 2545ba35..48069629 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -112,6 +112,7 @@ namespace Sortix nextsibling = NULL; firstchild = NULL; zombiechild = NULL; + program_image_path = NULL; parentlock = KTHREAD_MUTEX_INITIALIZER; childlock = KTHREAD_MUTEX_INITIALIZER; zombiecond = KTHREAD_COND_INITIALIZER; @@ -129,6 +130,8 @@ namespace Sortix Process::~Process() { + if ( program_image_path ) + delete[] program_image_path; assert(!zombiechild); assert(!firstchild); assert(!addrspace); @@ -568,6 +571,9 @@ namespace Sortix clone->mtable = mtable; kthread_mutex_unlock(&ptrlock); + if ( !(clone->program_image_path = String::Clone(program_image_path)) ) + failure = false; + if ( pid == 1) assert(dtable->Get(1)); @@ -601,8 +607,15 @@ namespace Sortix (void) programname; assert(CurrentProcess() == this); + char* programname_clone = String::Clone(programname); + if ( !programname_clone ) + return -1; + addr_t entry = ELF::Construct(CurrentProcess(), program, programsize); - if ( !entry ) { return -1; } + if ( !entry ) { delete[] programname_clone; return -1; } + + delete[] program_image_path; + program_image_path = programname_clone; programname_clone = NULL; // TODO: This may be an ugly hack! // TODO: Move this to x86/process.cpp. diff --git a/sortix/process.h b/sortix/process.h index d0977bd3..a6027ea8 100644 --- a/sortix/process.h +++ b/sortix/process.h @@ -80,6 +80,7 @@ namespace Sortix static pid_t AllocatePID(); public: + char* program_image_path; addr_t addrspace; pid_t pid; uid_t uid;