summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-16 18:57:04 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-09-17 09:54:41 +0200
commitee3455cf11acbfccc3df201f1feea674fc91f77d (patch)
treec288d42f0bdfad3d6a73815e4223538363b6ec13
parentman: explicitly document that "reboot -f" is different from "systemctl reboot... (diff)
downloadsystemd-ee3455cf11acbfccc3df201f1feea674fc91f77d.tar.xz
systemd-ee3455cf11acbfccc3df201f1feea674fc91f77d.zip
fd-util: rename CLOSE_AND_REPLACE() -> close_and_replace()
We have free_and_replace() and friends, they are all named with lower letters, even they are macros, not functions. For consistency, let's rename CLOSE_AND_REPLACE() with lower letters. This also mekes the macro used more places.
-rw-r--r--src/basic/chase-symlinks.c6
-rw-r--r--src/basic/fd-util.c2
-rw-r--r--src/basic/fd-util.h2
-rw-r--r--src/core/execute.c2
-rw-r--r--src/home/homed-home.c3
-rw-r--r--src/import/import-raw.c2
-rw-r--r--src/import/pull-raw.c2
-rw-r--r--src/libsystemd-network/sd-ipv4acd.c2
-rw-r--r--src/login/logind-session-device.c2
-rw-r--r--src/shared/data-fd-util.c2
-rw-r--r--src/tmpfiles/tmpfiles.c2
11 files changed, 12 insertions, 15 deletions
diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c
index ce50ff9726..e889b22f47 100644
--- a/src/basic/chase-symlinks.c
+++ b/src/basic/chase-symlinks.c
@@ -265,8 +265,7 @@ int chase_symlinks(
previous_stat = st;
}
- safe_close(fd);
- fd = TAKE_FD(fd_parent);
+ close_and_replace(fd, fd_parent);
continue;
}
@@ -362,8 +361,7 @@ int chase_symlinks(
return -ENOMEM;
/* And iterate again, but go one directory further down. */
- safe_close(fd);
- fd = TAKE_FD(child);
+ close_and_replace(fd, child);
}
if (ret_path)
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index 00591d6c2d..6c85a34896 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -654,7 +654,7 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
goto finish;
}
- CLOSE_AND_REPLACE(null_fd, copy);
+ close_and_replace(null_fd, copy);
}
}
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h
index 808cac4d5d..8543d0d5ea 100644
--- a/src/basic/fd-util.h
+++ b/src/basic/fd-util.h
@@ -98,7 +98,7 @@ static inline int make_null_stdio(void) {
})
/* Like free_and_replace(), but for file descriptors */
-#define CLOSE_AND_REPLACE(a, b) \
+#define close_and_replace(a, b) \
({ \
int *_fdp_ = &(a); \
safe_close(*_fdp_); \
diff --git a/src/core/execute.c b/src/core/execute.c
index e9443500ac..6a4e1e0954 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -4073,7 +4073,7 @@ static int add_shifted_fd(int *fds, size_t fds_size, size_t *n_fds, int fd, int
if (r < 0)
return -errno;
- CLOSE_AND_REPLACE(fd, r);
+ close_and_replace(fd, r);
}
*ret_fd = fds[*n_fds] = fd;
diff --git a/src/home/homed-home.c b/src/home/homed-home.c
index 47dc16d83f..19be186400 100644
--- a/src/home/homed-home.c
+++ b/src/home/homed-home.c
@@ -2041,8 +2041,7 @@ void home_process_notify(Home *h, char **l, int fd) {
if (taken_fd < 0)
return (void) log_debug("Got notify message with SYSTEMD_LUKS_LOCK_FD=1 but no fd passed, ignoring: %m");
- safe_close(h->luks_lock_fd);
- h->luks_lock_fd = TAKE_FD(taken_fd);
+ close_and_replace(h->luks_lock_fd, taken_fd);
log_debug("Successfully acquired LUKS lock fd from worker.");
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index 0faa58acf5..30f5b9050b 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -195,7 +195,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
unlink_and_free(i->temp_path);
i->temp_path = TAKE_PTR(t);
- CLOSE_AND_REPLACE(i->output_fd, converted_fd);
+ close_and_replace(i->output_fd, converted_fd);
return 1;
}
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index 0623afcc84..f4f869d38e 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -280,7 +280,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
unlink_and_free(i->temp_path);
i->temp_path = TAKE_PTR(t);
- CLOSE_AND_REPLACE(i->raw_job->disk_fd, converted_fd);
+ close_and_replace(i->raw_job->disk_fd, converted_fd);
return 1;
}
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c
index 673783b2b3..9b11b2f160 100644
--- a/src/libsystemd-network/sd-ipv4acd.c
+++ b/src/libsystemd-network/sd-ipv4acd.c
@@ -583,7 +583,7 @@ int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts) {
if (r < 0)
return r;
- CLOSE_AND_REPLACE(acd->fd, r);
+ close_and_replace(acd->fd, r);
if (reset_conflicts)
acd->n_conflict = 0;
diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c
index dc6a0d5407..acf0f20d85 100644
--- a/src/login/logind-session-device.c
+++ b/src/login/logind-session-device.c
@@ -188,7 +188,7 @@ static int session_device_start(SessionDevice *sd) {
/* For evdev devices, the file descriptor might be left uninitialized. This might happen while resuming
* into a session and logind has been restarted right before. */
- CLOSE_AND_REPLACE(sd->fd, r);
+ close_and_replace(sd->fd, r);
break;
case DEVICE_TYPE_UNKNOWN:
diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c
index 6ae3f11535..b6eb3d9f41 100644
--- a/src/shared/data-fd-util.c
+++ b/src/shared/data-fd-util.c
@@ -298,7 +298,7 @@ int copy_data_fd(int fd) {
if (f != 0)
return -errno;
- CLOSE_AND_REPLACE(copy_fd, tmp_fd);
+ close_and_replace(copy_fd, tmp_fd);
remains = mfree(remains);
remains_size = 0;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index ac6c5993e3..d27dc39a1c 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -2184,7 +2184,7 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
return log_error_errno(r, "Failed to stat \"%s\" at \"%s\": %m", t, strnull(parent_name));
}
- CLOSE_AND_REPLACE(parent_fd, next_fd);
+ close_and_replace(parent_fd, next_fd);
}
}