version 1.1.1.1, 2008/06/03 10:38:51 |
version 1.1.1.1.2.1, 2008/08/13 17:12:45 |
|
|
#include "proc.h" |
#include "proc.h" |
|
|
/* |
/* |
* Send a signal to the task. |
* Send a signal to the process. |
*/ |
*/ |
static int |
static int |
send_sig(struct proc *proc, int sig) |
send_sig(struct proc *p, int sig) |
{ |
{ |
|
|
if (proc->pid == 0 || proc->pid == 1) |
if (p->p_pid == 0 || p->p_pid == 1) |
return EPERM; |
return EPERM; |
return exception_raise(proc->task, sig); |
|
|
DPRINTF(("proc: send_sig task=%x\n", p->p_task)); |
|
return exception_raise(p->p_task, sig); |
} |
} |
|
|
/* |
/* |
|
|
{ |
{ |
struct proc *p; |
struct proc *p; |
|
|
dprintf("killone pid=%x sig=%d\n", pid, sig); |
DPRINTF(("proc: killone pid=%d sig=%d\n", pid, sig)); |
|
|
if ((p = proc_find(pid)) == NULL) |
if ((p = proc_find(pid)) == NULL) |
return ESRCH; |
return ESRCH; |
return send_sig(p, sig); |
return send_sig(p, sig); |
} |
} |
|
|
/* |
/* |
* Send signal to all process in the process group. |
* Send a signal to all process in the process group. |
*/ |
*/ |
int |
int |
kill_pg(pid_t pgid, int sig) |
kill_pg(pid_t pgid, int sig) |
|
|
list_t head, n; |
list_t head, n; |
int err = 0; |
int err = 0; |
|
|
dprintf("killpg pgid=%x sig=%d\n", pgid, sig); |
DPRINTF(("proc: killpg pgid=%d sig=%d\n", pgid, sig)); |
|
|
if ((pgrp = pgrp_find(pgid)) == NULL) |
if ((pgrp = pgrp_find(pgid)) == NULL) |
return ESRCH; |
return ESRCH; |
|
|
head = &pgrp->members; |
head = &pgrp->pg_members; |
for (n = list_first(head); n != head; n = list_next(n)) { |
for (n = list_first(head); n != head; n = list_next(n)) { |
p = list_entry(n, struct proc, pgrp_link); |
p = list_entry(n, struct proc, p_link); |
if ((err = send_sig(p, sig)) != 0) |
if ((err = send_sig(p, sig)) != 0) |
break; |
break; |
} |
} |
|
|
pid = (pid_t)msg->data[0]; |
pid = (pid_t)msg->data[0]; |
sig = msg->data[1]; |
sig = msg->data[1]; |
|
|
dprintf("kill pid=%x sig=%d\n", pid, sig); |
DPRINTF(("proc: kill pid=%d sig=%d\n", pid, sig)); |
|
|
switch (sig) { |
switch (sig) { |
case SIGFPE: |
case SIGFPE: |
|
|
return EINVAL; |
return EINVAL; |
} |
} |
|
|
if (curproc->cap & CAP_KILL) |
if (curproc->p_cap & CAP_KILL) |
capable = 1; |
capable = 1; |
|
|
if (pid > 0) { |
if (pid > 0) { |
if (pid != curproc->pid && !capable) |
if (pid != curproc->p_pid && !capable) |
return EPERM; |
return EPERM; |
err = kill_one(pid, sig); |
err = kill_one(pid, sig); |
} |
} |
|
|
return EPERM; |
return EPERM; |
for (n = list_first(&allproc); n != &allproc; |
for (n = list_first(&allproc); n != &allproc; |
n = list_next(n)) { |
n = list_next(n)) { |
p = list_entry(n, struct proc, link); |
p = list_entry(n, struct proc, p_link); |
if (p->pid != 0 && p->pid != 1) { |
if (p->p_pid != 0 && p->p_pid != 1) { |
err = kill_one(p->pid, sig); |
err = kill_one(p->p_pid, sig); |
if (err != 0) |
if (err != 0) |
break; |
break; |
} |
} |
|
|
else if (pid == 0) { |
else if (pid == 0) { |
if ((p = proc_find(pid)) == NULL) |
if ((p = proc_find(pid)) == NULL) |
return ESRCH; |
return ESRCH; |
err = kill_pg(p->pgrp->pgid, sig); |
err = kill_pg(p->p_pgrp->pg_pgid, sig); |
} |
} |
else { |
else { |
if (curproc->pgrp->pgid != -pid && !capable) |
if (curproc->p_pgrp->pg_pgid != -pid && !capable) |
return EPERM; |
return EPERM; |
err = kill_pg(-pid, sig); |
err = kill_pg(-pid, sig); |
} |
} |