* Common code for kill process group/broadcast kill. * cp is calling process. */
| 1727 | * cp is calling process. |
| 1728 | */ |
| 1729 | static int |
| 1730 | killpg1(struct thread *td, int sig, int pgid, int all, ksiginfo_t *ksi) |
| 1731 | { |
| 1732 | struct proc *p; |
| 1733 | struct pgrp *pgrp; |
| 1734 | struct killpg1_ctx arg; |
| 1735 | |
| 1736 | arg.td = td; |
| 1737 | arg.ksi = ksi; |
| 1738 | arg.sig = sig; |
| 1739 | arg.sent = false; |
| 1740 | arg.found = false; |
| 1741 | arg.ret = 0; |
| 1742 | if (all) { |
| 1743 | /* |
| 1744 | * broadcast |
| 1745 | */ |
| 1746 | sx_slock(&allproc_lock); |
| 1747 | FOREACH_PROC_IN_SYSTEM(p) { |
| 1748 | killpg1_sendsig(p, true, &arg); |
| 1749 | } |
| 1750 | sx_sunlock(&allproc_lock); |
| 1751 | } else { |
| 1752 | sx_slock(&proctree_lock); |
| 1753 | if (pgid == 0) { |
| 1754 | /* |
| 1755 | * zero pgid means send to my process group. |
| 1756 | */ |
| 1757 | pgrp = td->td_proc->p_pgrp; |
| 1758 | PGRP_LOCK(pgrp); |
| 1759 | } else { |
| 1760 | pgrp = pgfind(pgid); |
| 1761 | if (pgrp == NULL) { |
| 1762 | sx_sunlock(&proctree_lock); |
| 1763 | return (ESRCH); |
| 1764 | } |
| 1765 | } |
| 1766 | sx_sunlock(&proctree_lock); |
| 1767 | LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { |
| 1768 | killpg1_sendsig(p, false, &arg); |
| 1769 | } |
| 1770 | PGRP_UNLOCK(pgrp); |
| 1771 | } |
| 1772 | MPASS(arg.ret != 0 || arg.found || !arg.sent); |
| 1773 | if (arg.ret == 0 && !arg.sent) |
| 1774 | arg.ret = arg.found ? EPERM : ESRCH; |
| 1775 | return (arg.ret); |
| 1776 | } |
| 1777 | |
| 1778 | #ifndef _SYS_SYSPROTO_H_ |
| 1779 | struct kill_args { |
no test coverage detected