]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: move take_password_lock() to user-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 18:08:09 +0000 (19:08 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:55 +0000 (13:25 +0100)
Also, rename it take_etc_passwd_lock(), in order to make it more
expressive.

src/basic/user-util.c
src/basic/user-util.h
src/basic/util.c
src/basic/util.h
src/firstboot/firstboot.c
src/sysusers/sysusers.c

index 0b3cf3d733bea4554543b080a0a6d76fd3141191..bdee77a7d2802f856ca9bff523540502cebaae14 100644 (file)
@@ -22,6 +22,7 @@
 #include <pwd.h>
 #include <grp.h>
 
+#include "fd-util.h"
 #include "macro.h"
 #include "parse-util.h"
 #include "path-util.h"
@@ -428,3 +429,43 @@ int reset_uid_gid(void) {
 
         return 0;
 }
+
+int take_etc_passwd_lock(const char *root) {
+
+        struct flock flock = {
+                .l_type = F_WRLCK,
+                .l_whence = SEEK_SET,
+                .l_start = 0,
+                .l_len = 0,
+        };
+
+        const char *path;
+        int fd, r;
+
+        /* This is roughly the same as lckpwdf(), but not as awful. We
+         * don't want to use alarm() and signals, hence we implement
+         * our own trivial version of this.
+         *
+         * Note that shadow-utils also takes per-database locks in
+         * addition to lckpwdf(). However, we don't given that they
+         * are redundant as they they invoke lckpwdf() first and keep
+         * it during everything they do. The per-database locks are
+         * awfully racy, and thus we just won't do them. */
+
+        if (root)
+                path = prefix_roota(root, "/etc/.pwd.lock");
+        else
+                path = "/etc/.pwd.lock";
+
+        fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
+        if (fd < 0)
+                return -errno;
+
+        r = fcntl(fd, F_SETLKW, &flock);
+        if (r < 0) {
+                safe_close(fd);
+                return -errno;
+        }
+
+        return fd;
+}
index 7995698f272e8c6fc3e8435ffd7b97a6415ac7f5..4496f58ba3c1e880f28ed9ebe86e6a272dabf740 100644 (file)
@@ -52,3 +52,5 @@ int get_home_dir(char **ret);
 int get_shell(char **_ret);
 
 int reset_uid_gid(void);
+
+int take_etc_passwd_lock(const char *root);
index 576c6238d6321720f93bfd59c291d98fa3d4825e..2ee5de9cd03041cf65c89535e5a220debcc23ca1 100644 (file)
@@ -2096,46 +2096,6 @@ int update_reboot_param_file(const char *param) {
         return 0;
 }
 
-int take_password_lock(const char *root) {
-
-        struct flock flock = {
-                .l_type = F_WRLCK,
-                .l_whence = SEEK_SET,
-                .l_start = 0,
-                .l_len = 0,
-        };
-
-        const char *path;
-        int fd, r;
-
-        /* This is roughly the same as lckpwdf(), but not as awful. We
-         * don't want to use alarm() and signals, hence we implement
-         * our own trivial version of this.
-         *
-         * Note that shadow-utils also takes per-database locks in
-         * addition to lckpwdf(). However, we don't given that they
-         * are redundant as they they invoke lckpwdf() first and keep
-         * it during everything they do. The per-database locks are
-         * awfully racy, and thus we just won't do them. */
-
-        if (root)
-                path = strjoina(root, "/etc/.pwd.lock");
-        else
-                path = "/etc/.pwd.lock";
-
-        fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
-        if (fd < 0)
-                return -errno;
-
-        r = fcntl(fd, F_SETLKW, &flock);
-        if (r < 0) {
-                safe_close(fd);
-                return -errno;
-        }
-
-        return fd;
-}
-
 int is_symlink(const char *path) {
         struct stat info;
 
index f96b493d9d00211ae1d86bdbeb75e710c3e85c50..76d0784d3627a2becfbaf5956b2d6ce3f667c724 100644 (file)
@@ -519,8 +519,6 @@ union file_handle_union {
 
 int update_reboot_param_file(const char *param);
 
-int take_password_lock(const char *root);
-
 int is_symlink(const char *path);
 int is_dir(const char *path, bool follow);
 int is_device_node(const char *path);
index abb5e77966aa69d47eb5463bd86054b1697fb28a..564bd50f9bd7eee0e05aaf523f5b386bcd4a38d4 100644 (file)
@@ -38,6 +38,7 @@
 #include "strv.h"
 #include "terminal-util.h"
 #include "time-util.h"
+#include "user-util.h"
 
 static char *arg_root = NULL;
 static char *arg_locale = NULL;  /* $LANG */
@@ -536,7 +537,7 @@ static int process_root_password(void) {
 
         mkdir_parents(etc_shadow, 0755);
 
-        lock = take_password_lock(arg_root);
+        lock = take_etc_passwd_lock(arg_root);
         if (lock < 0)
                 return lock;
 
index 177432bf9ff2dfa8dcfa31805c1729121e1ef66d..5d2cbe1225672865f2308432db969408d4d9a18a 100644 (file)
@@ -1859,7 +1859,7 @@ int main(int argc, char *argv[]) {
         if (r < 0)
                 goto finish;
 
-        lock = take_password_lock(arg_root);
+        lock = take_etc_passwd_lock(arg_root);
         if (lock < 0) {
                 log_error_errno(lock, "Failed to take lock: %m");
                 goto finish;