[systemd-devel] [PATCH] main: Set umask before creating any files

Mike Gilbert floppym at gentoo.org
Thu Sep 26 07:50:31 PDT 2013


This avoids a problem when we inherit a non-zero umask from the
initramfs. This would cause /run/systemd to be created with the wrong
mode.
---
 src/core/main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/core/main.c b/src/core/main.c
index 72bd542..f532dca 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1276,6 +1276,9 @@ int main(int argc, char *argv[]) {
                 if (in_initrd())
                         initrd_timestamp = userspace_timestamp;
 
+                /* Set umask before creating any files. */
+                umask(0);
+
                 if (!skip_setup) {
                         mount_setup_early();
                         if (selinux_setup(&loaded_policy) < 0)
@@ -1339,6 +1342,9 @@ int main(int argc, char *argv[]) {
                 kernel_timestamp.monotonic = 0ULL;
                 kernel_timestamp.realtime = 0ULL;
 
+                /* Set umask before creating any files. */
+                umask(0);
+
         } else {
                 /* Running as user instance */
                 arg_running_as = SYSTEMD_USER;
@@ -1441,9 +1447,6 @@ int main(int argc, char *argv[]) {
         if (arg_running_as == SYSTEMD_SYSTEM) {
                 /* Become a session leader if we aren't one yet. */
                 setsid();
-
-                /* Disable the umask logic */
-                umask(0);
         }
 
         /* Move out of the way, so that we won't block unmounts */
-- 
1.8.3.2



More information about the systemd-devel mailing list