mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
Add CLOSE_AND_REPLACE helper
Similar to free_and_replace. I think this should be uppercase to make it clear that this is a macro. free_and_replace should probably be uppercased too.
This commit is contained in:
parent
831d57953e
commit
0706c01259
@ -731,8 +731,7 @@ int fd_duplicate_data_fd(int fd) {
|
|||||||
if (f != 0)
|
if (f != 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
safe_close(copy_fd);
|
CLOSE_AND_REPLACE(copy_fd, tmp_fd);
|
||||||
copy_fd = TAKE_FD(tmp_fd);
|
|
||||||
|
|
||||||
remains = mfree(remains);
|
remains = mfree(remains);
|
||||||
remains_size = 0;
|
remains_size = 0;
|
||||||
@ -865,8 +864,7 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_close(null_fd);
|
CLOSE_AND_REPLACE(null_fd, copy);
|
||||||
null_fd = copy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,16 @@ static inline int make_null_stdio(void) {
|
|||||||
_fd_; \
|
_fd_; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* Like free_and_replace(), but for file descriptors */
|
||||||
|
#define CLOSE_AND_REPLACE(a, b) \
|
||||||
|
({ \
|
||||||
|
int *_fdp_ = &(a); \
|
||||||
|
safe_close(*_fdp_); \
|
||||||
|
*_fdp_ = TAKE_FD(b); \
|
||||||
|
0; \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
int fd_reopen(int fd, int flags);
|
int fd_reopen(int fd, int flags);
|
||||||
|
|
||||||
int read_nr_open(void);
|
int read_nr_open(void);
|
||||||
|
@ -4217,8 +4217,7 @@ static int exec_child(
|
|||||||
return log_unit_error_errno(unit, errno, "Couldn't move exec fd up: %m");
|
return log_unit_error_errno(unit, errno, "Couldn't move exec fd up: %m");
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_close(exec_fd);
|
CLOSE_AND_REPLACE(exec_fd, moved_fd);
|
||||||
exec_fd = moved_fd;
|
|
||||||
} else {
|
} else {
|
||||||
/* This fd should be FD_CLOEXEC already, but let's make sure. */
|
/* This fd should be FD_CLOEXEC already, but let's make sure. */
|
||||||
r = fd_cloexec(exec_fd, true);
|
r = fd_cloexec(exec_fd, true);
|
||||||
|
@ -185,9 +185,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
|
|||||||
|
|
||||||
(void) unlink(i->temp_path);
|
(void) unlink(i->temp_path);
|
||||||
free_and_replace(i->temp_path, t);
|
free_and_replace(i->temp_path, t);
|
||||||
|
CLOSE_AND_REPLACE(i->output_fd, converted_fd);
|
||||||
safe_close(i->output_fd);
|
|
||||||
i->output_fd = TAKE_FD(converted_fd);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -253,9 +253,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
|
|||||||
|
|
||||||
(void) unlink(i->temp_path);
|
(void) unlink(i->temp_path);
|
||||||
free_and_replace(i->temp_path, t);
|
free_and_replace(i->temp_path, t);
|
||||||
|
CLOSE_AND_REPLACE(i->raw_job->disk_fd, converted_fd);
|
||||||
safe_close(i->raw_job->disk_fd);
|
|
||||||
i->raw_job->disk_fd = TAKE_FD(converted_fd);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -471,8 +471,7 @@ int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
safe_close(acd->fd);
|
CLOSE_AND_REPLACE(acd->fd, r);
|
||||||
acd->fd = r;
|
|
||||||
acd->defend_window = 0;
|
acd->defend_window = 0;
|
||||||
|
|
||||||
if (reset_conflicts)
|
if (reset_conflicts)
|
||||||
|
@ -195,8 +195,7 @@ static int session_device_start(SessionDevice *sd) {
|
|||||||
|
|
||||||
/* For evdev devices, the file descriptor might be left uninitialized. This might happen while resuming
|
/* 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. */
|
* into a session and logind has been restarted right before. */
|
||||||
safe_close(sd->fd);
|
CLOSE_AND_REPLACE(sd->fd, r);
|
||||||
sd->fd = r;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVICE_TYPE_UNKNOWN:
|
case DEVICE_TYPE_UNKNOWN:
|
||||||
|
Loading…
Reference in New Issue
Block a user