]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use assert_se() for signal operations with constants
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Dec 2018 08:20:15 +0000 (09:20 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Dec 2018 18:49:28 +0000 (19:49 +0100)
Continuation of a3ebe5eb620e49f0d24082876cafc7579261e64f:
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.

src/basic/async.c
src/basic/process-util.c
src/journal/journal-file.c
src/libsystemd/sd-resolve/sd-resolve.c

index 1c4b575b05b43390d4d51e794aaf287c25111ebf..c45ca01847f398afc453133c19a247f599eb2c65 100644 (file)
@@ -32,10 +32,7 @@ int asynchronous_job(void* (*func)(void *p), void *arg) {
                 goto finish;
         }
 
-        if (sigfillset(&ss) < 0) {
-                r = -errno;
-                goto finish;
-        }
+        assert_se(sigfillset(&ss) >= 0);
 
         /* 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. */
index 3cfaceea8540b22645fb89fda32489ec3a8381f3..448503409b5bb6ae930bc25524b9d7f828cdc7a2 100644 (file)
@@ -1255,25 +1255,17 @@ int safe_fork_full(
         original_pid = getpid_cached();
 
         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
                  * be sure that SIGTERMs are not lost we might send to the child. */
 
-                if (sigfillset(&ss) < 0)
-                        return log_full_errno(prio, errno, "Failed to reset signal set: %m");
-
+                assert_se(sigfillset(&ss) >= 0);
                 block_signals = true;
 
         } else if (flags & FORK_WAIT) {
-
                 /* Let's block SIGCHLD at least, so that we can safely watch for the child process */
 
-                if (sigemptyset(&ss) < 0)
-                        return log_full_errno(prio, errno, "Failed to clear signal set: %m");
-
-                if (sigaddset(&ss, SIGCHLD) < 0)
-                        return log_full_errno(prio, errno, "Failed to add SIGCHLD to signal set: %m");
-
+                assert_se(sigemptyset(&ss) >= 0);
+                assert_se(sigaddset(&ss, SIGCHLD) >= 0);
                 block_signals = true;
         }
 
index 3e5733da6b97c0937c2ac7d8a9281c2d3a58ce9d..56827f9f3698b19fb032e7ff8f8cce1e24982e3a 100644 (file)
@@ -236,8 +236,7 @@ int journal_file_set_offline(JournalFile *f, bool wait) {
                 sigset_t ss, saved_ss;
                 int k;
 
-                if (sigfillset(&ss) < 0)
-                        return -errno;
+                assert_se(sigfillset(&ss) >= 0);
 
                 r = pthread_sigmask(SIG_BLOCK, &ss, &saved_ss);
                 if (r > 0)
index 47986a4a63cd5b220496e1d4cb07a8290616aec8..21d783b8f00fa7ba16bd2e8b6965fc8d152437c0 100644 (file)
@@ -433,8 +433,7 @@ static int start_threads(sd_resolve *resolve, unsigned extra) {
         unsigned n;
         int r, k;
 
-        if (sigfillset(&ss) < 0)
-                return -errno;
+        assert_se(sigfillset(&ss) >= 0);
 
         /* 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 */