We use this at various places, let's unify this in one global constant.
This changes flags in crash-handler.c in a tiny irrelevant way: we ask
syscalls to be continued on signal arrival, which we previously didn't.
But that shouldn't change anything, the only thing we'll do in the
relevant process is call raise(), and that's it, hence there definitely
are no syscalls to restart or not to restart.
#include "string-util.h"
int reset_all_signal_handlers(void) {
- static const struct sigaction sa = {
- .sa_handler = SIG_DFL,
- .sa_flags = SA_RESTART,
- };
int ret = 0, r;
for (int sig = 1; sig < _NSIG; sig++) {
/* On Linux the first two RT signals are reserved by glibc, and sigaction() will return
* EINVAL for them. */
- r = RET_NERRNO(sigaction(sig, &sa, NULL));
+ r = RET_NERRNO(sigaction(sig, &sigaction_default, NULL));
if (r != -EINVAL)
RET_GATHER(ret, r);
}
if (rt_tgsigqueueinfo(p, gettid(), sig, siginfo) < 0)
assert_se(kill(p, sig) >= 0);
}
+
+const struct sigaction sigaction_ignore = {
+ .sa_handler = SIG_IGN,
+ .sa_flags = SA_RESTART,
+};
+
+const struct sigaction sigaction_default = {
+ .sa_handler = SIG_DFL,
+ .sa_flags = SA_RESTART,
+};
#define ignore_signals(...) \
sigaction_many_internal( \
- &(const struct sigaction) { \
- .sa_handler = SIG_IGN, \
- .sa_flags = SA_RESTART \
- }, \
+ &sigaction_ignore, \
__VA_ARGS__, \
-1)
#define default_signals(...) \
sigaction_many_internal( \
- &(const struct sigaction) { \
- .sa_handler = SIG_DFL, \
- .sa_flags = SA_RESTART \
- }, \
+ &sigaction_default, \
__VA_ARGS__, \
-1)
#define pop_pending_signal(...) pop_pending_signal_internal(__VA_ARGS__, -1)
void propagate_signal(int sig, siginfo_t *siginfo);
+
+extern const struct sigaction sigaction_ignore;
+extern const struct sigaction sigaction_default;
#include "path-util.h"
#include "proc-cmdline.h"
#include "process-util.h"
+#include "signal-util.h"
#include "socket-util.h"
#include "stat-util.h"
#include "stdio-util.h"
}
for (;;) {
- struct sigaction sa_old, sa_new = {
- .sa_handler = SIG_IGN,
- .sa_flags = SA_RESTART,
- };
-
if (notify >= 0) {
r = flush_fd(notify);
if (r < 0)
return fd;
/* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed if we already own the tty. */
- assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
+ struct sigaction sa_old;
+ assert_se(sigaction(SIGHUP, &sigaction_ignore, &sa_old) >= 0);
/* First, try to get the tty */
r = RET_NERRNO(ioctl(fd, TIOCSCTTY, (flags & ~ACQUIRE_TERMINAL_PERMISSIVE) == ACQUIRE_TERMINAL_FORCE));
/* Reset signal handler to old value */
- assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
+ assert_se(sigaction(SIGHUP, &sa_old, NULL) >= 0);
/* Success? Exit the loop now! */
if (r >= 0)
}
int release_terminal(void) {
- static const struct sigaction sa_new = {
- .sa_handler = SIG_IGN,
- .sa_flags = SA_RESTART,
- };
-
_cleanup_close_ int fd = -EBADF;
- struct sigaction sa_old;
int r;
fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
/* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
* by our own TIOCNOTTY */
- assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
+ struct sigaction sa_old;
+ assert_se(sigaction(SIGHUP, &sigaction_ignore, &sa_old) >= 0);
r = RET_NERRNO(ioctl(fd, TIOCNOTTY));
- assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
+ assert_se(sigaction(SIGHUP, &sa_old, NULL) >= 0);
return r;
}
else if (pid == 0) {
/* Enable default signal handler for core dump */
- sa = (struct sigaction) {
- .sa_handler = SIG_DFL,
- };
- (void) sigaction(sig, &sa, NULL);
+ (void) sigaction(sig, &sigaction_default, NULL);
/* Don't limit the coredump size */
(void) setrlimit(RLIMIT_CORE, &RLIMIT_MAKE_CONST(RLIM_INFINITY));
.sa_handler = nop_signal_handler,
.sa_flags = SA_NOCLDSTOP | SA_RESTART,
};
- static const struct sigaction sighup = {
- .sa_handler = SIG_DFL,
- .sa_flags = SA_RESTART,
- };
int r;
assert_se(sigaction(SIGCHLD, &sigchld, NULL) >= 0);
- assert_se(sigaction(SIGHUP, &sighup, NULL) >= 0);
+ assert_se(sigaction(SIGHUP, &sigaction_default, NULL) >= 0);
assert_se(sigprocmask_many(SIG_UNBLOCK, NULL, SIGHUP, SIGCHLD) >= 0);
r = safe_fork("(sd-passwd)", FORK_RESET_SIGNALS|FORK_LOG, ret_pid);