ratbagd: install the devel dbus policy file on startup

Don't rely on some other tool to install the policy file, let's just do this
in ratbagd.devel directly so it's immediately executable.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2019-07-25 21:31:23 +10:00
parent 122f05c272
commit 79e94b4a7e
4 changed files with 68 additions and 25 deletions

View File

@@ -422,19 +422,29 @@ install_man('ratbagd/ratbagd.8')
# (org.freedesktop.ratbag_devel1). This server is used by ratbagdctl.devel.
#
config_ratbagd_devel = configuration_data()
dbus_devel_policy = configure_file(input : 'dbus/org.freedesktop.ratbag_devel1.conf.in',
output : 'org.freedesktop.ratbag_devel1.conf',
configuration : config_ratbagd_devel)
# This is a hack. We always install the devel policy file into
# /etc/dbus-1/system.d, independent of any prefixes we use otherwise.
# This should never be used outside of developer machines anyway, but
# installations on those may use different prefixes for building.
# This is not set in stone, suggest something better if you can.
dbussystemdir = join_paths('/', get_option('sysconfdir'), 'dbus-1', 'system.d')
executable('ratbagd.devel',
src_ratbagd,
dependencies : deps_ratbagd,
include_directories : include_directories('src'),
install : false,
c_args : ['-DRATBAG_DBUS_INTERFACE="ratbag_devel1"',
'-DDBUS_POLICY_SRC="@0@/@1@"'.format(meson.build_root(), dbus_devel_policy),
'-DDBUS_POLICY_DST="@0@/@1@"'.format(dbussystemdir, dbus_devel_policy),
'-DDISABLE_COREDUMP=1'],
)
config_ratbagd_devel = configuration_data()
configure_file(input : 'dbus/org.freedesktop.ratbag_devel1.conf.in',
output : 'org.freedesktop.ratbag_devel1.conf',
configuration : config_ratbagd_devel)
#### unit file ####
if enable_systemd

View File

@@ -521,6 +521,56 @@ static int ratbagd_run(struct ratbagd *ctx)
return sd_event_loop(ctx->event);
}
static bool install_ratbagd_devel_dbus_policy(void)
{
bool rc = true;
#ifdef RATBAG_DEVELOPER_EDITION
_cleanup_close_ int in = -1, out = -1;
int nread, nwrite;
char buf[40960];
rc = false;
log_verbose("Installing DBus policy file to %s\n", DBUS_POLICY_DST);
in = open(DBUS_POLICY_SRC, O_RDONLY);
if (in == -1) {
log_error("Failed to source policy file: %m\n");
goto out;
}
out = open(DBUS_POLICY_DST, O_CREAT|O_WRONLY, 0644);
if (out == -1) {
log_error("Failed to open destination: %m\n");
goto out;
}
nread = read(in, buf, sizeof(buf));
if (nread < 0) {
log_error("Failed to read policy file: %m\n");
goto out;
}
nwrite = write(out, buf, nread);
if (nread != nwrite) {
log_error("Failed to write policy file: %m\n");
goto out;
}
rc = true;
out:
#endif
return rc;
}
static void remove_ratbagd_devel_dbus_policy(void)
{
#ifdef RATBAG_DEVELOPER_EDITION
unlink(DBUS_POLICY_DST);
#endif
}
int main(int argc, char *argv[])
{
struct ratbagd *ctx = NULL;
@@ -550,6 +600,9 @@ int main(int argc, char *argv[])
}
}
if (!install_ratbagd_devel_dbus_policy())
goto exit;
r = ratbagd_new(&ctx);
if (r < 0)
goto exit;
@@ -558,6 +611,7 @@ int main(int argc, char *argv[])
r = ratbagd_run(ctx);
remove_ratbagd_devel_dbus_policy();
exit:
ratbagd_free(ctx);

View File

@@ -603,11 +603,6 @@ class TestRatbagCtlLED(TestRatbagCtl):
def setUpModule():
global ratbagd_process, ratbagd, parser
# To do actually do this:
# - copy the org.freedesktop.ratbag_devel1.conf to
# /etc/dbus-1/system.d
# - start builddir/ratbagd.devel (in gdb if need be)
# - run builddir/ratbagctl.test
ratbagd_process = None
if start_ratbagd:
ratbagd_process = toolbox.start_ratbagd()

View File

@@ -36,9 +36,6 @@ RATBAGCTL_NAME = 'ratbagctl'
RATBAGCTL_PATH = os.path.join('@MESON_BUILD_ROOT@', RATBAGCTL_NAME)
RATBAGCTL_DEVEL_NAME = 'ratbagctl.devel'
RATBAGCTL_DEVEL_PATH = os.path.join('@MESON_BUILD_ROOT@', RATBAGCTL_DEVEL_NAME)
DBUS_CONF_DIR = '/etc/dbus-1/system.d'
DBUS_CONF_NAME = 'org.freedesktop.ratbag_devel1.conf'
DBUS_CONF_PATH = os.path.join(DBUS_CONF_DIR, DBUS_CONF_NAME)
def import_non_standard_path(name, path):
@@ -61,12 +58,6 @@ def start_ratbagd(verbosity=0):
from gi.repository import Gio
import time
os.makedirs(DBUS_CONF_DIR, exist_ok=True)
# first copy the policy for the ratbagd daemon to be allowed to run
shutil.copy(os.path.join('@MESON_BUILD_ROOT@', DBUS_CONF_NAME),
DBUS_CONF_PATH)
# FIXME: kill any running ratbagd.devel
args = [os.path.join('@MESON_BUILD_ROOT@', "ratbagd.devel")]
@@ -111,10 +102,6 @@ def terminate_ratbagd(ratbagd):
ratbagd.wait(5)
except subprocess.TimeoutExpired:
ratbagd.kill()
try:
os.unlink(DBUS_CONF_PATH)
except FileNotFoundError:
pass
def sync_dbus():
@@ -130,9 +117,6 @@ from ratbagctl import open_ratbagd, get_parser, RatbagError, RatbagErrorCapabili
__all__ = [
RATBAGCTL_NAME,
RATBAGCTL_PATH,
DBUS_CONF_DIR,
DBUS_CONF_NAME,
DBUS_CONF_PATH,
start_ratbagd,
terminate_ratbagd,
open_ratbagd,