From: Daan De Meyer Date: Tue, 14 Mar 2023 15:30:46 +0000 (+0100) Subject: copy: Move chattr arguments to full function signatures X-Git-Tag: v254-rc1~959^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c2f5495e27283c757a5eb544af7654c8f60e50d;p=thirdparty%2Fsystemd.git copy: Move chattr arguments to full function signatures These are almost never used, so let's move them to the _full() functions signatures. --- diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index 7662bf1827d..56bc3627767 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -2753,7 +2753,7 @@ static int offline_security_checks( profile = profile_path; } - r = copy_file(profile, dropin, 0, 0644, 0, 0, 0); + r = copy_file(profile, dropin, 0, 0644, 0); if (r < 0) return log_error_errno(r, "Failed to copy: %m"); } diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 98d48f62766..3b463f2ac77 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -40,7 +40,7 @@ static int process_aliases(char *argv[], char *tempdir, char ***ret) { if (!dst) return -ENOMEM; - r = copy_file(src, dst, 0, 0644, 0, 0, COPY_REFLINK); + r = copy_file(src, dst, 0, 0644, COPY_REFLINK); if (r < 0) return r; diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 5eaaff7d841..8f3e6a12651 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -325,7 +325,7 @@ static int process_locale(void) { if (arg_copy_locale && arg_root) { (void) mkdir_parents(etc_localeconf, 0755); - r = copy_file("/etc/locale.conf", etc_localeconf, 0, 0644, 0, 0, COPY_REFLINK); + r = copy_file("/etc/locale.conf", etc_localeconf, 0, 0644, COPY_REFLINK); if (r != -ENOENT) { if (r < 0) return log_error_errno(r, "Failed to copy %s: %m", etc_localeconf); @@ -405,7 +405,7 @@ static int process_keymap(void) { if (arg_copy_keymap && arg_root) { (void) mkdir_parents(etc_vconsoleconf, 0755); - r = copy_file("/etc/vconsole.conf", etc_vconsoleconf, 0, 0644, 0, 0, COPY_REFLINK); + r = copy_file("/etc/vconsole.conf", etc_vconsoleconf, 0, 0644, COPY_REFLINK); if (r != -ENOENT) { if (r < 0) return log_error_errno(r, "Failed to copy %s: %m", etc_vconsoleconf); diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 8a152d0f6f4..3befa96a042 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -327,7 +327,6 @@ static int raw_pull_copy_auxiliary_file( *path, local, 0644, - 0, 0, COPY_REFLINK | (FLAGS_SET(i->flags, PULL_FORCE) ? COPY_REPLACE : 0) | (FLAGS_SET(i->flags, PULL_SYNC) ? COPY_FSYNC_FULL : 0)); diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index d3a1179ebc7..f22eb0e3a33 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -275,7 +275,6 @@ static int tar_pull_make_local_copy(TarPull *i) { i->settings_path, local_settings, 0664, - 0, 0, COPY_REFLINK | (FLAGS_SET(i->flags, PULL_FORCE) ? COPY_REPLACE : 0) | (FLAGS_SET(i->flags, PULL_SYNC) ? COPY_FSYNC_FULL : 0)); diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c index 538d999de0a..37d41f0678e 100644 --- a/src/journal/managed-journal-file.c +++ b/src/journal/managed-journal-file.c @@ -222,10 +222,11 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) { log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->file->path); - r = copy_file_atomic(FORMAT_PROC_FD_PATH(f->file->fd), f->file->path, f->file->mode, - 0, - FS_NOCOW_FL, - COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS); + r = copy_file_atomic_full(FORMAT_PROC_FD_PATH(f->file->fd), f->file->path, f->file->mode, + 0, + FS_NOCOW_FL, + COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS, + NULL, NULL); if (r < 0) { log_debug_errno(r, "Failed to rewrite %s: %m", f->file->path); continue; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 7122902aa02..056fad005d3 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2034,7 +2034,7 @@ static int setup_timezone(const char *dest) { case TIMEZONE_COPY: /* If mounting failed, try to copy */ - r = copy_file_atomic("/etc/localtime", where, 0644, 0, 0, COPY_REFLINK|COPY_REPLACE); + r = copy_file_atomic("/etc/localtime", where, 0644, COPY_REFLINK|COPY_REPLACE); if (r < 0) { log_full_errno(IN_SET(r, -EROFS, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r, "Failed to copy /etc/localtime to %s, ignoring: %m", where); @@ -2168,9 +2168,9 @@ static int setup_resolv_conf(const char *dest) { } if (IN_SET(m, RESOLV_CONF_REPLACE_HOST, RESOLV_CONF_REPLACE_STATIC, RESOLV_CONF_REPLACE_UPLINK, RESOLV_CONF_REPLACE_STUB)) - r = copy_file_atomic(what, where, 0644, 0, 0, COPY_REFLINK|COPY_REPLACE); + r = copy_file_atomic(what, where, 0644, COPY_REFLINK|COPY_REPLACE); else - r = copy_file(what, where, O_TRUNC|O_NOFOLLOW, 0644, 0, 0, COPY_REFLINK); + r = copy_file(what, where, O_TRUNC|O_NOFOLLOW, 0644, COPY_REFLINK); if (r < 0) { /* If the file already exists as symlink, let's suppress the warning, under the assumption that * resolved or something similar runs inside and the symlink points there. @@ -5697,7 +5697,10 @@ static int run(int argc, char *argv[]) { { BLOCK_SIGNALS(SIGINT); - r = copy_file(arg_image, np, O_EXCL, arg_read_only ? 0400 : 0600, FS_NOCOW_FL, FS_NOCOW_FL, COPY_REFLINK|COPY_CRTIME|COPY_SIGINT); + r = copy_file_full(arg_image, np, O_EXCL, arg_read_only ? 0400 : 0600, + FS_NOCOW_FL, FS_NOCOW_FL, + COPY_REFLINK|COPY_CRTIME|COPY_SIGINT, + NULL, NULL); } if (r == -EINTR) { log_error_errno(r, "Interrupted while copying image file to %s, removed again.", np); diff --git a/src/portable/portable.c b/src/portable/portable.c index 7b0ee97c8c3..23102e51ddf 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -1072,7 +1072,7 @@ static int install_profile_dropin( if (flags & PORTABLE_PREFER_COPY) { - r = copy_file_atomic(from, dropin, 0644, 0, 0, COPY_REFLINK); + r = copy_file_atomic(from, dropin, 0644, COPY_REFLINK); if (r < 0) return log_debug_errno(r, "Failed to copy %s %s %s: %m", from, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), dropin); diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index fa6d6ec0e9c..815503c6e7f 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -152,7 +152,7 @@ static int move_file(PStoreEntry *pe, const char *subdir1, const char *subdir2) r = mkdir_parents(ofd_path, 0755); if (r < 0) return log_error_errno(r, "Failed to create directory %s: %m", ofd_path); - r = copy_file_atomic(ifd_path, ofd_path, 0600, 0, 0, COPY_REPLACE); + r = copy_file_atomic(ifd_path, ofd_path, 0600, COPY_REPLACE); if (r < 0) return log_error_errno(r, "Failed to copy_file_atomic: %s to %s", ifd_path, ofd_path); } diff --git a/src/shared/copy.h b/src/shared/copy.h index ab2e256915c..ec65959aefd 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -47,19 +47,19 @@ static inline int copy_file_fd(const char *from, int to, CopyFlags copy_flags) { } int copy_file_at_full(int dir_fdf, const char *from, int dir_fdt, const char *to, int open_flags, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags, copy_progress_bytes_t progress, void *userdata); -static inline int copy_file_at(int dir_fdf, const char *from, int dir_fdt, const char *to, int open_flags, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags) { - return copy_file_at_full(dir_fdf, from, dir_fdt, to, open_flags, mode, chattr_flags, chattr_mask, copy_flags, NULL, NULL); +static inline int copy_file_at(int dir_fdf, const char *from, int dir_fdt, const char *to, int open_flags, mode_t mode, CopyFlags copy_flags) { + return copy_file_at_full(dir_fdf, from, dir_fdt, to, open_flags, mode, 0, 0, copy_flags, NULL, NULL); } static inline int copy_file_full(const char *from, const char *to, int open_flags, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags, copy_progress_bytes_t progress, void *userdata) { return copy_file_at_full(AT_FDCWD, from, AT_FDCWD, to, open_flags, mode, chattr_flags, chattr_mask, copy_flags, progress, userdata); } -static inline int copy_file(const char *from, const char *to, int open_flags, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags) { - return copy_file_at(AT_FDCWD, from, AT_FDCWD, to, open_flags, mode, chattr_flags, chattr_mask, copy_flags); +static inline int copy_file(const char *from, const char *to, int open_flags, mode_t mode, CopyFlags copy_flags) { + return copy_file_at(AT_FDCWD, from, AT_FDCWD, to, open_flags, mode, copy_flags); } int copy_file_atomic_full(const char *from, const char *to, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags, copy_progress_bytes_t progress, void *userdata); -static inline int copy_file_atomic(const char *from, const char *to, mode_t mode, unsigned chattr_flags, unsigned chattr_mask, CopyFlags copy_flags) { - return copy_file_atomic_full(from, to, mode, chattr_flags, chattr_mask, copy_flags, NULL, NULL); +static inline int copy_file_atomic(const char *from, const char *to, mode_t mode, CopyFlags copy_flags) { + return copy_file_atomic_full(from, to, mode, 0, 0, copy_flags, NULL, NULL); } int copy_tree_at_full(int fdf, const char *from, int fdt, const char *to, uid_t override_uid, gid_t override_gid, CopyFlags copy_flags, Hashmap *denylist, copy_progress_path_t progress_path, copy_progress_bytes_t progress_bytes, void *userdata); diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index 17a3ac679af..1f5b11f5f40 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -850,7 +850,7 @@ static int clone_auxiliary_file(const char *path, const char *new_name, const ch if (r < 0) return r; - return copy_file_atomic(path, rs, 0664, 0, 0, COPY_REFLINK); + return copy_file_atomic(path, rs, 0664, COPY_REFLINK); } int image_clone(Image *i, const char *new_name, bool read_only) { @@ -911,7 +911,8 @@ int image_clone(Image *i, const char *new_name, bool read_only) { case IMAGE_RAW: new_path = strjoina("/var/lib/machines/", new_name, ".raw"); - r = copy_file_atomic(i->path, new_path, read_only ? 0444 : 0644, FS_NOCOW_FL, FS_NOCOW_FL, COPY_REFLINK|COPY_CRTIME); + r = copy_file_atomic_full(i->path, new_path, read_only ? 0444 : 0644, FS_NOCOW_FL, FS_NOCOW_FL, + COPY_REFLINK|COPY_CRTIME, NULL, NULL); break; case IMAGE_BLOCK: diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index 58cd7fe9f3d..b59f1295288 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -138,7 +138,7 @@ static int create_edit_temp_file(EditFile *e) { if (r < 0) return r; - r = copy_file(e->original_path, temp, 0, 0644, 0, 0, COPY_REFLINK); + r = copy_file(e->original_path, temp, 0, 0644, COPY_REFLINK); if (r == -ENOENT) { r = touch(temp); mac_selinux_create_file_clear(); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index a2b2b34d984..d3f37ea9e39 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -39,7 +39,7 @@ TEST(copy_file) { assert_se(write_string_file(fn, "foo bar bar bar foo", WRITE_STRING_FILE_CREATE) == 0); - assert_se(copy_file(fn, fn_copy, 0, 0644, 0, 0, COPY_REFLINK) == 0); + assert_se(copy_file(fn, fn_copy, 0, 0644, COPY_REFLINK) == 0); assert_se(read_full_file(fn_copy, &buf, &sz) == 0); assert_se(streq(buf, "foo bar bar bar foo\n")); @@ -366,13 +366,13 @@ TEST(copy_atomic) { q = strjoina(p, "/fstab"); - r = copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REFLINK); + r = copy_file_atomic("/etc/fstab", q, 0644, COPY_REFLINK); if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) return; - assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REFLINK) == -EEXIST); + assert_se(copy_file_atomic("/etc/fstab", q, 0644, COPY_REFLINK) == -EEXIST); - assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REPLACE) >= 0); + assert_se(copy_file_atomic("/etc/fstab", q, 0644, COPY_REPLACE) >= 0); } TEST(copy_proc) { @@ -383,7 +383,7 @@ TEST(copy_proc) { assert_se(mkdtemp_malloc(NULL, &p) >= 0); assert_se(f = path_join(p, "version")); - assert_se(copy_file("/proc/version", f, 0, MODE_INVALID, 0, 0, 0) >= 0); + assert_se(copy_file("/proc/version", f, 0, MODE_INVALID, 0) >= 0); assert_se(read_one_line_file("/proc/version", &a) >= 0); assert_se(read_one_line_file(f, &b) >= 0); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 0c96f28aa96..fc6eba9fcaf 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -283,7 +283,7 @@ static void test_exec_workingdirectory(Manager *m) { static void test_exec_execsearchpath(Manager *m) { assert_se(mkdir_p("/tmp/test-exec_execsearchpath", 0755) >= 0); - assert_se(copy_file("/bin/ls", "/tmp/test-exec_execsearchpath/ls_temp", 0, 0777, 0, 0, COPY_REPLACE) >= 0); + assert_se(copy_file("/bin/ls", "/tmp/test-exec_execsearchpath/ls_temp", 0, 0777, COPY_REPLACE) >= 0); test(m, "exec-execsearchpath.service", 0, CLD_EXITED); diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index ce61f28017a..f115a40188f 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -997,7 +997,7 @@ TEST(conservative_rename) { assert_se(access(q, F_OK) < 0 && errno == ENOENT); /* Check that a manual copy is detected */ - assert_se(copy_file(p, q, 0, MODE_INVALID, 0, 0, COPY_REFLINK) >= 0); + assert_se(copy_file(p, q, 0, MODE_INVALID, COPY_REFLINK) >= 0); assert_se(conservative_renameat(AT_FDCWD, q, AT_FDCWD, p) == 0); assert_se(access(q, F_OK) < 0 && errno == ENOENT);