fs-util: replace symlink_atomic() by symlinkat_atomic()

This commit is contained in:
Lennart Poettering
2022-09-23 09:22:36 +02:00
parent cc43328c7f
commit da9dd029a2
3 changed files with 9 additions and 8 deletions
+6 -5
View File
@@ -432,7 +432,7 @@ int symlink_idempotent(const char *from, const char *to, bool make_relative) {
return 0;
}
int symlink_atomic_full(const char *from, const char *to, bool make_relative) {
int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_relative) {
_cleanup_free_ char *relpath = NULL, *t = NULL;
int r;
@@ -451,12 +451,13 @@ int symlink_atomic_full(const char *from, const char *to, bool make_relative) {
if (r < 0)
return r;
if (symlink(from, t) < 0)
if (symlinkat(from, atfd, t) < 0)
return -errno;
if (rename(t, to) < 0) {
unlink_noerrno(t);
return -errno;
r = RET_NERRNO(renameat(atfd, t, atfd, to));
if (r < 0) {
(void) unlinkat(atfd, t, 0);
return r;
}
return 0;
+2 -2
View File
@@ -58,9 +58,9 @@ static inline int touch(const char *path) {
int symlink_idempotent(const char *from, const char *to, bool make_relative);
int symlink_atomic_full(const char *from, const char *to, bool make_relative);
int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_relative);
static inline int symlink_atomic(const char *from, const char *to) {
return symlink_atomic_full(from, to, false);
return symlinkat_atomic_full(from, AT_FDCWD, to, false);
}
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
int mkfifo_atomic(const char *path, mode_t mode);
+1 -1
View File
@@ -71,7 +71,7 @@ int symlink_atomic_full_label(const char *from, const char *to, bool make_relati
if (r < 0)
return r;
r = symlink_atomic_full(from, to, make_relative);
r = symlinkat_atomic_full(from, AT_FDCWD, to, make_relative);
mac_selinux_create_file_clear();
if (r < 0)