Remove explicit SIGCHLD handling. (#7816)
* Remove unused SIGCHLD handling. * Remove unused `init_sigchld`. * Remove unnecessary `#define RUBY_SIGCHLD (0)`. * Remove unused `SIGCHLD_LOSSY`.
This commit is contained in:
parent
bab9966b7a
commit
ab7bb38aca
Notes:
git
2023-05-15 14:15:12 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
82
signal.c
82
signal.c
@ -133,7 +133,7 @@ static const struct signals {
|
|||||||
#ifdef SIGCONT
|
#ifdef SIGCONT
|
||||||
{"CONT", SIGCONT},
|
{"CONT", SIGCONT},
|
||||||
#endif
|
#endif
|
||||||
#if RUBY_SIGCHLD
|
#ifdef RUBY_SIGCHLD
|
||||||
{"CHLD", RUBY_SIGCHLD },
|
{"CHLD", RUBY_SIGCHLD },
|
||||||
{"CLD", RUBY_SIGCHLD },
|
{"CLD", RUBY_SIGCHLD },
|
||||||
#endif
|
#endif
|
||||||
@ -509,9 +509,6 @@ static struct {
|
|||||||
rb_atomic_t cnt[RUBY_NSIG];
|
rb_atomic_t cnt[RUBY_NSIG];
|
||||||
rb_atomic_t size;
|
rb_atomic_t size;
|
||||||
} signal_buff;
|
} signal_buff;
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
volatile unsigned int ruby_nocldwait;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define sighandler_t ruby_sighandler_t
|
#define sighandler_t ruby_sighandler_t
|
||||||
|
|
||||||
@ -609,27 +606,6 @@ ruby_signal(int signum, sighandler_t handler)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
case RUBY_SIGCHLD:
|
|
||||||
if (handler == SIG_IGN) {
|
|
||||||
ruby_nocldwait = 1;
|
|
||||||
# ifdef USE_SIGALTSTACK
|
|
||||||
if (sigact.sa_flags & SA_SIGINFO) {
|
|
||||||
sigact.sa_sigaction = (ruby_sigaction_t*)sighandler;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sigact.sa_handler = sighandler;
|
|
||||||
}
|
|
||||||
# else
|
|
||||||
sigact.sa_handler = handler;
|
|
||||||
sigact.sa_flags = 0;
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ruby_nocldwait = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
|
#if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
|
||||||
case SIGSEGV:
|
case SIGSEGV:
|
||||||
#ifdef SIGBUS
|
#ifdef SIGBUS
|
||||||
@ -708,35 +684,14 @@ signal_enque(int sig)
|
|||||||
ATOMIC_INC(signal_buff.size);
|
ATOMIC_INC(signal_buff.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
static rb_atomic_t sigchld_hit;
|
|
||||||
/* destructive getter than simple predicate */
|
|
||||||
# define GET_SIGCHLD_HIT() ATOMIC_EXCHANGE(sigchld_hit, 0)
|
|
||||||
#else
|
|
||||||
# define GET_SIGCHLD_HIT() 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sighandler(int sig)
|
sighandler(int sig)
|
||||||
{
|
{
|
||||||
int old_errnum = errno;
|
int old_errnum = errno;
|
||||||
|
|
||||||
/* the VM always needs to handle SIGCHLD for rb_waitpid */
|
signal_enque(sig);
|
||||||
if (sig == RUBY_SIGCHLD) {
|
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
rb_vm_t *vm = GET_VM();
|
|
||||||
ATOMIC_EXCHANGE(sigchld_hit, 1);
|
|
||||||
|
|
||||||
/* avoid spurious wakeup in main thread if and only if nobody uses trap(:CHLD) */
|
|
||||||
if (vm && ACCESS_ONCE(VALUE, vm->trap_list.cmd[sig])) {
|
|
||||||
signal_enque(sig);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
signal_enque(sig);
|
|
||||||
}
|
|
||||||
rb_thread_wakeup_timer_thread(sig);
|
rb_thread_wakeup_timer_thread(sig);
|
||||||
|
|
||||||
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
#if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
|
||||||
ruby_signal(sig, sighandler);
|
ruby_signal(sig, sighandler);
|
||||||
#endif
|
#endif
|
||||||
@ -1152,9 +1107,6 @@ default_handler(int sig)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef SIGUSR2
|
#ifdef SIGUSR2
|
||||||
case SIGUSR2:
|
case SIGUSR2:
|
||||||
#endif
|
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
case RUBY_SIGCHLD:
|
|
||||||
#endif
|
#endif
|
||||||
func = sighandler;
|
func = sighandler;
|
||||||
break;
|
break;
|
||||||
@ -1221,9 +1173,6 @@ trap_handler(VALUE *cmd, int sig)
|
|||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
if (memcmp(cptr, "SYSTEM_DEFAULT", 14) == 0) {
|
if (memcmp(cptr, "SYSTEM_DEFAULT", 14) == 0) {
|
||||||
if (sig == RUBY_SIGCHLD) {
|
|
||||||
goto sig_dfl;
|
|
||||||
}
|
|
||||||
func = SIG_DFL;
|
func = SIG_DFL;
|
||||||
*cmd = 0;
|
*cmd = 0;
|
||||||
}
|
}
|
||||||
@ -1441,6 +1390,7 @@ sig_list(VALUE _)
|
|||||||
if (reserved_signal_p(signum)) rb_bug(failed); \
|
if (reserved_signal_p(signum)) rb_bug(failed); \
|
||||||
perror(failed); \
|
perror(failed); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
install_sighandler_core(int signum, sighandler_t handler, sighandler_t *old_handler)
|
install_sighandler_core(int signum, sighandler_t handler, sighandler_t *old_handler)
|
||||||
{
|
{
|
||||||
@ -1465,25 +1415,6 @@ install_sighandler_core(int signum, sighandler_t handler, sighandler_t *old_hand
|
|||||||
# define force_install_sighandler(signum, handler, old_handler) \
|
# define force_install_sighandler(signum, handler, old_handler) \
|
||||||
INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, old_handler), #signum, signum)
|
INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, old_handler), #signum, signum)
|
||||||
|
|
||||||
#if RUBY_SIGCHLD
|
|
||||||
static int
|
|
||||||
init_sigchld(int sig)
|
|
||||||
{
|
|
||||||
sighandler_t oldfunc;
|
|
||||||
sighandler_t func = sighandler;
|
|
||||||
|
|
||||||
oldfunc = ruby_signal(sig, SIG_DFL);
|
|
||||||
if (oldfunc == SIG_ERR) return -1;
|
|
||||||
ruby_signal(sig, func);
|
|
||||||
ACCESS_ONCE(VALUE, GET_VM()->trap_list.cmd[sig]) = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
# define init_sigchld(signum) \
|
|
||||||
INSTALL_SIGHANDLER(init_sigchld(signum), #signum, signum)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_sig_finalize(void)
|
ruby_sig_finalize(void)
|
||||||
{
|
{
|
||||||
@ -1495,7 +1426,6 @@ ruby_sig_finalize(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ruby_enable_coredump = 0;
|
int ruby_enable_coredump = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1592,8 +1522,8 @@ Init_signal(void)
|
|||||||
install_sighandler(SIGSYS, sig_do_nothing);
|
install_sighandler(SIGSYS, sig_do_nothing);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if RUBY_SIGCHLD
|
#ifdef RUBY_SIGCHLD
|
||||||
init_sigchld(RUBY_SIGCHLD);
|
install_sighandler(RUBY_SIGCHLD, sighandler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb_enable_interrupt();
|
rb_enable_interrupt();
|
||||||
|
2
thread.c
2
thread.c
@ -4511,7 +4511,7 @@ check_signals_nogvl(rb_thread_t *th, int sigwait_fd)
|
|||||||
else {
|
else {
|
||||||
threadptr_trap_interrupt(vm->ractor.main_thread);
|
threadptr_trap_interrupt(vm->ractor.main_thread);
|
||||||
}
|
}
|
||||||
ret = TRUE; /* for SIGCHLD_LOSSY && rb_sigwait_sleep */
|
ret = TRUE; /* for rb_sigwait_sleep */
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
13
vm_core.h
13
vm_core.h
@ -132,18 +132,9 @@ extern int ruby_assert_critical_section_entered;
|
|||||||
#define RUBY_NSIG NSIG
|
#define RUBY_NSIG NSIG
|
||||||
|
|
||||||
#if defined(SIGCLD)
|
#if defined(SIGCLD)
|
||||||
# define RUBY_SIGCHLD (SIGCLD)
|
# define RUBY_SIGCHLD (SIGCLD)
|
||||||
#elif defined(SIGCHLD)
|
#elif defined(SIGCHLD)
|
||||||
# define RUBY_SIGCHLD (SIGCHLD)
|
# define RUBY_SIGCHLD (SIGCHLD)
|
||||||
#else
|
|
||||||
# define RUBY_SIGCHLD (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* platforms with broken or non-existent SIGCHLD work by polling */
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
# define SIGCHLD_LOSSY (1)
|
|
||||||
#else
|
|
||||||
# define SIGCHLD_LOSSY (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
|
#if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user