rfjakob / systembus-notify

systembus-notify - system bus notification daemon
MIT License
57 stars 6 forks source link

Support building with libelogind as an alternative libsystemd provider #10

Closed aidanharris closed 1 year ago

aidanharris commented 2 years ago

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.

rfjakob commented 2 years 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
aidanharris commented 2 years ago

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)

rfjakob commented 2 years ago

Better, but, why replace #include <systemd/sd-bus.h> with <sd-bus.h>? Does libelogind not provide the systemd directory?

rfjakob commented 2 years ago

Looking at https://github.com/elogind/elogind/blob/main/src/systemd/sd-bus.h , it seems that elogind does provide the systemd directory.

aidanharris commented 2 years ago

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 
aidanharris commented 2 years ago

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

aidanharris commented 2 years ago

The second push was to remove the -I/usr/include/systemd but that doesn't show in Github's webui for some reason.

rfjakob commented 1 year ago

Hi, I implemented this a little differently, please see if

https://github.com/rfjakob/systembus-notify/commit/f5f7a4134b6801a7d970ff8133741a9a1e7ca792#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R3

works for you.