Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 7d0c8ee

Browse files
Marek Szubaheftig
authored andcommitted
Make systemd integration (sd-daemon API calls) optional
Now that rtkit links against libsystemd in order to use the sd-daemon API, it requires systemd to be installed - even if the system at hand uses a different service manager and calling said API doesn't actually do anything. Add a compile-time option ("enable-libsystemd" in autoconf, "libsystemd" in meson) which controls whether to enable systemd integration or not, in the latter case excluding all sd-daemon-related bits from rtkit-daemon. The logic of the new option is as follows: - by default, look for libsystemd and decide whether to enable this feature or not depending on whether the library has been found; - if explicitly disable, do not even bother looking for libsystemd; - if explicitly enabled, look for libsystemd and fail if it hasn't been found. Note that this option only affects whether or not rtkit talks to systemd via the sd-daemon API, i.e. it has no effect on the installation of unit files.
1 parent d3e55f4 commit 7d0c8ee

6 files changed

Lines changed: 33 additions & 3 deletions

File tree

README

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,6 @@ REQUIREMENTS:
224224
Linux kernel >= 2.6.31
225225
D-Bus
226226
PolicyKit >= 0.92
227-
libsystemd
227+
228+
OPTIONAL DEPENDENCIES:
229+
libsystemd - to let rtkit talk to systemd using the sd-daemon API

config.h.meson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
#mesondefine PACKAGE_VERSION
55

6+
#mesondefine HAVE_LIBSYSTEMD
7+
68
#endif

configure.ac

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,18 @@ AC_SEARCH_LIBS([mq_open], [rt])
115115
AC_SEARCH_LIBS([cap_init], [cap])
116116

117117
PKG_CHECK_MODULES(DBUS, dbus-1)
118-
PKG_CHECK_MODULES(LIBSYSTEMD, libsystemd)
118+
119+
AC_ARG_ENABLE([libsystemd],
120+
AS_HELP_STRING([--enable-libsystemd], [use the libsystemd sd-daemon API to communicate with systemd (default: automatic)]))
121+
AS_IF([test "x${enable_libsystemd}" != "xno"],
122+
[PKG_CHECK_MODULES(LIBSYSTEMD, libsystemd, [have_libsystemd=yes], [have_libsystemd=no])],
123+
[have_libsystemd=no])
124+
AS_IF([test "x${have_libsystemd}" = "xyes"],
125+
[AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Define to 1 if you have libsystemd and its header files])],
126+
[AS_IF([test "x${enable_libsystemd}" = "xyes"],
127+
[AC_MSG_ERROR([sd-daemon support requested but libsystemd not found])
128+
])
129+
])
119130

120131
AC_ARG_WITH([systemdsystemunitdir],
121132
AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
@@ -148,4 +159,5 @@ echo "
148159
Compiler: ${CC}
149160
CFLAGS: ${CFLAGS}
150161
systemd unit directory: ${systemdsystemunitdir}
162+
use sd-daemon API: ${have_libsystemd}
151163
"

meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ xxd = find_program('xxd')
1717

1818
dbus_dep = dependency('dbus-1')
1919
libcap_dep = dependency('libcap')
20-
libsystemd_dep = dependency('libsystemd')
20+
libsystemd_dep = dependency('libsystemd', required: get_option('libsystemd'))
2121
polkit_dep = dependency('polkit-gobject-1', required: false)
2222
systemd_dep = dependency('systemd', required: false)
2323
thread_dep = dependency('threads')
@@ -72,6 +72,7 @@ endif
7272
config = configuration_data()
7373
config.set('LIBEXECDIR', get_option('prefix') / libexecdir)
7474
config.set_quoted('PACKAGE_VERSION', meson.project_version())
75+
config.set('HAVE_LIBSYSTEMD', libsystemd_dep.found())
7576

7677
config_h = configure_file(
7778
input: 'config.h.meson',

meson_options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ option(
1616
value: '',
1717
description: 'Directory for D-Bus system services',
1818
)
19+
option(
20+
'libsystemd',
21+
type: 'feature',
22+
value: 'auto',
23+
description: 'Use the libsystemd sd-daemon API to communicate with systemd'
24+
)
1925
option(
2026
'polkit_actiondir',
2127
type: 'string',

rtkit-daemon.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
#include <dirent.h>
5151
#include <syslog.h>
5252
#include <grp.h>
53+
54+
#ifdef HAVE_LIBSYSTEMD
5355
#include <systemd/sd-daemon.h>
56+
#endif
5457

5558
#include "rtkit.h"
5659

@@ -1434,11 +1437,13 @@ static DBusHandlerResult dbus_handler(DBusConnection *c, DBusMessage *m, void *u
14341437
n_total_processes,
14351438
n_users);
14361439

1440+
#ifdef HAVE_LIBSYSTEMD
14371441
sd_notifyf(0,
14381442
"STATUS=Supervising %u threads of %u processes of %u users.",
14391443
n_total_threads,
14401444
n_total_processes,
14411445
n_users);
1446+
#endif
14421447

14431448
finish:
14441449
if (r) {
@@ -2306,7 +2311,9 @@ int main(int argc, char *argv[]) {
23062311

23072312
syslog(LOG_DEBUG, "Running.\n");
23082313

2314+
#ifdef HAVE_LIBSYSTEMD
23092315
sd_notify(0, "STATUS=Running.");
2316+
#endif
23102317

23112318
dbus_connection_set_exit_on_disconnect(bus, FALSE);
23122319

0 commit comments

Comments
 (0)