Brian Stinson 2593d8
From 5df63c2ddf93bab5e7f13e09dfb1f97a011b3451 Mon Sep 17 00:00:00 2001
Brian Stinson 2593d8
From: Taro Yamada <archer_ame@yahoo.co.jp>
Brian Stinson 2593d8
Date: Sun, 27 Jan 2019 13:50:04 +0900
Brian Stinson 2593d8
Subject: [PATCH] Add a warning about the difference in permissions between
Brian Stinson 2593d8
 existing directories and unit settings.
Brian Stinson 2593d8
Brian Stinson 2593d8
To follows the intent of 30c81ce, this change does not execute chmod() and just add warnings.
Brian Stinson 2593d8
Brian Stinson 2593d8
(cherry picked from commit 6cff72eb0a18d8547f005a481cd0622d3bc78483)
Brian Stinson 2593d8
Brian Stinson 2593d8
Related: #1778384
Brian Stinson 2593d8
---
Brian Stinson 2593d8
 src/core/execute.c | 17 +++++++++++++++--
Brian Stinson 2593d8
 1 file changed, 15 insertions(+), 2 deletions(-)
Brian Stinson 2593d8
Brian Stinson 2593d8
diff --git a/src/core/execute.c b/src/core/execute.c
Brian Stinson 2593d8
index 8293c522bc..9ddba00421 100644
Brian Stinson 2593d8
--- a/src/core/execute.c
Brian Stinson 2593d8
+++ b/src/core/execute.c
Brian Stinson 2593d8
@@ -2099,8 +2099,21 @@ static int setup_exec_directory(
Brian Stinson 2593d8
                         r = mkdir_label(p, context->directories[type].mode);
Brian Stinson 2593d8
                         if (r < 0 && r != -EEXIST)
Brian Stinson 2593d8
                                 goto fail;
Brian Stinson 2593d8
-                        if (r == -EEXIST && !context->dynamic_user)
Brian Stinson 2593d8
-                                continue;
Brian Stinson 2593d8
+                        if (r == -EEXIST) {
Brian Stinson 2593d8
+                                struct stat st;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+                                if (stat(p, &st) < 0) {
Brian Stinson 2593d8
+                                        r = -errno;
Brian Stinson 2593d8
+                                        goto fail;
Brian Stinson 2593d8
+                                }
Brian Stinson 2593d8
+                                if (((st.st_mode ^ context->directories[type].mode) & 07777) != 0)
Brian Stinson 2593d8
+                                        log_warning("%s \'%s\' already exists but the mode is different. "
Brian Stinson 2593d8
+                                                    "(filesystem: %o %sMode: %o)",
Brian Stinson 2593d8
+                                                    exec_directory_type_to_string(type), *rt,
Brian Stinson 2593d8
+                                                    st.st_mode & 07777, exec_directory_type_to_string(type), context->directories[type].mode & 07777);
Brian Stinson 2593d8
+                                if (!context->dynamic_user)
Brian Stinson 2593d8
+                                        continue;
Brian Stinson 2593d8
+                        }
Brian Stinson 2593d8
                 }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
                 /* Don't change the owner of the configuration directory, as in the common case it is not written to by