anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0446-core-make-exec-code-a-bit-more-readable.patch

803fb7
From ccf46ebc548054f876a418fc2e949a05a74a9c2a Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Wed, 13 May 2015 16:34:02 +0200
803fb7
Subject: [PATCH] core: make exec code a bit more readable
803fb7
803fb7
Let's add a function that checks whether we need fs namespacing, to make
803fb7
things easier to read, instead of using a humungous if expression...
803fb7
803fb7
Cherry-picked from: 8b44a3d22c1fdfc5ce5fcb77e38a90ec02ba8019
803fb7
Related: #1421181
803fb7
---
803fb7
 src/core/execute.c | 41 +++++++++++++++++++++++++++++++----------
803fb7
 1 file changed, 31 insertions(+), 10 deletions(-)
803fb7
803fb7
diff --git a/src/core/execute.c b/src/core/execute.c
803fb7
index e9b4359a7..59340ec05 100644
803fb7
--- a/src/core/execute.c
803fb7
+++ b/src/core/execute.c
803fb7
@@ -1256,6 +1256,36 @@ static int build_environment(
803fb7
         return 0;
803fb7
 }
803fb7
 
803fb7
+static bool exec_needs_mount_namespace(
803fb7
+                const ExecContext *context,
803fb7
+                const ExecParameters *params,
803fb7
+                ExecRuntime *runtime) {
803fb7
+
803fb7
+        assert(context);
803fb7
+        assert(params);
803fb7
+
803fb7
+        if (!strv_isempty(context->read_write_dirs) ||
803fb7
+            !strv_isempty(context->read_only_dirs) ||
803fb7
+            !strv_isempty(context->inaccessible_dirs))
803fb7
+                return true;
803fb7
+
803fb7
+        if (context->mount_flags != 0)
803fb7
+                return true;
803fb7
+
803fb7
+        if (context->private_tmp && runtime && (runtime->tmp_dir || runtime->var_tmp_dir))
803fb7
+                return true;
803fb7
+
803fb7
+        if (params->bus_endpoint_path)
803fb7
+                return true;
803fb7
+
803fb7
+        if (context->private_devices ||
803fb7
+            context->protect_system != PROTECT_SYSTEM_NO ||
803fb7
+            context->protect_home != PROTECT_HOME_NO)
803fb7
+                return true;
803fb7
+
803fb7
+        return false;
803fb7
+}
803fb7
+
803fb7
 static int exec_child(
803fb7
                 ExecCommand *command,
803fb7
                 const ExecContext *context,
803fb7
@@ -1563,16 +1593,7 @@ static int exec_child(
803fb7
                 }
803fb7
         }
803fb7
 
803fb7
-        if (!strv_isempty(context->read_write_dirs) ||
803fb7
-            !strv_isempty(context->read_only_dirs) ||
803fb7
-            !strv_isempty(context->inaccessible_dirs) ||
803fb7
-            context->mount_flags != 0 ||
803fb7
-            (context->private_tmp && runtime && (runtime->tmp_dir || runtime->var_tmp_dir)) ||
803fb7
-            params->bus_endpoint_path ||
803fb7
-            context->private_devices ||
803fb7
-            context->protect_system != PROTECT_SYSTEM_NO ||
803fb7
-            context->protect_home != PROTECT_HOME_NO) {
803fb7
-
803fb7
+        if (exec_needs_mount_namespace(context, params, runtime)) {
803fb7
                 char *tmp = NULL, *var = NULL;
803fb7
 
803fb7
                 /* The runtime struct only contains the parent