From b9bae8fc5bd89349e95a04911559e970324f8754 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 15 Dec 2017 17:01:46 +0000 Subject: [PATCH] daemon/config: add new rpm-ostreed.conf Making this a separate commit, since it's a first for rpm-ostree. We now have a conf file complete with man page! No options yet though. Interestingly, there was a function called `rpmostreed_reload_config` which was declared but never defined. Didn't look too much into that. We make sure that the config is part of the things we reload when users call `rpm-ostree reload`. Closes: #1204 Approved by: cgwalters --- Makefile-daemon.am | 3 ++ Makefile-decls.am | 1 + Makefile-man.am | 6 ++- Makefile.am | 3 +- man/rpm-ostreed.conf.xml | 92 +++++++++++++++++++++++++++++++++ src/daemon/rpm-ostreed.conf | 5 ++ src/daemon/rpmostreed-daemon.c | 50 ++++++++++++++++++ src/daemon/rpmostreed-daemon.h | 3 +- src/daemon/rpmostreed-sysroot.c | 3 ++ 9 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 man/rpm-ostreed.conf.xml create mode 100644 src/daemon/rpm-ostreed.conf diff --git a/Makefile-daemon.am b/Makefile-daemon.am index deecd6e2..bfe0e40b 100644 --- a/Makefile-daemon.am +++ b/Makefile-daemon.am @@ -111,10 +111,13 @@ polkit_policydir = $(datadir)/polkit-1/actions dbus_introspection_DATA = src/daemon/org.projectatomic.rpmostree1.xml dbus_introspectiondir = $(datadir)/dbus-1/interfaces +sysconf_DATA += $(srcdir)/src/daemon/rpm-ostreed.conf + EXTRA_DIST += \ $(dbus_introspection_DATA) \ $(dbusservice_DATA) \ $(polkit_policy_DATA) \ + $(sysconf_DATA) \ $(service_in_files) \ $(systemdunit_in_files) \ $(NULL) diff --git a/Makefile-decls.am b/Makefile-decls.am index 86653167..433e30dd 100644 --- a/Makefile-decls.am +++ b/Makefile-decls.am @@ -38,6 +38,7 @@ privlibdir = $(pkglibdir) privlib_LTLIBRARIES = pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = +sysconf_DATA = INTROSPECTION_GIRS = girdir = $(datadir)/gir-1.0 gir_DATA = diff --git a/Makefile-man.am b/Makefile-man.am index 0b952156..2397a36c 100644 --- a/Makefile-man.am +++ b/Makefile-man.am @@ -16,6 +16,7 @@ # Boston, MA 02111-1307, USA. man1_MANS = rpm-ostree.1 +man5_MANS = rpm-ostreed.conf.5 XSLTPROC_FLAGS = \ --nonet \ @@ -31,4 +32,7 @@ XSLTPROC_FLAGS_MAN = \ rpm-ostree.1: man/rpm-ostree.xml Makefile $(AM_V_GEN) $(XSLTPROC) $(XSLTPROC_FLAGS_MAN) $< -CLEANFILES += rpm-ostree.1 +rpm-ostreed.conf.5: man/rpm-ostreed.conf.xml Makefile + $(AM_V_GEN) $(XSLTPROC) $(XSLTPROC_FLAGS_MAN) $< + +CLEANFILES += $(man1_MANS) $(man5_MANS) diff --git a/Makefile.am b/Makefile.am index d16d698e..003859d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,8 @@ AM_CPPFLAGS += -DDATADIR='"$(datadir)"' \ -DWITH_SWDB=0 \ -DLIBEXECDIR='"$(libexecdir)"' \ -DLOCALEDIR=\"$(datadir)/locale\" \ - -DRPM_OSTREE_FEATURES='"$(RPM_OSTREE_FEATURES)"' \ + -DSYSCONFDIR='"$(sysconfdir)"' \ + -DRPM_OSTREE_FEATURES='"$(RPM_OSTREE_FEATURES)"' \ -DRPM_OSTREE_GITREV='"$(RPM_OSTREE_GITREV)"' \ -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_50 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_50 # Keep this in sync with the AM_CFLAGS in libostree; see diff --git a/man/rpm-ostreed.conf.xml b/man/rpm-ostreed.conf.xml new file mode 100644 index 00000000..d36ec185 --- /dev/null +++ b/man/rpm-ostreed.conf.xml @@ -0,0 +1,92 @@ + + + + + + + + + rpm-ostreed.conf + rpm-ostree + + + + Developer + Jonathan + Lebon + jlebon@redhat.com + + + + + + rpm-ostreed.conf + 5 + + + + rpm-ostreed.conf + RPM-OSTree daemon configuration file + + + + /etc/rpm-ostreed.conf + + + + Description + + + This file configures the RPM-OSTree daemon. + + + + + Options + + + All options are configured in the "[Daemon]" section. There are + currently no available options. + + + + + + + + + See Also + + + rpm-ostree1 + + + + diff --git a/src/daemon/rpm-ostreed.conf b/src/daemon/rpm-ostreed.conf new file mode 100644 index 00000000..f9e0ff71 --- /dev/null +++ b/src/daemon/rpm-ostreed.conf @@ -0,0 +1,5 @@ +# Entries in this file show the compile time defaults. +# You can change settings by editing this file. +# For option meanings, see rpm-ostreed.conf(5). + +[Daemon] diff --git a/src/daemon/rpmostreed-daemon.c b/src/daemon/rpmostreed-daemon.c index 28896526..b91014ff 100644 --- a/src/daemon/rpmostreed-daemon.c +++ b/src/daemon/rpmostreed-daemon.c @@ -34,6 +34,9 @@ * follow-up requests are more responsive */ #define IDLE_EXIT_TIMEOUT_SECONDS 60 +#define RPMOSTREED_CONF SYSCONFDIR "/rpm-ostreed.conf" +#define DAEMON_CONFIG_GROUP "Daemon" + /** * SECTION: daemon * @title: RpmostreedDaemon @@ -246,6 +249,10 @@ rpmostreed_daemon_initable_init (GInitable *initable, g_dbus_object_manager_server_set_connection (self->object_manager, self->connection); g_debug ("exported object manager"); + /* do this early so sysroot startup sets properties to the right values */ + if (!rpmostreed_daemon_reload_config (self, NULL, error)) + return FALSE; + g_autofree gchar *path = rpmostreed_generate_object_path (BASE_DBUS_PATH, "Sysroot", NULL); self->sysroot = g_object_new (RPMOSTREED_TYPE_SYSROOT, @@ -279,6 +286,49 @@ rpmostreed_daemon_initable_init (GInitable *initable, return TRUE; } +/* Returns TRUE if config file exists and could be loaded or if config file doesn't exist. + * Returns FALSE if config file exists but could not be loaded. */ +static gboolean +maybe_load_config_keyfile (GKeyFile **out_keyfile, + GError **error) +{ + g_autoptr(GError) local_error = NULL; + + g_autoptr(GKeyFile) keyfile = g_key_file_new (); + if (g_key_file_load_from_file (keyfile, RPMOSTREED_CONF, 0, &local_error)) + { + *out_keyfile = g_steal_pointer (&keyfile); + sd_journal_print (LOG_INFO, "Reading config file '%s'", RPMOSTREED_CONF); + return TRUE; + } + + if (!g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + { + g_propagate_error (error, g_steal_pointer (&local_error)); + return FALSE; + } + + sd_journal_print (LOG_WARNING, "Missing config file '%s'; using compiled defaults", + RPMOSTREED_CONF); + return TRUE; +} + +gboolean +rpmostreed_daemon_reload_config (RpmostreedDaemon *self, + gboolean *out_changed, + GError **error) +{ + g_autoptr(GKeyFile) config = NULL; + if (!maybe_load_config_keyfile (&config, error)) + return FALSE; + + /* when we have configs, we'll read them in here */ + + if (out_changed) + *out_changed = FALSE; + return TRUE; +} + static void rpmostreed_daemon_class_init (RpmostreedDaemonClass *klass) { diff --git a/src/daemon/rpmostreed-daemon.h b/src/daemon/rpmostreed-daemon.h index 0f4ad91e..e93b74a7 100644 --- a/src/daemon/rpmostreed-daemon.h +++ b/src/daemon/rpmostreed-daemon.h @@ -47,5 +47,6 @@ void rpmostreed_daemon_publish (RpmostreedDaemon *self, void rpmostreed_daemon_unpublish (RpmostreedDaemon *self, const gchar *path, gpointer thing); -gboolean rpmostreed_reload_config (RpmostreedDaemon *self, +gboolean rpmostreed_daemon_reload_config (RpmostreedDaemon *self, + gboolean *out_changed, GError **error); diff --git a/src/daemon/rpmostreed-sysroot.c b/src/daemon/rpmostreed-sysroot.c index 10e64737..f6bee926 100644 --- a/src/daemon/rpmostreed-sysroot.c +++ b/src/daemon/rpmostreed-sysroot.c @@ -417,6 +417,9 @@ handle_reload_config (RPMOSTreeSysroot *object, g_autoptr(GError) local_error = NULL; GError **error = &local_error; + if (!rpmostreed_daemon_reload_config (rpmostreed_daemon_get (), NULL, error)) + goto out; + if (!rpmostreed_sysroot_reload (self, error)) goto out;