Skip to content

Commit dc3270f

Browse files
polarvidRbb666
authored andcommitted
feat: add signal kill all functionality
This change introduces the `lwp_signal_kill_all` function, which allows a signal to be sent to all processes in the system. The function iterates over all PIDs and sends the specified signal to each process, except those that are protected from signals. This enhancement provides a convenient way to broadcast signals across all processes in the system. Changes: - Added `lwp_signal_kill_all` function in `lwp_signal.c` to broadcast a signal to all processes by iterating over all PIDs using the existing `lwp_pid_for_each` function. - Introduced a new `kill_all_param` structure to encapsulate the signal information needed for killing processes. - Added internal `_kill_each` helper function for sending the signal to each PID. - Updated `lwp_signal.h` with the new function prototype for `lwp_signal_kill_all`. - Modified `sys_kill` in `lwp_syscall.c` to call `lwp_signal_kill_all` when a process is not specified. Signed-off-by: Shell <[email protected]>
1 parent c0b0838 commit dc3270f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

components/lwp/lwp_signal.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,3 +1442,41 @@ rt_err_t lwp_pgrp_signal_kill(rt_processgroup_t pgrp, long signo, long code,
14421442

14431443
return rc;
14441444
}
1445+
1446+
struct kill_all_param
1447+
{
1448+
long signo;
1449+
long code;
1450+
lwp_siginfo_ext_t value;
1451+
};
1452+
1453+
static int _kill_each(pid_t pid, void *data)
1454+
{
1455+
struct kill_all_param *param = data;
1456+
rt_lwp_t lwp;
1457+
rt_err_t error;
1458+
1459+
lwp = lwp_from_pid_locked(pid);
1460+
if (lwp && !lwp->sig_protected)
1461+
{
1462+
error = lwp_signal_kill(lwp, param->signo, param->code, param->value);
1463+
}
1464+
else
1465+
{
1466+
error = RT_EOK;
1467+
}
1468+
1469+
return error;
1470+
}
1471+
1472+
rt_err_t lwp_signal_kill_all(long signo, long code, lwp_siginfo_ext_t value)
1473+
{
1474+
struct kill_all_param buf =
1475+
{
1476+
.signo = signo,
1477+
.code = code,
1478+
.value = value,
1479+
};
1480+
1481+
return lwp_pid_for_each(_kill_each, &buf);
1482+
}

components/lwp/lwp_signal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ rt_err_t lwp_signal_setitimer(struct rt_lwp *lwp, int which,
229229

230230
rt_bool_t lwp_signal_restart_syscall(struct rt_lwp *lwp, int error_code);
231231

232+
rt_err_t lwp_signal_kill_all(long signo, long code, lwp_siginfo_ext_t value);
233+
232234
#ifdef __cplusplus
233235
}
234236
#endif

components/lwp/lwp_syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ sysret_t sys_kill(int pid, int signo)
994994
* of system processes) for which the process has permission to send
995995
* that signal.
996996
*/
997-
kret = -RT_ENOSYS;
997+
kret = lwp_signal_kill_all(signo, SI_USER, 0);
998998
}
999999

10001000
switch (kret)

0 commit comments

Comments
 (0)