From 7f26122c62423bdab6c18732bbc0f3fe9f06e8f1 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Tue, 16 Jan 2018 17:26:45 +0000 Subject: [PATCH] Allow controlling whether systemd is used or not Currently this will switch the build system between using a plain D-BUS service file, or a user controllable systemd unit that can be actively stopped/started. In most cases it is more desirable to use the systemd unit approach, as plain D-BUS services cannot be controlled and are more difficult to introspect via the log. For fallback cases we'll have the plain D-BUS unit, and in future we can use this to allow untying from systemd specifics. Signed-off-by: Ikey Doherty --- data/gamemoded.service.in | 10 ++++++++++ data/meson.build | 26 ++++++++++++++++++-------- meson.build | 33 +++++++++++++++++++++++++++++---- meson_options.txt | 8 ++++++++ 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 data/gamemoded.service.in diff --git a/data/gamemoded.service.in b/data/gamemoded.service.in new file mode 100644 index 0000000..9472485 --- /dev/null +++ b/data/gamemoded.service.in @@ -0,0 +1,10 @@ +[Unit] +Description=gamemoded + +[Service] +Type=dbus +BusName=com.feralinteractive.GameMode +ExecStart=@BINDIR@/gamemoded -l + +[Install] +WantedBy=default.target diff --git a/data/meson.build b/data/meson.build index 616cc88..3f7f490 100644 --- a/data/meson.build +++ b/data/meson.build @@ -2,15 +2,25 @@ data_conf = configuration_data() data_conf.set('BINDIR', path_bindir) data_conf.set('LIBEXECDIR', path_libexecdir) -# Install the D-BUS service file -configure_file( - input: 'com.feralinteractive.GameMode.service.in', - output: 'com.feralinteractive.GameMode.service', - configuration: data_conf, - install_dir: path_dbus_service_dir, -) +if with_systemd == true + # Install systemd user unit + configure_file( + input: 'gamemoded.service.in', + output: 'gamemoded.service', + configuration: data_conf, + install_dir: path_systemd_unit_dir, + ) +else + # Install the D-BUS service file + configure_file( + input: 'com.feralinteractive.GameMode.service.in', + output: 'com.feralinteractive.GameMode.service', + configuration: data_conf, + install_dir: path_dbus_service_dir, + ) +endif -# Install the Polkit action file +# Install the Polkit action file in all cases configure_file( input: 'com.feralinteractive.GameMode.policy.in', output: 'com.feralinteractive.GameMode.policy', diff --git a/meson.build b/meson.build index 5382bd1..a539f21 100644 --- a/meson.build +++ b/meson.build @@ -44,10 +44,21 @@ dep_threads = dependency('threads') # On non glibc systems this might be a stub, i.e. for musl libdl = cc.find_library('dl', required: false) -# Set the dbus path as appropriate. -path_dbus_service_dir = get_option('with-dbus-service-dir') -if path_dbus_service_dir == '' - path_dbus_service_dir = join_paths(path_datadir, 'dbus-1', 'services') +with_systemd = get_option('with-systemd') +if with_systemd == true + # If the path isn't explicitly set, ask systemd for the systemd user unit directory + path_systemd_unit_dir = get_option('with-systemd-user-unit-dir') + if path_systemd_unit_dir == '' + message('Asking pkg-config for systemd\'s directories') + pkgconfig_systemd = dependency('systemd') + path_systemd_unit_dir = pkgconfig_systemd.get_pkgconfig_variable('systemduserunitdir') + endif +else + # Set the dbus path as appropriate. + path_dbus_service_dir = get_option('with-dbus-service-dir') + if path_dbus_service_dir == '' + path_dbus_service_dir = join_paths(path_datadir, 'dbus-1', 'services') + endif endif path_polkit_action_dir = join_paths(path_datadir, 'polkit-1', 'actions') @@ -92,7 +103,20 @@ report = [ ' libdir: @0@'.format(path_libdir), ' libexecdir: @0@'.format(path_libexecdir), ' includedir: @0@'.format(path_includedir), +] + +if with_systemd == true +report += [ + ' systemd user unit directory: @0@'.format(path_systemd_unit_dir), +] +else +report += [ ' D-BUS service directory: @0@'.format(path_dbus_service_dir), +] +endif + +report += [ + ' PolKit Action Directory: @0@'.format(path_polkit_action_dir), '', ' Options:', @@ -100,6 +124,7 @@ report = [ '', ' daemon: @0@'.format(with_daemon), ' examples: @0@'.format(with_examples), + ' systemd: @0@'.format(with_systemd), ] # Output some stuff to validate the build config diff --git a/meson_options.txt b/meson_options.txt index dfc93d3..249879b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,11 @@ +option('with-systemd', type: 'boolean', description: 'Use systemd support (unit, etc)', value: 'true') + +# systemd specific +option('with-systemd-user-unit-dir', type: 'string', description: 'Explicitly set the systemd user unit directory') + +# Not using systemd option('with-dbus-service-dir', type: 'string', description: 'Explicitly set the D-BUS session directory') + +# General options option('with-examples', type: 'boolean', description: 'Build sample programs', value: 'true') option('with-daemon', type: 'boolean', description: 'Build the daemon', value: 'true')