From: Matthias Kruk Date: Wed, 6 Nov 2019 06:51:42 +0000 (+0900) Subject: Implement process ownership and inheritance X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=e207c7cfe2f7ce9d798d4def191c3a3a426f4542;p=corax Implement process ownership and inheritance --- diff --git a/kernel/core/process.c b/kernel/core/process.c index 58890c3..710fc75 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -22,6 +22,8 @@ struct process { u32_t p_privl; pid_t p_id; pid_t p_pid; + uid_t p_uid; + gid_t p_gid; struct { struct cxmsg *msg; @@ -161,11 +163,9 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) { int ret_val; process_t *proc; - pid_t ppid; ret_val = -ENOMEM; proc = NULL; - ppid = 1; /* was a specific pid requested? */ if(pid != PID_ANY) { @@ -190,12 +190,12 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) /* inherit the ppl from the current task, in the case of fork and vfork */ ctask = task_get_current(); ppl = ctask->t_privl; - ppid = ctask->t_pid; } proc = kmalloc(sizeof(*proc)); if(proc) { + process_t *cproc; void *pdbr; void *kstack; void *ustack; @@ -217,11 +217,36 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) goto cleanup; } + cproc = process_get_current(); + + if(cproc) { + /* inherit uid and gid from the current process */ + proc->p_uid = cproc->p_uid; + proc->p_gid = cproc->p_gid; + + /* set the ppid */ + proc->p_pid = cproc->p_id; + + /* also inherit the scheduling settings */ + proc->p_tasks->t_tslice = cproc->p_tasks->t_tslice; + proc->p_tasks->t_rslice = proc->p_tasks->t_tslice; + } else { + /* + * This only happens when process_create() is called before the + * scheduler is invoked for the first time. + */ + proc->p_uid = 0; + proc->p_gid = 0; + proc->p_pid = 0; + + proc->p_tasks->t_tslice = 50; + proc->p_tasks->t_rslice = 50; + } + /* set the default signal handlers */ memcpy(proc->p_sighandler, _sig_dfl, sizeof(proc->p_sighandler)); proc->p_privl = ppl; - proc->p_pid = ppid; if(pid == PID_ANY) { /* no specific pid requested */ @@ -231,8 +256,6 @@ int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry) } proc->p_tasks->t_kstack = kstack; - proc->p_tasks->t_tslice = 50; - proc->p_tasks->t_rslice = 50; proc->p_tasks->t_proc = proc; proc->p_tasks->t_pid = proc->p_id;