-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow building on systems using musl C library #19513
Conversation
The musl C library for example only defines SIGCHLD and not SIGCLD: ``` [...] CC src/common/libcockpit_common_a-cockpitunixsignal.o src/common/cockpitunixsignal.c:76:17: error: use of undeclared identifier 'SIGCLD' { "CLD", SIGCLD }, /* same as SIGCHLD (mips) */ ^ ```
Building with the musl libc failed with the following error: ``` src/session/session-utils.c:180:14: error: use of undeclared identifier '_PATH_LASTLOG' fd = open (_PATH_LASTLOG, O_RDWR); ^ src/session/session-utils.c:183:34: error: use of undeclared identifier '_PATH_LASTLOG' warn ("failed to open %s", _PATH_LASTLOG); ^ src/session/session-utils.c:220:48: error: use of undeclared identifier '_PATH_LASTLOG' warn ("failed to pread() %s for uid %u", _PATH_LASTLOG, (unsigned) uid); ^ src/session/session-utils.c:227:14: error: use of undeclared identifier '_PATH_LASTLOG' _PATH_LASTLOG, (unsigned) uid, r, sizeof entry); ^ src/session/session-utils.c:261:49: error: use of undeclared identifier '_PATH_LASTLOG' warn ("failed to pwrite() %s for uid %u", _PATH_LASTLOG, (unsigned) uid); ^ src/session/session-utils.c:268:14: error: use of undeclared identifier '_PATH_LASTLOG' _PATH_LASTLOG, (unsigned) uid, r, sizeof entry); ^ ``` glibc and musl declare `_PATH_LASTLOG` in `<paths.h>`, include it to fix this error
On systems with musl C library the build of cockpit-bridge otherwise fails with a linker error: ``` [...] CCLD cockpit-bridge ld.lld: error: undefined symbol: fts_open >>> referenced by cockpitcgroupsamples.c:230 (/home/marv/devel/cockpit/src/bridge/cockpitcgroupsamples.c:230) >>> libcockpit_metrics_a-cockpitcgroupsamples.o:(notice_cgroups_in_hierarchy) in archive libcockpit-metrics.a ld.lld: error: undefined symbol: fts_read >>> referenced by cockpitcgroupsamples.c:233 (/home/marv/devel/cockpit/src/bridge/cockpitcgroupsamples.c:233) >>> libcockpit_metrics_a-cockpitcgroupsamples.o:(notice_cgroups_in_hierarchy) in archive libcockpit-metrics.a ld.lld: error: undefined symbol: fts_close >>> referenced by cockpitcgroupsamples.c:254 (/home/marv/devel/cockpit/src/bridge/cockpitcgroupsamples.c:254) >>> libcockpit_metrics_a-cockpitcgroupsamples.o:(notice_cgroups_in_hierarchy) in archive libcockpit-metrics.a ```
The build of `cockpit-tls` otherwise fails with a linker error on systems using the musl C library: ``` [...] CCLD cockpit-tls ld.lld: error: undefined symbol: argp_parse >>> referenced by main.c:103 (/home/marv/devel/cockpit/src/tls/main.c:103) >>> src/tls/main.o:(main) ld.lld: error: undefined symbol: argp_error >>> referenced by main.c:51 (/home/marv/devel/cockpit/src/tls/main.c:51) >>> src/tls/main.o:(arg_parse_int) clang-15: error: linker command failed with exit code 1 (use -v to see invocation) ```
musl warns about the latter being incorrect: ``` [...] CC src/session/session-utils.o In file included from src/session/session-utils.c:22: In file included from src/session/session-utils.h:36: /usr/x86_64-pc-linux-musl/include/sys/signal.h:1:2: warning: redirecting incorrect #include <sys/signal.h> to <signal.h> [-W#warnings] ``` and in glibc `<sys/signal.h>` is also just a wrapper for `<signal.h>`
musl libc warns about it: ``` In file included from src/tls/cockpit-certificate-ensure.c:32: /usr/x86_64-pc-linux-musl/include/sys/fcntl.h:1:2: warning: redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> [-W#warnings] 1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> | ^ ``` and it's just a wrapper in glibc as well. Use `<fcntl.h>` to be warning-free when building against musl
musl libc warns about these: ``` In file included from src/tls/socket-io.c:32: /usr/x86_64-pc-linux-musl/include/sys/poll.h:1:2: warning: redirecting incorrect #include <sys/poll.h> to <poll.h> [-W#warnings] 1 | #warning redirecting incorrect #include <sys/poll.h> to <poll.h> | ^ CC src/pam-ssh-add/pam_ssh_add_so-pam-ssh-add.o In file included from src/tls/connection.c:37: /usr/x86_64-pc-linux-musl/include/sys/poll.h:1:2: warning: redirecting incorrect #include <sys/poll.h> to <poll.h> [-W#warnings] 1 | #warning redirecting incorrect #include <sys/poll.h> to <poll.h> | ^ ``` and glibc's `<sys/poll.h>` also just wraps `<poll.h>`. Use `<poll.h>` to get rid of the warning on musl based systems
Thanks a lot! We don't run CI on musl, so we can't guarantee that we won't break it again -- but as the C bridge is basically dead and will be dropped from main in less than 6 months, we won't touch it much any more anyway. Out of interest, why do you even build with |
IIRC systemd does not support musl at all and Cockpit basically depends on it, it might not be worthy to chase this. Although for the bridge this is fine ofcourse. |
Fix a couple of things to allow building on musl based systems:
SIGCLD
but onlySIGCHLD
=> ifdef it as done for other signalssrc/session/session-utils.c
uses_PATH_LASTLOG
but doesn't include<paths.h>
where it's defined (on musl and glibc)fts_{open,read,close}
itself and needs to link against an external fts libraryargp_{parse,error}
itself and needs to link against an external argp library<xyz.h>
instead of<sys/xyz.h>
so the build on musl systems is warning-free