Commit dc91036e authored by Léo Grange's avatar Léo Grange

use pointer to parent process struct instead of ppid

parent b0e569a7
......@@ -43,6 +43,7 @@ static int _process_number = 0;
// virtual task for idle
struct process _proc_idle_task = {
.pid = 0,
.parent = NULL,
.dir_list = NULL,
.state = PROCESS_STATE_RUNNING,
.acnt = NULL,
......@@ -105,7 +106,7 @@ struct process *process_alloc() {
proc->pid = process_get_pid();
proc->pgid = 1; // group of init?
proc->ppid = 0;
proc->parent = NULL;
proc->state = PROCESS_STATE_CREATE;
proc->ctty = NULL;
......@@ -262,7 +263,7 @@ pid_t sys_fork() {
newproc = process_alloc();
newproc->pgid = cur->pgid;
newproc->ppid = cur->pid;
newproc->parent = cur;
for(i=0; i<PROCESS_MAX_FILE; i++) {
// for each valid file descriptor, increment usage counter
newproc->files[i] = cur->files[i];
......@@ -366,7 +367,7 @@ pid_t sys_getpid() {
}
pid_t sys_getppid() {
return process_get_current()->ppid;
return process_get_ppid();
}
......@@ -798,19 +799,17 @@ pid_t sys_getpgid(pid_t pid) {
}
int process_is_descendant(struct process *proc, pid_t other) {
struct process *cur;
int process_is_descendant(struct process *proc, pid_t otherpid) {
struct process *other = process_from_pid(otherpid);
for(cur=proc; cur!=NULL && cur->ppid != other && cur->pid != 1;
cur = process_from_pid(cur->ppid));
if(cur != NULL) {
if(cur->ppid == other)
if(other != NULL) {
struct process *cur;
for(cur=proc; cur != NULL && cur->parent != other; cur = cur->parent);
if(cur != NULL && cur->parent->pid == otherpid)
return 1;
}
else {
printk(LOG_DEBUG, "proc: bad process hierarchy\n");
}
return 0;
}
......@@ -827,7 +826,7 @@ static void copy_proc_user(struct process *proc, void *userbuf) {
uinfo->uticks = proc->uticks;
uinfo->pid = proc->pid;
uinfo->ppid = proc->ppid;
uinfo->ppid = process_get_ppid(proc);
uinfo->state = proc->state;
uinfo->exit_status = proc->exit_status;
......
......@@ -59,6 +59,9 @@ struct process {
pid_t pid;
pid_t pgid;
// parent, or NULL (no other process than swaper and init should use NULL)
struct process *parent;
// virtual memory managing data :
struct addr_space addr_space;
struct page_dir *dir_list;
......@@ -78,7 +81,6 @@ struct process {
sigset_t sig_pending;
struct sigaction sig_array[SIGNAL_INDEX_MAX];
pid_t ppid;
int state;
int exit_status; // only valid when state is PROCESS_STATE_ZOMBIE
......@@ -181,6 +183,14 @@ static inline struct process *process_get_current() {
}
/**
* Return the pid of the parent process, or 0 if not available.
*/
static inline pid_t process_get_ppid() {
return _proc_current->parent == NULL ? 0 : _proc_current->parent->pid;
}
/**
* Run given process, switching context from current kernel context to
* process context_info.
......
......@@ -212,7 +212,7 @@ pid_t sys_wait(int *status) {
// do not return before a child is in Zombie state
int ret = 0;
pid_t ppid = process_get_current()->pid;
struct process *proc = process_get_current();
while(ret == 0) {
int i;
......@@ -222,7 +222,7 @@ pid_t sys_wait(int *status) {
for(i=0; i<SCHED_MAX_TASKS; i++) {
//printk(LOG_DEBUG, "task %d", i);
//printk(LOG_DEBUG, "->%p\n", _tasks[i]);
if(_tasks[i] != NULL && _tasks[i]->ppid == ppid) {
if(_tasks[i] != NULL && _tasks[i]->parent == proc) {
if(_tasks[i]->state == PROCESS_STATE_ZOMBIE) {
ret = _tasks[i]->pid;
if(status != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment