summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-20 17:11:59 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-01-22 12:55:54 +0900
commit10195179bb663f000198543628b44ef8e51d71a7 (patch)
treebc367ca21a65f364a9c73a79b876c07c8bc28e2a /src
parent9092113d93f61d67605f7c4a824b65a56b33fa59 (diff)
downloadsystemd-10195179bb663f000198543628b44ef8e51d71a7.tar.gz
fs-util: rename conservative_rename() -> conservative_renameat()
And this introduces conservative_rename() which does not take dirfd.
Diffstat (limited to 'src')
-rw-r--r--src/basic/fs-util.c2
-rw-r--r--src/basic/fs-util.h5
-rw-r--r--src/resolve/resolved-resolv-conf.c4
-rw-r--r--src/test/test-fs-util.c14
4 files changed, 14 insertions, 11 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 7f44b93726..9290fd8784 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -1614,7 +1614,7 @@ int path_is_encrypted(const char *path) {
return blockdev_is_encrypted(p, 10 /* safety net: maximum recursion depth */);
}
-int conservative_rename(
+int conservative_renameat(
int olddirfd, const char *oldpath,
int newdirfd, const char *newpath) {
diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h
index 8bd8da1704..f036a19eb5 100644
--- a/src/basic/fs-util.h
+++ b/src/basic/fs-util.h
@@ -143,4 +143,7 @@ int open_parent(const char *path, int flags, mode_t mode);
int path_is_encrypted(const char *path);
-int conservative_rename(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
+int conservative_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
+static inline int conservative_rename(const char *oldpath, const char *newpath) {
+ return conservative_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
+}
diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c
index 029d5c93ed..2f06c9046f 100644
--- a/src/resolve/resolved-resolv-conf.c
+++ b/src/resolve/resolved-resolv-conf.c
@@ -360,7 +360,7 @@ int manager_write_resolv_conf(Manager *m) {
goto fail;
}
- r = conservative_rename(AT_FDCWD, temp_path_stub, AT_FDCWD, PRIVATE_STUB_RESOLV_CONF);
+ r = conservative_rename(temp_path_stub, PRIVATE_STUB_RESOLV_CONF);
if (r < 0)
log_error_errno(r, "Failed to move new %s into place: %m", PRIVATE_STUB_RESOLV_CONF);
@@ -370,7 +370,7 @@ int manager_write_resolv_conf(Manager *m) {
log_error_errno(r, "Failed to symlink %s: %m", PRIVATE_STUB_RESOLV_CONF);
}
- r = conservative_rename(AT_FDCWD, temp_path_uplink, AT_FDCWD, PRIVATE_UPLINK_RESOLV_CONF);
+ r = conservative_rename(temp_path_uplink, PRIVATE_UPLINK_RESOLV_CONF);
if (r < 0)
log_error_errno(r, "Failed to move new %s into place: %m", PRIVATE_UPLINK_RESOLV_CONF);
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index e0ef8257bd..f01b08b2eb 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -847,37 +847,37 @@ static void test_conservative_rename(void) {
/* Check that the hardlinked "copy" is detected */
assert_se(link(p, q) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) == 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Check that a manual copy is detected */
assert_se(copy_file(p, q, 0, (mode_t) -1, 0, 0, COPY_REFLINK) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) == 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Check that a manual new writeout is also detected */
assert_se(write_string_file(q, "this is a test", WRITE_STRING_FILE_CREATE) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) == 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Check that a minimally changed version is detected */
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) > 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Check that this really is new updated version */
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) == 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Make sure we detect extended files */
assert_se(write_string_file(q, "this is a_testx", WRITE_STRING_FILE_CREATE) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) > 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
/* Make sure we detect truncated files */
assert_se(write_string_file(q, "this is a_test", WRITE_STRING_FILE_CREATE) >= 0);
- assert_se(conservative_rename(AT_FDCWD, q, AT_FDCWD, p) > 0);
+ assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) > 0);
assert_se(access(q, F_OK) < 0 && errno == ENOENT);
}