aboutsummaryrefslogtreecommitdiff
path: root/src/xz
diff options
context:
space:
mode:
authorAlexander Bluhm <alexander.bluhm@gmx.net>2021-10-05 23:33:16 +0200
committerLasse Collin <lasse.collin@tukaani.org>2021-10-27 20:49:41 +0300
commit892b16cc282f5b4e1c49871b326f4db25c5b4d81 (patch)
treecec88fc36db0d7959682bf95ada3548f2c085e68 /src/xz
parentliblzma: Fix liblzma.map for the lzma_microlzma_* symbols. (diff)
downloadxz-892b16cc282f5b4e1c49871b326f4db25c5b4d81.tar.xz
xz: Avoid fchown(2) failure.
OpenBSD does not allow to change the group of a file if the user does not belong to this group. In contrast to Linux, OpenBSD also fails if the new group is the same as the old one. Do not call fchown(2) in this case, it would change nothing anyway. This fixes an issue with Perl Alien::Build module. https://github.com/PerlAlien/Alien-Build/issues/62
Diffstat (limited to 'src/xz')
-rw-r--r--src/xz/file_io.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c
index 80b56d38..1602443e 100644
--- a/src/xz/file_io.c
+++ b/src/xz/file_io.c
@@ -368,7 +368,13 @@ io_copy_attrs(const file_pair *pair)
mode_t mode;
- if (fchown(pair->dest_fd, (uid_t)(-1), pair->src_st.st_gid)) {
+ // With BSD semantics the new dest file may have a group that
+ // does not belong to the user. If the src file has the same gid
+ // nothing has to be done. Nevertheless OpenBSD fchown(2) fails
+ // in this case which seems to be POSIX compliant. As there is
+ // nothing to do, skip the system call.
+ if (pair->dest_st.st_gid != pair->src_st.st_gid &&
+ fchown(pair->dest_fd, (uid_t)(-1), pair->src_st.st_gid)) {
message_warning(_("%s: Cannot set the file group: %s"),
pair->dest_name, strerror(errno));
// We can still safely copy some additional permissions: