From: Daan De Meyer Date: Mon, 13 Feb 2023 20:51:11 +0000 (+0100) Subject: copy: Make copy_xattr() more generic X-Git-Tag: v254-rc1~1278^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c17cfe6ef7bc1ac4501b5f6e7d4f4efc08aef439;p=thirdparty%2Fsystemd.git copy: Make copy_xattr() more generic Let's make copy_xattr() a little more generic in preparation for copying symlink xattrs. --- diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index f435932815d..8d3d3712d7e 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -1105,7 +1105,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) { if (r < 0) return log_error_errno(r, "Failed to copy bytes from %s in mage '%s' to '%s': %m", arg_source, arg_image, arg_target); - (void) copy_xattr(source_fd, target_fd, 0); + (void) copy_xattr(source_fd, NULL, target_fd, NULL, 0); (void) copy_access(source_fd, target_fd); (void) copy_times(source_fd, target_fd, 0); @@ -1182,7 +1182,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) { if (r < 0) return log_error_errno(r, "Failed to copy bytes from '%s' to '%s' in image '%s': %m", arg_source, arg_target, arg_image); - (void) copy_xattr(source_fd, target_fd, 0); + (void) copy_xattr(source_fd, NULL, target_fd, NULL, 0); (void) copy_access(source_fd, target_fd); (void) copy_times(source_fd, target_fd, 0); diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 7c61aef3b68..44181fd9b2f 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -216,7 +216,7 @@ static int raw_export_process(RawExport *e) { finish: if (r >= 0) { (void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME); - (void) copy_xattr(e->input_fd, e->output_fd, 0); + (void) copy_xattr(e->input_fd, NULL, e->output_fd, NULL, 0); } if (e->on_finished) diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 5d4dedf66d6..3765b514bb3 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -234,7 +234,7 @@ static int raw_import_finish(RawImport *i) { if (S_ISREG(i->input_stat.st_mode)) { (void) copy_times(i->input_fd, i->output_fd, COPY_CRTIME); - (void) copy_xattr(i->input_fd, i->output_fd, 0); + (void) copy_xattr(i->input_fd, NULL, i->output_fd, NULL, 0); } } diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index a4a844bf072..8a152d0f6f4 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -396,7 +396,7 @@ static int raw_pull_make_local_copy(RawPull *i) { return log_error_errno(r, "Failed to make writable copy of image: %m"); (void) copy_times(i->raw_job->disk_fd, dfd, COPY_CRTIME); - (void) copy_xattr(i->raw_job->disk_fd, dfd, 0); + (void) copy_xattr(i->raw_job->disk_fd, NULL, dfd, NULL, 0); dfd = safe_close(dfd); diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c index 8f18ecd0d2f..d6b6593bea6 100644 --- a/src/locale/localed-util.c +++ b/src/locale/localed-util.c @@ -921,7 +921,7 @@ int locale_gen_enable_locale(const char *locale) { r = copy_access(fileno(fr), fileno(fw)); if (r < 0) return r; - r = copy_xattr(fileno(fr), fileno(fw), COPY_ALL_XATTRS); + r = copy_xattr(fileno(fr), NULL, fileno(fw), NULL, COPY_ALL_XATTRS); if (r < 0) log_debug_errno(r, "Failed to copy all xattrs from old to new /etc/locale.gen file, ignoring: %m"); } diff --git a/src/partition/repart.c b/src/partition/repart.c index 6ba48b528ec..43f25e7e59a 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -3840,7 +3840,7 @@ static int do_copy_files(Partition *p, const char *root, const Set *denylist) { if (r < 0) return log_error_errno(r, "Failed to copy '%s' to '%s%s': %m", *source, strempty(arg_root), *target); - (void) copy_xattr(sfd, tfd, COPY_ALL_XATTRS); + (void) copy_xattr(sfd, NULL, tfd, NULL, COPY_ALL_XATTRS); (void) copy_access(sfd, tfd); (void) copy_times(sfd, tfd, 0); } diff --git a/src/shared/copy.c b/src/shared/copy.c index 4eb4f9f765c..3e624d8844f 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -754,7 +754,7 @@ static int fd_copy_regular( r = -errno; (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim }); - (void) copy_xattr(fdf, fdt, copy_flags); + (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags); if (copy_flags & COPY_FSYNC) { if (fsync(fdt) < 0) { @@ -1058,7 +1058,7 @@ static int fd_copy_directory( if (fchmod(fdt, st->st_mode & 07777) < 0) r = -errno; - (void) copy_xattr(dirfd(d), fdt, copy_flags); + (void) copy_xattr(dirfd(d), NULL, fdt, NULL, copy_flags); (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim }); } @@ -1313,7 +1313,7 @@ int copy_file_fd_full( * mode/ownership of that device node...) */ if (S_ISREG(st.st_mode)) { (void) copy_times(fdf, fdt, copy_flags); - (void) copy_xattr(fdf, fdt, copy_flags); + (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags); } if (copy_flags & COPY_FSYNC_FULL) { @@ -1385,7 +1385,7 @@ int copy_file_full( goto fail; (void) copy_times(fdf, fdt, copy_flags); - (void) copy_xattr(fdf, fdt, copy_flags); + (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags); if (chattr_mask != 0) (void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL); @@ -1570,11 +1570,11 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht) { return fchmod_and_chown_with_fallback(fdt, patht, st.st_mode & 07777, st.st_uid, st.st_gid); } -int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) { +int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags) { _cleanup_free_ char *names = NULL; int ret = 0, r; - r = flistxattr_malloc(fdf, &names); + r = listxattr_at_malloc(df, from, 0, &names); if (r < 0) return r; @@ -1584,13 +1584,13 @@ int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) { if (!FLAGS_SET(copy_flags, COPY_ALL_XATTRS) && !startswith(p, "user.")) continue; - r = fgetxattr_malloc(fdf, p, &value); + r = getxattr_at_malloc(df, from, p, 0, &value); if (r == -ENODATA) continue; /* gone by now */ if (r < 0) return r; - if (fsetxattr(fdt, p, value, r, 0) < 0) + if (xsetxattr(dt, to, p, value, r, 0) < 0) ret = -errno; } diff --git a/src/shared/copy.h b/src/shared/copy.h index 1eb6d1ce053..22151ff83b0 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -77,4 +77,4 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht); static inline int copy_rights(int fdf, int fdt) { return copy_rights_with_fallback(fdf, fdt, NULL); /* no fallback */ } -int copy_xattr(int fdf, int fdt, CopyFlags copy_flags); +int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags);