]> git.corax.cc Git - corax/commitdiff
Implement process ownership and inheritance
authorMatthias Kruk <m@m10k.eu>
Wed, 6 Nov 2019 06:51:42 +0000 (15:51 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 6 Nov 2019 06:51:42 +0000 (15:51 +0900)
kernel/core/process.c

index 58890c35f3ead935874d7e68f0c10202bc00faeb..710fc7580d986c9c09f5b7b4e63b9b2e86b892b3 100644 (file)
@@ -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;