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
This commit is contained in:
Colin Walters 2016-05-27 14:46:46 -04:00 committed by Atomic Bot
parent 7887c5a923
commit 687567d3ee
13 changed files with 68 additions and 90 deletions

View File

@ -1,5 +1,3 @@
libexec_PROGRAMS += rpm-ostreed
dbus_built_sources = rpm-ostreed-generated.h rpm-ostreed-generated.c dbus_built_sources = rpm-ostreed-generated.h rpm-ostreed-generated.c
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) $(CAP_LIBS)
$(NULL) $(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 dbusconf_DATA = $(srcdir)/src/daemon/org.projectatomic.rpmostree1.conf
dbusconfdir = ${sysconfdir}/dbus-1/system.d dbusconfdir = ${sysconfdir}/dbus-1/system.d
@ -96,9 +76,13 @@ endif
$(systemdunit_DATA): Makefile $(systemdunit_DATA): Makefile
$(SED_SUBST) $(daemon_asan_options) $@.in > $@ $(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: 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 mv $(DESTDIR)$(systemdunitdir)/rpm-ostreed.service $(DESTDIR)$(systemdunitdir)/$(primaryname)d.service
ln -sf $(primaryname)d.service $(DESTDIR)$(systemdunitdir)/rpm-ostreed.service ln -sf $(primaryname)d.service $(DESTDIR)$(systemdunitdir)/rpm-ostreed.service
if BUILDOPT_NEW_NAME if BUILDOPT_NEW_NAME
@ -109,8 +93,8 @@ endif
service_in_files = $(srcdir)/src/daemon/org.projectatomic.rpmostree1.service.in service_in_files = $(srcdir)/src/daemon/org.projectatomic.rpmostree1.service.in
service_DATA = $(service_in_files:.service.in=.service) service_DATA = $(service_in_files:.service.in=.service)
servicedir = $(dbusservicedir) servicedir = $(dbusservicedir)
$(service_DATA): %.service: %.service.in Makefile
$(SED_SUBST) $@.in > $@ $(SED_SUBST) $@.in > $@.tmp && mv $@.tmp $@
EXTRA_DIST += \ EXTRA_DIST += \
$(dbusservice_DATA) \ $(dbusservice_DATA) \

View File

@ -41,6 +41,7 @@ rpm_ostree_SOURCES = src/app/main.c \
src/app/rpmostree-container-builtins.h \ src/app/rpmostree-container-builtins.h \
src/app/rpmostree-container-builtins.c \ src/app/rpmostree-container-builtins.c \
src/app/rpmostree-internals-builtin-unpack.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.c \
src/app/rpmostree-libbuiltin.h \ src/app/rpmostree-libbuiltin.h \
$(NULL) $(NULL)
@ -53,8 +54,10 @@ rpm_ostree_SOURCES += \
$(NULL) $(NULL)
endif 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_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/daemon \
rpm_ostree_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la librpmostree-1.la -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) privdatadir=$(pkglibdir)
privdata_DATA = src/app/rpm-ostree-0-integration.conf privdata_DATA = src/app/rpm-ostree-0-integration.conf

View File

@ -50,6 +50,7 @@ GITIGNOREFILES += build-aux/ gtk-doc.make config.h.in aclocal.m4 insttree/
SED_SUBST = sed \ SED_SUBST = sed \
-e 's,[@]libexecdir[@],$(libexecdir),g' \ -e 's,[@]libexecdir[@],$(libexecdir),g' \
-e 's,[@]primaryname[@],$(primaryname),g' \ -e 's,[@]primaryname[@],$(primaryname),g' \
-e 's,[@]bindir[@],$(bindir),g' \
$(NULL) $(NULL)
libglnx_srcpath := $(srcdir)/libglnx libglnx_srcpath := $(srcdir)/libglnx

View File

@ -30,6 +30,7 @@ typedef struct {
static RpmOstreeInternalsCommand internals_subcommands[] = { static RpmOstreeInternalsCommand internals_subcommands[] = {
{ "unpack", rpmostree_internals_builtin_unpack }, { "unpack", rpmostree_internals_builtin_unpack },
{ "start-daemon", rpmostree_internals_builtin_start_daemon },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -52,7 +52,9 @@ get_connection_for_path (gchar *sysroot,
gboolean ret = FALSE; gboolean ret = FALSE;
const gchar *args[] = { const gchar *args[] = {
"rpm-ostreed", "rpm-ostree",
"internals",
"start-daemon",
"--sysroot", sysroot, "--sysroot", sysroot,
"--dbus-peer", buffer, "--dbus-peer", buffer,
NULL NULL

View File

@ -1,33 +1,39 @@
/* /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
* Copyright (C) 2007-2010 David Zeuthen <zeuthen@gmail.com> *
* Copyright (C) 2013-2015 Red Hat, Inc. * Copyright (C) 2016 Colin Walters <walters@verbum.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published
* the Free Software Foundation; either version 2 of the License, or * by the Free Software Foundation; either version 2 of the licence or (at
* (at your option) any later version. * your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Lesser General
* along with this program; if not, write to the Free Software * Public License along with this library; if not, write to the
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
*/ * Boston, MA 02111-1307, USA.
*/
#include "config.h" #include "config.h"
#include "rpmostreed-daemon.h" #include <string.h>
#include <glib/gi18n.h>
#include <glib-unix.h> #include <glib-unix.h>
#include <gio/gio.h> #include <gio/gunixoutputstream.h>
#include <stdio.h>
#include <libglnx.h>
#include <glib/gi18n.h>
#include <syslog.h> #include <syslog.h>
#include "libglnx.h" #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 GMainLoop *loop = NULL;
static gboolean opt_debug = FALSE; static gboolean opt_debug = FALSE;
static char *opt_sysroot = "/"; static char *opt_sysroot = "/";
@ -292,38 +298,23 @@ out:
int int
main (int argc, rpmostree_internals_builtin_start_daemon (int argc,
char **argv) char **argv,
GCancellable *cancellable,
GError **error)
{ {
GError *error; int ret = 1;
g_autoptr(GOptionContext) opt_context = NULL; g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GOptionContext) opt_context = g_option_context_new ("rpm-ostreed -- rpm-ostree daemon");
GIOChannel *channel; GIOChannel *channel;
guint name_owner_id = 0; 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)); 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); g_option_context_add_main_entries (opt_context, opt_entries, NULL);
error = NULL;
if (!g_option_context_parse (opt_context, &argc, &argv, &error)) if (!g_option_context_parse (opt_context, &argc, &argv, error))
{ goto out;
g_printerr ("Error parsing options: %s\n", error->message);
g_error_free (error);
goto out;
}
if (opt_debug) if (opt_debug)
{ {
@ -371,10 +362,7 @@ main (int argc,
NULL, (GDestroyNotify) NULL); NULL, (GDestroyNotify) NULL);
} }
else if (!connect_to_peer (service_dbus_fd)) else if (!connect_to_peer (service_dbus_fd))
{ goto out;
ret = 1;
goto out;
}
g_debug ("Entering main event loop"); g_debug ("Entering main event loop");
@ -391,10 +379,5 @@ main (int argc,
ret = 0; ret = 0;
out: out:
if (loop != NULL)
g_main_loop_unref (loop);
g_info ("rpm-ostreed exiting");
return ret; return ret;
} }

View File

@ -27,6 +27,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean rpmostree_internals_builtin_unpack (int argc, char **argv, GCancellable *cancellable, GError **error); 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 G_END_DECLS

View File

@ -1,5 +1,5 @@
[D-BUS Service] [D-BUS Service]
Name=org.projectatomic.rpmostree1 Name=org.projectatomic.rpmostree1
Exec=@libexecdir@/@primaryname@d Exec=@bindir@/rpm-ostree internals start-daemon
User=root User=root
SystemdService=@primaryname@d.service SystemdService=@primaryname@d.service

View File

@ -0,0 +1,2 @@
#!/bin/sh
exec @bindir@/rpm-ostree internals start-daemon "$@"

View File

@ -6,4 +6,4 @@ ConditionPathExists=/ostree
Type=dbus Type=dbus
BusName=org.projectatomic.rpmostree1 BusName=org.projectatomic.rpmostree1
@SYSTEMD_ENVIRON@ @SYSTEMD_ENVIRON@
ExecStart=@libexecdir@/@primaryname@d ExecStart=@bindir@/rpm-ostree internals start-daemon

View File

@ -25,7 +25,7 @@ set -e
# libtest.sh should have added the builddir which contains rpm-ostreed to our # libtest.sh should have added the builddir which contains rpm-ostreed to our
# path # path
exec_binary="$(which rpm-ostreed)" exec_binary="$(which rpm-ostree)"
mkdir -p sysroot mkdir -p sysroot
mkdir -p session-services mkdir -p session-services
@ -56,7 +56,7 @@ EOF
cat > session-services/rpmostree.service <<EOF cat > session-services/rpmostree.service <<EOF
[D-BUS Service] [D-BUS Service]
Name=org.projectatomic.rpmostree1 Name=org.projectatomic.rpmostree1
Exec=${exec_binary} --debug --sysroot=${test_tmpdir}/sysroot Exec=${exec_binary} internals start-daemon --debug --sysroot=${test_tmpdir}/sysroot
EOF EOF
# Tell rpm-ostree to connect to the session bus instead of system # Tell rpm-ostree to connect to the session bus instead of system

View File

@ -18,7 +18,7 @@ if test -z "${INSIDE_VM:-}"; then
DESTDIR=$(pwd)/insttree DESTDIR=$(pwd)/insttree
make install DESTDIR=${DESTDIR} make install DESTDIR=${DESTDIR}
for san in a t ub; do for san in a t ub; do
if eu-readelf -d ${DESTDIR}/usr/libexec/rpm-ostreed | grep -q "NEEDED.*lib${san}san"; then if eu-readelf -d ${DESTDIR}/usr/bin/rpm-ostree | grep -q "NEEDED.*lib${san}san"; then
echo "Installing extra sanitizier: lib${san}san" echo "Installing extra sanitizier: lib${san}san"
cp /usr/lib64/lib${san}san*.so.* ${DESTDIR}/usr/lib64 cp /usr/lib64/lib${san}san*.so.* ${DESTDIR}/usr/lib64
fi fi

View File

@ -27,6 +27,7 @@ else
set -x set -x
ostree admin unlock || : ostree admin unlock || :
rsync -rlv /var/roothome/sync/insttree/usr/ /usr/ rsync -rlv /var/roothome/sync/insttree/usr/ /usr/
restorecon /usr/libexec/rpm-ostreed restorecon -v /usr/bin/rpm-ostree
restorecon -v /usr/libexec/rpm-ostreed
systemctl restart rpm-ostreed systemctl restart rpm-ostreed
fi fi