From 687567d3eef470887ff14f9128ab3be2fa25d68d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 27 May 2016 14:46:46 -0400 Subject: [PATCH] Merge daemon binary into main binary The actual problem I am trying to fix with this is fallout from the introduction of `/usr/libexec/rpm-ostreed`, which required a SELinux policy change. Specifically for CentOS, the base policy is rev'd slowly. My hope was that by merging the daemon code back into `/usr/bin/rpm-ostree` which is labeled `install_exec_t`, starting via systemd would do the right thing. It turns out that doesn't happen. Now later, I'm picking this patch back up because I want to do multprocessing in the daemon (and in the core), and it makes sense to share code between them, because multiprocessing will need to go through a re-exec path. Another benefit is we avoid duplicated text (libglnx, internal helpers) between the two binaries. Closes: #292 Approved by: jlebon --- Makefile-daemon.am | 32 ++---- Makefile-rpm-ostree.am | 7 +- Makefile.am | 1 + src/app/rpmostree-builtin-internals.c | 1 + src/app/rpmostree-dbus-helpers.c | 4 +- ...pmostree-internals-builtin-start-daemon.c} | 97 ++++++++----------- src/app/rpmostree-internals-builtins.h | 1 + .../org.projectatomic.rpmostree1.service.in | 2 +- src/daemon/rpm-ostreed-stub.sh.in | 2 + src/daemon/rpm-ostreed.service.in | 2 +- tests/utils/setup-session.sh | 4 +- tests/vmcheck/overlay.sh | 2 +- tests/vmcheck/sync.sh | 3 +- 13 files changed, 68 insertions(+), 90 deletions(-) rename src/{daemon/main.c => app/rpmostree-internals-builtin-start-daemon.c} (83%) create mode 100644 src/daemon/rpm-ostreed-stub.sh.in diff --git a/Makefile-daemon.am b/Makefile-daemon.am index 51c23cb1..2047bf87 100644 --- a/Makefile-daemon.am +++ b/Makefile-daemon.am @@ -1,5 +1,3 @@ -libexec_PROGRAMS += rpm-ostreed - dbus_built_sources = rpm-ostreed-generated.h rpm-ostreed-generated.c rpm-ostreed-generated.h: rpm-ostreed-generated.c @@ -64,24 +62,6 @@ librpmostreed_la_LIBADD = \ $(CAP_LIBS) $(NULL) -rpm_ostreed_SOURCES = \ - src/daemon/main.c \ - $(NULL) - -rpm_ostreed_CFLAGS = \ - $(AM_CFLAGS) \ - -DPKGLIBDIR=\"$(pkglibdir)\" \ - $(PKGDEP_RPMOSTREE_CFLAGS) \ - -I$(srcdir)/src/daemon \ - -I$(srcdir)/libglnx \ - -DG_LOG_DOMAIN=\"rpm-ostreed\" \ - $(NULL) - -rpm_ostreed_LDADD = \ - librpmostreed.la \ - $(PKGDEP_RPMOSTREE_LIBS) \ - $(NULL) - dbusconf_DATA = $(srcdir)/src/daemon/org.projectatomic.rpmostree1.conf dbusconfdir = ${sysconfdir}/dbus-1/system.d @@ -96,9 +76,13 @@ endif $(systemdunit_DATA): Makefile $(SED_SUBST) $(daemon_asan_options) $@.in > $@ +# We keep this stub script around to have SELinux labeling work, +# plus some backwards compatibility. +libexec_SCRIPTS = rpm-ostreed +rpm-ostreed: $(srcdir)/src/daemon/rpm-ostreed-stub.sh.in Makefile + $(SED_SUBST) $< > $@.tmp && mv $@.tmp $@ + install-daemon-altname-hook: - mv $(DESTDIR)$(libexecdir)/rpm-ostreed $(DESTDIR)$(libexecdir)/$(primaryname)d - ln -sf $(primaryname)d $(DESTDIR)$(libexecdir)/rpm-ostreed mv $(DESTDIR)$(systemdunitdir)/rpm-ostreed.service $(DESTDIR)$(systemdunitdir)/$(primaryname)d.service ln -sf $(primaryname)d.service $(DESTDIR)$(systemdunitdir)/rpm-ostreed.service if BUILDOPT_NEW_NAME @@ -109,8 +93,8 @@ endif service_in_files = $(srcdir)/src/daemon/org.projectatomic.rpmostree1.service.in service_DATA = $(service_in_files:.service.in=.service) servicedir = $(dbusservicedir) -$(service_DATA): - $(SED_SUBST) $@.in > $@ +%.service: %.service.in Makefile + $(SED_SUBST) $@.in > $@.tmp && mv $@.tmp $@ EXTRA_DIST += \ $(dbusservice_DATA) \ diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index a4d8c60e..0526e7b8 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -41,6 +41,7 @@ rpm_ostree_SOURCES = src/app/main.c \ src/app/rpmostree-container-builtins.h \ src/app/rpmostree-container-builtins.c \ src/app/rpmostree-internals-builtin-unpack.c \ + src/app/rpmostree-internals-builtin-start-daemon.c \ src/app/rpmostree-libbuiltin.c \ src/app/rpmostree-libbuiltin.h \ $(NULL) @@ -53,8 +54,10 @@ rpm_ostree_SOURCES += \ $(NULL) endif -rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/lib -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS) -rpm_ostree_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la librpmostree-1.la +rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/daemon \ + -I$(srcdir)/src/lib -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) \ + -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS) +rpm_ostree_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la librpmostree-1.la librpmostreed.la privdatadir=$(pkglibdir) privdata_DATA = src/app/rpm-ostree-0-integration.conf diff --git a/Makefile.am b/Makefile.am index 25b1c694..c409b523 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ GITIGNOREFILES += build-aux/ gtk-doc.make config.h.in aclocal.m4 insttree/ SED_SUBST = sed \ -e 's,[@]libexecdir[@],$(libexecdir),g' \ -e 's,[@]primaryname[@],$(primaryname),g' \ + -e 's,[@]bindir[@],$(bindir),g' \ $(NULL) libglnx_srcpath := $(srcdir)/libglnx diff --git a/src/app/rpmostree-builtin-internals.c b/src/app/rpmostree-builtin-internals.c index 9f087d17..f540111a 100644 --- a/src/app/rpmostree-builtin-internals.c +++ b/src/app/rpmostree-builtin-internals.c @@ -30,6 +30,7 @@ typedef struct { static RpmOstreeInternalsCommand internals_subcommands[] = { { "unpack", rpmostree_internals_builtin_unpack }, + { "start-daemon", rpmostree_internals_builtin_start_daemon }, { NULL, NULL } }; diff --git a/src/app/rpmostree-dbus-helpers.c b/src/app/rpmostree-dbus-helpers.c index fd49bd1e..58e6aee1 100644 --- a/src/app/rpmostree-dbus-helpers.c +++ b/src/app/rpmostree-dbus-helpers.c @@ -52,7 +52,9 @@ get_connection_for_path (gchar *sysroot, gboolean ret = FALSE; const gchar *args[] = { - "rpm-ostreed", + "rpm-ostree", + "internals", + "start-daemon", "--sysroot", sysroot, "--dbus-peer", buffer, NULL diff --git a/src/daemon/main.c b/src/app/rpmostree-internals-builtin-start-daemon.c similarity index 83% rename from src/daemon/main.c rename to src/app/rpmostree-internals-builtin-start-daemon.c index ecad1c57..f70b61b3 100644 --- a/src/daemon/main.c +++ b/src/app/rpmostree-internals-builtin-start-daemon.c @@ -1,33 +1,39 @@ -/* -* Copyright (C) 2007-2010 David Zeuthen -* Copyright (C) 2013-2015 Red Hat, Inc. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2016 Colin Walters + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2 of the licence or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ #include "config.h" -#include "rpmostreed-daemon.h" - -#include +#include #include -#include +#include +#include +#include +#include #include #include "libglnx.h" -/* ---------------------------------------------------------------------------------------------------- */ +#include "rpmostree-internals-builtins.h" +#include "rpmostree-util.h" +#include "rpmostreed-daemon.h" +#include "rpmostree-libbuiltin.h" + static GMainLoop *loop = NULL; static gboolean opt_debug = FALSE; static char *opt_sysroot = "/"; @@ -292,38 +298,23 @@ out: int -main (int argc, - char **argv) +rpmostree_internals_builtin_start_daemon (int argc, + char **argv, + GCancellable *cancellable, + GError **error) { - GError *error; - g_autoptr(GOptionContext) opt_context = NULL; + int ret = 1; + g_autoptr(GMainLoop) loop = NULL; + g_autoptr(GOptionContext) opt_context = g_option_context_new ("rpm-ostreed -- rpm-ostree daemon"); GIOChannel *channel; guint name_owner_id = 0; - gint ret; - ret = 1; - loop = NULL; - - #if !GLIB_CHECK_VERSION(2,36,0) - g_type_init (); - #endif - - /* See glib/gio/gsocket.c */ - signal (SIGPIPE, SIG_IGN); - - /* avoid gvfs and gsettings: https://bugzilla.gnome.org/show_bug.cgi?id=767183 */ - g_assert (g_setenv ("GIO_USE_VFS", "local", TRUE)); g_assert (g_setenv ("GSETTINGS_BACKEND", "memory", TRUE)); - opt_context = g_option_context_new ("rpm-ostreed -- rpm-ostree daemon"); g_option_context_add_main_entries (opt_context, opt_entries, NULL); - error = NULL; - if (!g_option_context_parse (opt_context, &argc, &argv, &error)) - { - g_printerr ("Error parsing options: %s\n", error->message); - g_error_free (error); - goto out; - } + + if (!g_option_context_parse (opt_context, &argc, &argv, error)) + goto out; if (opt_debug) { @@ -371,10 +362,7 @@ main (int argc, NULL, (GDestroyNotify) NULL); } else if (!connect_to_peer (service_dbus_fd)) - { - ret = 1; - goto out; - } + goto out; g_debug ("Entering main event loop"); @@ -391,10 +379,5 @@ main (int argc, ret = 0; out: - if (loop != NULL) - g_main_loop_unref (loop); - - g_info ("rpm-ostreed exiting"); - return ret; } diff --git a/src/app/rpmostree-internals-builtins.h b/src/app/rpmostree-internals-builtins.h index e7f44ca4..506f7312 100644 --- a/src/app/rpmostree-internals-builtins.h +++ b/src/app/rpmostree-internals-builtins.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS gboolean rpmostree_internals_builtin_unpack (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean rpmostree_internals_builtin_start_daemon (int argc, char **argv, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/daemon/org.projectatomic.rpmostree1.service.in b/src/daemon/org.projectatomic.rpmostree1.service.in index c0b8f3c4..662e7bb2 100644 --- a/src/daemon/org.projectatomic.rpmostree1.service.in +++ b/src/daemon/org.projectatomic.rpmostree1.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.projectatomic.rpmostree1 -Exec=@libexecdir@/@primaryname@d +Exec=@bindir@/rpm-ostree internals start-daemon User=root SystemdService=@primaryname@d.service diff --git a/src/daemon/rpm-ostreed-stub.sh.in b/src/daemon/rpm-ostreed-stub.sh.in new file mode 100644 index 00000000..48e7417f --- /dev/null +++ b/src/daemon/rpm-ostreed-stub.sh.in @@ -0,0 +1,2 @@ +#!/bin/sh +exec @bindir@/rpm-ostree internals start-daemon "$@" diff --git a/src/daemon/rpm-ostreed.service.in b/src/daemon/rpm-ostreed.service.in index 2a68977b..508d8e92 100644 --- a/src/daemon/rpm-ostreed.service.in +++ b/src/daemon/rpm-ostreed.service.in @@ -6,4 +6,4 @@ ConditionPathExists=/ostree Type=dbus BusName=org.projectatomic.rpmostree1 @SYSTEMD_ENVIRON@ -ExecStart=@libexecdir@/@primaryname@d +ExecStart=@bindir@/rpm-ostree internals start-daemon diff --git a/tests/utils/setup-session.sh b/tests/utils/setup-session.sh index 8a9f7694..f7ed321a 100755 --- a/tests/utils/setup-session.sh +++ b/tests/utils/setup-session.sh @@ -25,7 +25,7 @@ set -e # libtest.sh should have added the builddir which contains rpm-ostreed to our # path -exec_binary="$(which rpm-ostreed)" +exec_binary="$(which rpm-ostree)" mkdir -p sysroot mkdir -p session-services @@ -56,7 +56,7 @@ EOF cat > session-services/rpmostree.service <