mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-10 00:58:20 +03:00
basic/user-util: convert prefix_roota→path_join and use _cleanup_ more
This commit is contained in:
parent
fddb524d8a
commit
e5b30f7232
@ -670,7 +670,6 @@ int reset_uid_gid(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int take_etc_passwd_lock(const char *root) {
|
int take_etc_passwd_lock(const char *root) {
|
||||||
|
|
||||||
struct flock flock = {
|
struct flock flock = {
|
||||||
.l_type = F_WRLCK,
|
.l_type = F_WRLCK,
|
||||||
.l_whence = SEEK_SET,
|
.l_whence = SEEK_SET,
|
||||||
@ -678,9 +677,6 @@ int take_etc_passwd_lock(const char *root) {
|
|||||||
.l_len = 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,
|
/* 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.
|
* hence we implement our own trivial version of this.
|
||||||
*
|
*
|
||||||
@ -688,22 +684,18 @@ int take_etc_passwd_lock(const char *root) {
|
|||||||
* given that they are redundant: they invoke lckpwdf() first and keep it during everything they do.
|
* given that they are redundant: 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. */
|
* The per-database locks are awfully racy, and thus we just won't do them. */
|
||||||
|
|
||||||
if (root)
|
_cleanup_free_ char *path = path_join(root, ETC_PASSWD_LOCK_PATH);
|
||||||
path = prefix_roota(root, ETC_PASSWD_LOCK_PATH);
|
if (!path)
|
||||||
else
|
return log_oom_debug();
|
||||||
path = ETC_PASSWD_LOCK_PATH;
|
|
||||||
|
|
||||||
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
|
_cleanup_close_ int fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_debug_errno(errno, "Cannot open %s: %m", path);
|
return log_debug_errno(errno, "Cannot open %s: %m", path);
|
||||||
|
|
||||||
r = fcntl(fd, F_SETLKW, &flock);
|
if (fcntl(fd, F_SETLKW, &flock) < 0)
|
||||||
if (r < 0) {
|
|
||||||
safe_close(fd);
|
|
||||||
return log_debug_errno(errno, "Locking %s failed: %m", path);
|
return log_debug_errno(errno, "Locking %s failed: %m", path);
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
return TAKE_FD(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid_user_group_name(const char *u, ValidUserFlags flags) {
|
bool valid_user_group_name(const char *u, ValidUserFlags flags) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user