teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0002-core-remove-redundant-check-when-serializing-FDs.patch

Adam Williamson f41ff6
From 2d042c75ffb71f59ebd4689c3972786c29b4bf51 Mon Sep 17 00:00:00 2001
Adam Williamson f41ff6
From: Luca Boccassi <bluca@debian.org>
Adam Williamson f41ff6
Date: Thu, 23 Nov 2023 19:14:45 +0000
Adam Williamson f41ff6
Subject: [PATCH 2/3] core: remove redundant check when serializing FDs
Adam Williamson f41ff6
Adam Williamson f41ff6
The helpers already skip if the FD is < 0
Adam Williamson f41ff6
---
Adam Williamson f41ff6
 src/core/execute-serialize.c | 50 ++++++++++++++----------------------
Adam Williamson f41ff6
 1 file changed, 19 insertions(+), 31 deletions(-)
Adam Williamson f41ff6
Adam Williamson f41ff6
diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c
Adam Williamson f41ff6
index 60c121a0d1..56c4f4da8a 100644
Adam Williamson f41ff6
--- a/src/core/execute-serialize.c
Adam Williamson f41ff6
+++ b/src/core/execute-serialize.c
Adam Williamson f41ff6
@@ -1274,11 +1274,9 @@ static int exec_parameters_serialize(const ExecParameters *p, const ExecContext
Adam Williamson f41ff6
                                 return r;
Adam Williamson f41ff6
                 }
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-                if (p->n_socket_fds + p->n_storage_fds > 0) {
Adam Williamson f41ff6
-                        r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_storage_fds);
Adam Williamson f41ff6
-                        if (r < 0)
Adam Williamson f41ff6
-                                return r;
Adam Williamson f41ff6
-                }
Adam Williamson f41ff6
+                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_storage_fds);
Adam Williamson f41ff6
+                if (r < 0)
Adam Williamson f41ff6
+                        return r;
Adam Williamson f41ff6
         }
Adam Williamson f41ff6
 
Adam Williamson f41ff6
         r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
Adam Williamson f41ff6
@@ -1351,31 +1349,23 @@ static int exec_parameters_serialize(const ExecParameters *p, const ExecContext
Adam Williamson f41ff6
                         return r;
Adam Williamson f41ff6
         }
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (p->stdin_fd >= 0) {
Adam Williamson f41ff6
-                r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
Adam Williamson f41ff6
-                if (r < 0)
Adam Williamson f41ff6
-                        return r;
Adam Williamson f41ff6
-        }
Adam Williamson f41ff6
+        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
Adam Williamson f41ff6
+        if (r < 0)
Adam Williamson f41ff6
+                return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (p->stdout_fd >= 0) {
Adam Williamson f41ff6
-                r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
Adam Williamson f41ff6
-                if (r < 0)
Adam Williamson f41ff6
-                        return r;
Adam Williamson f41ff6
-        }
Adam Williamson f41ff6
+        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
Adam Williamson f41ff6
+        if (r < 0)
Adam Williamson f41ff6
+                return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (p->stderr_fd >= 0) {
Adam Williamson f41ff6
-                r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
Adam Williamson f41ff6
-                if (r < 0)
Adam Williamson f41ff6
-                        return r;
Adam Williamson f41ff6
-        }
Adam Williamson f41ff6
+        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
Adam Williamson f41ff6
+        if (r < 0)
Adam Williamson f41ff6
+                return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (p->exec_fd >= 0) {
Adam Williamson f41ff6
-                r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
Adam Williamson f41ff6
-                if (r < 0)
Adam Williamson f41ff6
-                        return r;
Adam Williamson f41ff6
-        }
Adam Williamson f41ff6
+        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
Adam Williamson f41ff6
+        if (r < 0)
Adam Williamson f41ff6
+                return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (c && exec_context_restrict_filesystems_set(c) && p->bpf_outer_map_fd >= 0) {
Adam Williamson f41ff6
+        if (c && exec_context_restrict_filesystems_set(c)) {
Adam Williamson f41ff6
                 r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_outer_map_fd);
Adam Williamson f41ff6
                 if (r < 0)
Adam Williamson f41ff6
                         return r;
Adam Williamson f41ff6
@@ -1401,11 +1391,9 @@ static int exec_parameters_serialize(const ExecParameters *p, const ExecContext
Adam Williamson f41ff6
         if (r < 0)
Adam Williamson f41ff6
                 return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
-        if (p->user_lookup_fd >= 0) {
Adam Williamson f41ff6
-                r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
Adam Williamson f41ff6
-                if (r < 0)
Adam Williamson f41ff6
-                        return r;
Adam Williamson f41ff6
-        }
Adam Williamson f41ff6
+        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
Adam Williamson f41ff6
+        if (r < 0)
Adam Williamson f41ff6
+                return r;
Adam Williamson f41ff6
 
Adam Williamson f41ff6
         r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
Adam Williamson f41ff6
         if (r < 0)
Adam Williamson f41ff6
-- 
Adam Williamson f41ff6
2.43.0
Adam Williamson f41ff6