Closed aidanharris closed 1 year ago
Yeah, just tested in Debian docker container with neither libsystemd-dev nor libelogind installed:
# make
Package libelogind was not found in the pkg-config search path.
Perhaps you should add the directory containing `libelogind.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libelogind' found
Package libelogind was not found in the pkg-config search path.
Perhaps you should add the directory containing `libelogind.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libelogind' found
cc -Wall -Wextra -Wformat-security -Wconversion -fstack-protector-all -std=gnu99 -g -I/usr/include/systemd -o systembus-notify *.c
main.c:4:10: fatal error: sd-bus.h: No such file or directory
4 | #include <sd-bus.h>
| ^~~~~~~~~~
compilation terminated.
notify.c:4:10: fatal error: sd-bus.h: No such file or directory
4 | #include <sd-bus.h>
| ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:8: systembus-notify] Error 1
I think if neither is installed the error message should tell the user to install libsystemd.
Fixed by inverting the condition. It's better to assume systemd is installed (systems using libelogind won't have libsystemd installed)
Better, but, why replace #include <systemd/sd-bus.h>
with <sd-bus.h>
? Does libelogind not provide the systemd directory?
Looking at https://github.com/elogind/elogind/blob/main/src/systemd/sd-bus.h , it seems that elogind does provide the systemd directory.
Does libelogind not provide the systemd directory?
It's installed at /usr/include/elogind, probably to not conflict with /usr/include/systemd if somebody were to install both libsystemd and libelogind at the same time, which I think is technically possible but there's no reason to do that.
Debian blocks that from happening so it should be okay to check if libelogind is installed first (it shouldn't be on most systems) and always use systemd in any other case.
# apt install -y libsystemd-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libelogind0 : Conflicts: libsystemd0
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
If for some strange reason somebody had both libsystemd and libelogind installed they could still force libsystemd to be used by running:
make LIBSYSTEMD_PROVIDER=libsystemd
Looking at https://github.com/elogind/elogind/blob/main/src/systemd/sd-bus.h , it seems that elogind does provide the systemd directory.
For some reason this didn't work the first time I tried this but it does now. I'm not sure why it didn't work on my first attempt. I'll push again without the changes to main.c and notify.c
The second push was to remove the -I/usr/include/systemd
but that doesn't show in Github's webui for some reason.
Hi, I implemented this a little differently, please see if
works for you.
This uses pkg-config to fetch the include dir and ldflags instead of hardcoding it.
Tested on my Gentoo system with elogind and compile-tested on an Archlinux system.