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 <smokewood@qq.com>
This commit is contained in:
parent
c0b0838892
commit
dc3270f14e
@ -1442,3 +1442,41 @@ rt_err_t lwp_pgrp_signal_kill(rt_processgroup_t pgrp, long signo, long code,
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
struct kill_all_param
|
||||
{
|
||||
long signo;
|
||||
long code;
|
||||
lwp_siginfo_ext_t value;
|
||||
};
|
||||
|
||||
static int _kill_each(pid_t pid, void *data)
|
||||
{
|
||||
struct kill_all_param *param = data;
|
||||
rt_lwp_t lwp;
|
||||
rt_err_t error;
|
||||
|
||||
lwp = lwp_from_pid_locked(pid);
|
||||
if (lwp && !lwp->sig_protected)
|
||||
{
|
||||
error = lwp_signal_kill(lwp, param->signo, param->code, param->value);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = RT_EOK;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
rt_err_t lwp_signal_kill_all(long signo, long code, lwp_siginfo_ext_t value)
|
||||
{
|
||||
struct kill_all_param buf =
|
||||
{
|
||||
.signo = signo,
|
||||
.code = code,
|
||||
.value = value,
|
||||
};
|
||||
|
||||
return lwp_pid_for_each(_kill_each, &buf);
|
||||
}
|
||||
|
@ -229,6 +229,8 @@ rt_err_t lwp_signal_setitimer(struct rt_lwp *lwp, int which,
|
||||
|
||||
rt_bool_t lwp_signal_restart_syscall(struct rt_lwp *lwp, int error_code);
|
||||
|
||||
rt_err_t lwp_signal_kill_all(long signo, long code, lwp_siginfo_ext_t value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -994,7 +994,7 @@ sysret_t sys_kill(int pid, int signo)
|
||||
* of system processes) for which the process has permission to send
|
||||
* that signal.
|
||||
*/
|
||||
kret = -RT_ENOSYS;
|
||||
kret = lwp_signal_kill_all(signo, SI_USER, 0);
|
||||
}
|
||||
|
||||
switch (kret)
|
||||
|
Loading…
x
Reference in New Issue
Block a user