duplicate definition of `fsetxattr` on static
There is an explicit definition of fsetxattr in src/test/file_caps_test.c:
https://github.com/stevegrubb/libcap-ng/blob/3bf765b0132cb9237e0f240bcf6e7ce9a608f4e8/src/test/file_caps_test.c#L127-L143
In static builds, this collides with fsetxattr in <sys/xattr.h> as reported downstream in https://github.com/NixOS/nixpkgs/pull/555423#issuecomment-5649811155 / https://github.com/NixOS/nixpkgs/issues/562705.
relevant build log excerpt
make[3]: Entering directory '/build/source/src/test'
x86_64-unknown-linux-musl-gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -g -O2 -c -o lib_test.o lib_test.c
x86_64-unknown-linux-musl-gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -g -O2 -c -o thread_test.o thread_test.c
x86_64-unknown-linux-musl-gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -g -O2 -c -o change_id_test.o change_id_test.c
x86_64-unknown-linux-musl-gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -g -O2 -c -o file_caps_test.o file_caps_test.c
x86_64-unknown-linux-musl-gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -g -O2 -c -o securebits_test.o securebits_test.c
/nix/store/byi2zpy2bgcf3dr6y0l8m50rmjj8z7q1-bash-5.3p15/bin/bash ../../libtool --tag=CC --mode=link x86_64-unknown-linux-musl-gcc -g -O2 -o thread_test thread_test.o ../../src/libcap-ng.la -lpthread
/nix/store/byi2zpy2bgcf3dr6y0l8m50rmjj8z7q1-bash-5.3p15/bin/bash ../../libtool --tag=CC --mode=link x86_64-unknown-linux-musl-gcc -g -O2 -o securebits_test securebits_test.o ../../src/libcap-ng.la
/nix/store/byi2zpy2bgcf3dr6y0l8m50rmjj8z7q1-bash-5.3p15/bin/bash ../../libtool --tag=CC --mode=link x86_64-unknown-linux-musl-gcc -g -O2 -o file_caps_test file_caps_test.o ../../src/libcap-ng.la
libtool: link: x86_64-unknown-linux-musl-gcc -g -O2 -o thread_test thread_test.o ../../src/.libs/libcap-ng.a -lpthread
libtool: link: x86_64-unknown-linux-musl-gcc -g -O2 -o securebits_test securebits_test.o ../../src/.libs/libcap-ng.a
/nix/store/byi2zpy2bgcf3dr6y0l8m50rmjj8z7q1-bash-5.3p15/bin/bash ../../libtool --tag=CC --mode=link x86_64-unknown-linux-musl-gcc -g -O2 -o lib_test lib_test.o ../../src/libcap-ng.la
libtool: link: x86_64-unknown-linux-musl-gcc -g -O2 -o file_caps_test file_caps_test.o ../../src/.libs/libcap-ng.a
/nix/store/ri6cwisd7vqmq148xhag76cvjj3wm5pf-x86_64-unknown-linux-musl-binutils-2.46/bin/x86_64-unknown-linux-musl-ld.bfd: /nix/store/mcif7qfgzvjafzxyznaxpk1aq7hk6dxg-musl-static-x86_64-unknown-linux-musl-1.2.6/lib/libc.a(xattr.lo): in function `fgetxattr':
(.text.fgetxattr+0x0): multiple definition of `fgetxattr'; file_caps_test.o:/build/source/src/test/file_caps_test.c:78: first defined here
/nix/store/ri6cwisd7vqmq148xhag76cvjj3wm5pf-x86_64-unknown-linux-musl-binutils-2.46/bin/x86_64-unknown-linux-musl-ld.bfd: /nix/store/mcif7qfgzvjafzxyznaxpk1aq7hk6dxg-musl-static-x86_64-unknown-linux-musl-1.2.6/lib/libc.a(xattr.lo): in function `fsetxattr':
(.text.fsetxattr+0x0): multiple definition of `fsetxattr'; file_caps_test.o:/build/source/src/test/file_caps_test.c:129: first defined here
libtool: link: x86_64-unknown-linux-musl-gcc -g -O2 -o lib_test lib_test.o ../../src/.libs/libcap-ng.a
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:634: file_caps_test] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/build/source/src/test'
make[2]: *** [Makefile:995: check-am] Error 2
make[2]: Leaving directory '/build/source/src/test'
make[1]: *** [Makefile:622: check-recursive] Error 1
make[1]: Leaving directory '/build/source/src'
make: *** [Makefile:466: check-recursive] Error 1
This is likely because we build and run the tests on static, not just the package. We do not do this in CI, but occasionally someone tries from source and finds these obscure issues.
I believe the correct fix would be to delete fsetxattr in src/test/file_caps_test.c and instead rely on fsetxattr in <sys/xattr.h> for the tests, as is already being done in src/cap-ng.c:
https://github.com/stevegrubb/libcap-ng/blob/3bf765b0132cb9237e0f240bcf6e7ce9a608f4e8/src/cap-ng.c#L1161
I am slightly surprised this doesn't blow up on dynamic linking, only static, but whatever.
Thanks for the report. Commit ef1b349 should resolve this. We can't pull in the definition from xattr.h because that will create conflicts in other tests. We don't have permission to run actual xattr diagnostics so it is mocked for testing. While testing on musl-c, I found another unrelated problem and commit b346f99 addresses it. There will probably be a new release in 2 - 3 weeks, so you may not need to carry a patch for long. Let me know if anything else pops up.
Thank you for the quick fix, this seems to work now :)