]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/exec-invoke: dedup error handling 40382/head
authorMike Yuan <me@yhndnzj.com>
Tue, 6 Jan 2026 21:42:37 +0000 (22:42 +0100)
committerMike Yuan <me@yhndnzj.com>
Sun, 18 Jan 2026 15:42:22 +0000 (16:42 +0100)
Also, do not log about errno if it's suffciently encoded
in the log text already.

src/core/exec-invoke.c

index c8994c83340983ea1e873eae009b7445996e5a1b..ebacec7fd9a4c2e27c3b762f17be4ffd5c1011ae 100644 (file)
@@ -4752,6 +4752,33 @@ static int setup_delegated_namespaces(
         return 0;
 }
 
+static int set_memory_thp(MemoryTHP thp) {
+        int r;
+
+        switch (thp) {
+
+        case MEMORY_THP_INHERIT:
+                return 0;
+
+        case MEMORY_THP_DISABLE:
+                r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0));
+                break;
+
+        case MEMORY_THP_MADVISE:
+                r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 1, PR_THP_DISABLE_EXCEPT_ADVISED, 0, 0));
+                break;
+
+        case MEMORY_THP_SYSTEM:
+                r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0));
+                break;
+
+        default:
+                assert_not_reached();
+        }
+
+        return r == -EINVAL ? -EOPNOTSUPP : r;
+}
+
 static bool exec_context_shall_confirm_spawn(const ExecContext *context) {
         assert(context);
 
@@ -4868,32 +4895,6 @@ static int exec_fd_mark_hot(
         return 1;
 }
 
-static int set_memory_thp(MemoryTHP thp) {
-        switch (thp) {
-
-        case MEMORY_THP_INHERIT:
-                return 0;
-
-        case MEMORY_THP_DISABLE:
-                if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0) < 0)
-                        return errno == EINVAL ? -EOPNOTSUPP : -errno;
-                return 0;
-
-        case MEMORY_THP_MADVISE:
-                if (prctl(PR_SET_THP_DISABLE, 1, PR_THP_DISABLE_EXCEPT_ADVISED, 0, 0) < 0)
-                        return errno == EINVAL ? -EOPNOTSUPP : -errno;
-                return 0;
-
-        case MEMORY_THP_SYSTEM:
-                if (prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0) < 0)
-                        return errno == EINVAL ? -EOPNOTSUPP : -errno;
-                return 0;
-
-        default:
-                assert_not_reached();
-        }
-}
-
 static int send_handoff_timestamp(
                 const ExecContext *c,
                 ExecParameters *p,
@@ -5580,7 +5581,7 @@ int exec_invoke(
 
         r = set_memory_thp(context->memory_thp);
         if (r == -EOPNOTSUPP)
-                log_debug_errno(r, "Setting MemoryTHP=%s is not supported, ignoring: %m",
+                log_debug_errno(r, "Setting MemoryTHP=%s is not supported, ignoring.",
                                 memory_thp_to_string(context->memory_thp));
         else if (r < 0) {
                 *exit_status = EXIT_MEMORY_THP;