mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
tree-wide: use assert_se() for signal operations with constants
Continuation of a3ebe5eb62
:
in other places we sometimes use assert_se(), and sometimes normal error
handling. sigfillset and sigaddset can only fail if mask is NULL (which cannot
happen if we are passing in a reference), or if the signal number is invalid
(which really shouldn't happen when we are using a constant like SIGCHLD. If
SIGCHLD is invalid, we have a bigger problem). So let's simplify things and
always use assert_se() in those cases.
In sigset_add_many() we could conceivably pass an invalid signal, so let's keep
normal error handling here. The caller can do assert_se() around the
sigprocmask_many() call if appropriate.
'>= 0' is used for consistency with the rest of the codebase.
This commit is contained in:
parent
9d6e839ed8
commit
cd2a429ed7
@ -32,10 +32,7 @@ int asynchronous_job(void* (*func)(void *p), void *arg) {
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sigfillset(&ss) < 0) {
|
assert_se(sigfillset(&ss) >= 0);
|
||||||
r = -errno;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Block all signals before forking off the thread, so that the new thread is started with all signals
|
/* Block all signals before forking off the thread, so that the new thread is started with all signals
|
||||||
* blocked. This way the existence of the new thread won't affect signal handling in other threads. */
|
* blocked. This way the existence of the new thread won't affect signal handling in other threads. */
|
||||||
|
@ -1255,25 +1255,17 @@ int safe_fork_full(
|
|||||||
original_pid = getpid_cached();
|
original_pid = getpid_cached();
|
||||||
|
|
||||||
if (flags & (FORK_RESET_SIGNALS|FORK_DEATHSIG)) {
|
if (flags & (FORK_RESET_SIGNALS|FORK_DEATHSIG)) {
|
||||||
|
|
||||||
/* We temporarily block all signals, so that the new child has them blocked initially. This way, we can
|
/* We temporarily block all signals, so that the new child has them blocked initially. This way, we can
|
||||||
* be sure that SIGTERMs are not lost we might send to the child. */
|
* be sure that SIGTERMs are not lost we might send to the child. */
|
||||||
|
|
||||||
if (sigfillset(&ss) < 0)
|
assert_se(sigfillset(&ss) >= 0);
|
||||||
return log_full_errno(prio, errno, "Failed to reset signal set: %m");
|
|
||||||
|
|
||||||
block_signals = true;
|
block_signals = true;
|
||||||
|
|
||||||
} else if (flags & FORK_WAIT) {
|
} else if (flags & FORK_WAIT) {
|
||||||
|
|
||||||
/* Let's block SIGCHLD at least, so that we can safely watch for the child process */
|
/* Let's block SIGCHLD at least, so that we can safely watch for the child process */
|
||||||
|
|
||||||
if (sigemptyset(&ss) < 0)
|
assert_se(sigemptyset(&ss) >= 0);
|
||||||
return log_full_errno(prio, errno, "Failed to clear signal set: %m");
|
assert_se(sigaddset(&ss, SIGCHLD) >= 0);
|
||||||
|
|
||||||
if (sigaddset(&ss, SIGCHLD) < 0)
|
|
||||||
return log_full_errno(prio, errno, "Failed to add SIGCHLD to signal set: %m");
|
|
||||||
|
|
||||||
block_signals = true;
|
block_signals = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +236,7 @@ int journal_file_set_offline(JournalFile *f, bool wait) {
|
|||||||
sigset_t ss, saved_ss;
|
sigset_t ss, saved_ss;
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
if (sigfillset(&ss) < 0)
|
assert_se(sigfillset(&ss) >= 0);
|
||||||
return -errno;
|
|
||||||
|
|
||||||
r = pthread_sigmask(SIG_BLOCK, &ss, &saved_ss);
|
r = pthread_sigmask(SIG_BLOCK, &ss, &saved_ss);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
|
@ -433,8 +433,7 @@ static int start_threads(sd_resolve *resolve, unsigned extra) {
|
|||||||
unsigned n;
|
unsigned n;
|
||||||
int r, k;
|
int r, k;
|
||||||
|
|
||||||
if (sigfillset(&ss) < 0)
|
assert_se(sigfillset(&ss) >= 0);
|
||||||
return -errno;
|
|
||||||
|
|
||||||
/* No signals in forked off threads please. We set the mask before forking, so that the threads never exist
|
/* No signals in forked off threads please. We set the mask before forking, so that the threads never exist
|
||||||
* with a different mask than a fully blocked one */
|
* with a different mask than a fully blocked one */
|
||||||
|
Loading…
Reference in New Issue
Block a user