-
Notifications
You must be signed in to change notification settings - Fork 46
/
do_kill.c
61 lines (52 loc) · 1.5 KB
/
do_kill.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Syscall in this file: kill
* Input: m1_i1: pid to which the signal is sent
*
* Return: reply_res: default return
*
* @author Bruce Tan
* @email brucetansh@gmail.com
*
* @author Paul Monigatti
* @email paulmoni@waikato.ac.nz
*
* @create date 2017-08-23 06:09:49
*
*/
#include <kernel/kernel.h>
#include <winix/ksignal.h>
int sys_kill(struct proc* who, pid_t pid, int signum){
struct proc* to;
int valid_targets = 0;
if(signum < 0 || signum >= _NSIG)
return -EINVAL;
if(pid == 1 && (signum == SIGSTOP || signum == SIGKILL))
return -EINVAL;
foreach_proc(to){
if(pid < -1 && -pid != to->procgrp) continue;
if(pid == 0 && to->procgrp == who->procgrp) continue;
if(pid > 0 && pid != to->pid) continue;
if(pid == -1 && to->pid == 1) continue;
if(signum == 0)
return 0;
/*
* if the process to which we are sending
* is blocked, we will need to temporarily unblock it
* so that the scheduler will trigger the signal handling
*/
send_sig(to, signum);
// kdebug("send sig %d to proc %s[%d]\n", signum, to->name, to->pid);
if(to != who && to->state){
handle_pendingsig(to, true);
}
valid_targets++;
}
if(!valid_targets)
return -ESRCH;
return 0;
}
int do_kill(struct proc *who, struct message *m){
pid_t pid = m->m1_i1;
int signum = m->m1_i2;
return sys_kill(who, pid, signum);
}