From: Daan De Meyer Date: Thu, 9 Mar 2023 11:28:31 +0000 (+0100) Subject: user-util: Use unposix_lock() in take_etc_passwd_lock() X-Git-Tag: v254-rc1~1066^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=460accdf3d681d9a5ccf4fc6356e73b6b323e72c;p=thirdparty%2Fsystemd.git user-util: Use unposix_lock() in take_etc_passwd_lock() --- diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 6c5041230a1..0a47947d348 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -18,6 +18,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "lock-util.h" #include "macro.h" #include "mkdir.h" #include "parse-util.h" @@ -671,12 +672,7 @@ int reset_uid_gid(void) { } 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, - }; + int 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. @@ -695,8 +691,9 @@ int take_etc_passwd_lock(const char *root) { if (fd < 0) return log_debug_errno(errno, "Cannot open %s: %m", path); - if (fcntl(fd, F_SETLKW, &flock) < 0) - return log_debug_errno(errno, "Locking %s failed: %m", path); + r = unposix_lock(fd, LOCK_EX); + if (r < 0) + return log_debug_errno(r, "Locking %s failed: %m", path); return TAKE_FD(fd); }