diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-06-13 13:19:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 13:19:02 +0200 |
commit | 39b5f49f2848c5b8c212773ac14a2c0adacd0a24 (patch) | |
tree | 6885767c739616e1095212fc03a0877e57c3055b /src/portable/portable.c | |
parent | Merge pull request #28017 from poettering/link-tmpfile-flags (diff) | |
parent | portable: make sure to fsync after extracting/copying (diff) | |
download | systemd-39b5f49f2848c5b8c212773ac14a2c0adacd0a24.tar.xz systemd-39b5f49f2848c5b8c212773ac14a2c0adacd0a24.zip |
Merge pull request #28014 from bluca/portable_fixes
portabled fixes
Diffstat (limited to 'src/portable/portable.c')
-rw-r--r-- | src/portable/portable.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c index 7d1fc87a91..52b8a5ba83 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -255,6 +255,7 @@ static int extract_now( _cleanup_(portable_metadata_unrefp) PortableMetadata *m = NULL; _cleanup_(mac_selinux_freep) char *con = NULL; _cleanup_close_ int fd = -EBADF; + struct stat st; if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY)) continue; @@ -275,6 +276,17 @@ static int extract_now( continue; } + /* Reject empty files, just in case */ + if (fstat(fd, &st) < 0) { + log_debug_errno(errno, "Failed to stat unit file '%s', ignoring: %m", de->d_name); + continue; + } + + if (st.st_size <= 0) { + log_debug("Unit file '%s' is empty, ignoring.", de->d_name); + continue; + } + #if HAVE_SELINUX /* The units will be copied on the host's filesystem, so if they had a SELinux label * we have to preserve it. Copy it out so that it can be applied later. */ @@ -1130,7 +1142,7 @@ static int install_chroot_dropin( } } - r = write_string_file(dropin, text, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC); + r = write_string_file(dropin, text, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_SYNC); if (r < 0) return log_debug_errno(r, "Failed to write '%s': %m", dropin); @@ -1177,7 +1189,7 @@ static int install_profile_dropin( if (flags & PORTABLE_PREFER_COPY) { - r = copy_file_atomic(from, dropin, 0644, COPY_REFLINK); + r = copy_file_atomic(from, dropin, 0644, COPY_REFLINK|COPY_FSYNC); if (r < 0) return log_debug_errno(r, "Failed to copy %s %s %s: %m", from, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), dropin); |