Keep track of program image path.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-19 23:17:36 +01:00
parent e97990e144
commit f2556c3551
3 changed files with 19 additions and 1 deletions

View File

@ -46,6 +46,7 @@
#include <sortix/kernel/time.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/kernel/fcache.h>
#include <sortix/kernel/string.h>
#include <sortix/fcntl.h>
#include <sortix/stat.h>
@ -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("<kernel process>")) )
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

View File

@ -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.

View File

@ -80,6 +80,7 @@ namespace Sortix
static pid_t AllocatePID();
public:
char* program_image_path;
addr_t addrspace;
pid_t pid;
uid_t uid;