Fork me on GitHub

root/kernel/syscalls/setpgid.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_setpgid

   1 /*
   2  * fiwix/kernel/syscalls/setpgid.c
   3  *
   4  * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/process.h>
  10 #include <fiwix/sched.h>
  11 #include <fiwix/errno.h>
  12 
  13 #ifdef __DEBUG__
  14 #include <fiwix/stdio.h>
  15 #endif /*__DEBUG__ */
  16 
  17 int sys_setpgid(__pid_t pid, __pid_t pgid)
  18 {
  19         struct proc *p;
  20 
  21 #ifdef __DEBUG__
  22         printk("(pid %d) sys_setpgid(%d, %d)", current->pid, pid, pgid);
  23 #endif /*__DEBUG__ */
  24 
  25         if(pid < 0 || pgid < 0) {
  26                 return -EINVAL;
  27         }
  28         if(!pid) {
  29                 pid = current->pid;
  30         }
  31 
  32         if(!(p = get_proc_by_pid(pid))) {
  33                 return -EINVAL;
  34         }
  35         if(!pgid) {
  36                 pgid = p->pid;
  37         }
  38 
  39         if(p != current && p->ppid != current->pid) {
  40                 return -ESRCH;
  41         }
  42         if(p->sid == p->pid || p->sid != current->sid) {
  43                 return -EPERM;
  44         }
  45 
  46         {
  47                 struct proc *p;
  48 
  49                 FOR_EACH_PROCESS(p) {
  50                         if(p->pgid == pgid && p->sid != current->sid) {
  51                                 return -EPERM;
  52                         }
  53                         p = p->next;
  54                 }
  55         }
  56 
  57         if(p != current && p->flags & PF_PEXEC) {
  58                 return -EACCES;
  59         }
  60 
  61         p->pgid = pgid;
  62 
  63 #ifdef __DEBUG__
  64         printk(" -> 0\n");
  65 #endif /*__DEBUG__ */
  66 
  67         return 0;
  68 }

/* [previous][next][first][last][top][bottom][index][help] */