From d173d5564f59426fcff234f6b8b2cf0157a6cd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 31 Jan 2023 16:24:50 +0100 Subject: [PATCH] basic/user-util: create /etc from take_etc_passwd_lock This allows sysusers to operate with --root that is an empty directory. It may be useful to, for example, populate the user database before installing anything else. firstboot was already doing this, so drop the duplicated call there. --- src/basic/user-util.c | 3 +++ src/firstboot/firstboot.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 734122c2a3..6c5041230a 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -19,6 +19,7 @@ #include "fileio.h" #include "format-util.h" #include "macro.h" +#include "mkdir.h" #include "parse-util.h" #include "path-util.h" #include "path-util.h" @@ -688,6 +689,8 @@ int take_etc_passwd_lock(const char *root) { if (!path) return log_oom_debug(); + (void) mkdir_parents(path, 0755); + _cleanup_close_ int fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600); if (fd < 0) return log_debug_errno(errno, "Cannot open %s: %m", path); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 45bb386da2..9e79f84691 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -904,8 +904,6 @@ static int process_root_account(void) { return 0; } - (void) mkdir_parents(etc_passwd, 0755); - lock = take_etc_passwd_lock(arg_root); if (lock < 0) return log_error_errno(lock, "Failed to take a lock on %s: %m", etc_passwd);