1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

copy: simplify error paths when creating temporary files

This commit is contained in:
Lennart Poettering 2021-02-01 17:50:56 +01:00 committed by Yu Watanabe
parent e6283cbf48
commit e1aec57dd1

View File

@ -1147,24 +1147,24 @@ int copy_file_atomic_full(
* writing it. */
if (copy_flags & COPY_REPLACE) {
r = tempfn_random(to, NULL, &t);
_cleanup_free_ char *f = NULL;
r = tempfn_random(to, NULL, &f);
if (r < 0)
return r;
if (copy_flags & COPY_MAC_CREATE) {
r = mac_selinux_create_file_prepare(to, S_IFREG);
if (r < 0) {
t = mfree(t);
if (r < 0)
return r;
}
}
fdt = open(t, O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY|O_WRONLY|O_CLOEXEC, 0600);
fdt = open(f, O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY|O_WRONLY|O_CLOEXEC, 0600);
if (copy_flags & COPY_MAC_CREATE)
mac_selinux_create_file_clear();
if (fdt < 0) {
t = mfree(t);
if (fdt < 0)
return -errno;
}
t = TAKE_PTR(f);
} else {
if (copy_flags & COPY_MAC_CREATE) {
r = mac_selinux_create_file_prepare(to, S_IFREG);