[systemd-commits] 23 commits - .gitignore Makefile.am man/hostname.xml man/machine-id.xml man/machine-info.xml man/os-release.xml man/systemd-ask-password.xml man/systemd.unit.xml src/ask-password.c src/automount.c src/cgroups-agent.c src/cryptsetup.c src/cryptsetup-generator.c src/dbus-automount.c src/dbus.c src/dbus-common.c src/dbus-common.h src/dbus-device.c src/dbus-execute.c src/dbus-execute.h src/dbus.h src/dbus-job.c src/dbus-manager.c src/dbus-mount.c src/dbus-path.c src/dbus-service.c src/dbus-snapshot.c src/dbus-socket.c src/dbus-swap.c src/dbus-target.c src/dbus-timer.c src/dbus-unit.c src/dbus-unit.h src/def.h src/device.c src/getty-generator.c src/hostnamed.c src/hostname-setup.c src/initctl.c src/load-fragment.c src/logger.c src/manager.c src/mount.c src/org.freedesktop.hostname1.conf src/org.freedesktop.hostname1.policy src/org.freedesktop.hostname1.service src/strv.c src/strv.h src/swap.c src/unit.c src/unit.h src/util.c src/util.h units/emergency.service units/fsck-r oot.service.in units/.gitignore units/quotacheck.service.in units/remount-rootfs.service units/rescue.service.m4 units/syslog.target units/systemd-hostnamed.service.in units/systemd-kmsg-syslogd.service.in units/systemd-logger.service.in units/systemd-logger.socket units/systemd-shutdownd.service.in units/systemd-update-utmp-runlevel.service.in units/systemd-update-utmp-shutdown.service.in
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Apr 15 17:04:52 PDT 2011
.gitignore | 1
Makefile.am | 38 +
man/hostname.xml | 13
man/machine-id.xml | 6
man/machine-info.xml | 147 +++++
man/os-release.xml | 9
man/systemd-ask-password.xml | 3
man/systemd.unit.xml | 10
src/ask-password.c | 3
src/automount.c | 2
src/cgroups-agent.c | 2
src/cryptsetup-generator.c | 18
src/cryptsetup.c | 2
src/dbus-automount.c | 3
src/dbus-common.c | 447 ++++++++++++++++
src/dbus-common.h | 119 ++++
src/dbus-device.c | 3
src/dbus-execute.c | 39 -
src/dbus-execute.h | 30 -
src/dbus-job.c | 10
src/dbus-manager.c | 105 ++-
src/dbus-mount.c | 13
src/dbus-path.c | 9
src/dbus-service.c | 3
src/dbus-snapshot.c | 4
src/dbus-socket.c | 3
src/dbus-swap.c | 6
src/dbus-target.c | 3
src/dbus-timer.c | 9
src/dbus-unit.c | 58 --
src/dbus-unit.h | 36 -
src/dbus.c | 459 -----------------
src/dbus.h | 108 ----
src/def.h | 2
src/device.c | 3
src/getty-generator.c | 1
src/hostname-setup.c | 37 -
src/hostnamed.c | 689 ++++++++++++++++++++++++++
src/initctl.c | 5
src/load-fragment.c | 1
src/logger.c | 5
src/manager.c | 26
src/mount.c | 3
src/org.freedesktop.hostname1.conf | 27 +
src/org.freedesktop.hostname1.policy | 49 +
src/org.freedesktop.hostname1.service | 12
src/strv.c | 50 +
src/strv.h | 1
src/swap.c | 3
src/unit.c | 6
src/unit.h | 6
src/util.c | 156 +++++
src/util.h | 11
units/.gitignore | 1
units/emergency.service | 2
units/fsck-root.service.in | 2
units/quotacheck.service.in | 2
units/remount-rootfs.service | 2
units/rescue.service.m4 | 2
units/syslog.target | 5
units/systemd-hostnamed.service.in | 16
units/systemd-kmsg-syslogd.service.in | 1
units/systemd-logger.service.in | 1
units/systemd-logger.socket | 7
units/systemd-shutdownd.service.in | 2
units/systemd-update-utmp-runlevel.service.in | 1
units/systemd-update-utmp-shutdown.service.in | 1
67 files changed, 2015 insertions(+), 844 deletions(-)
New commits:
commit 7640a5de1b3ffe6547200ad204d14e4f067caf4f
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 02:02:54 2011 +0200
hostnamed: introduce systemd-hostnamed
http://www.freedesktop.org/wiki/Software/systemd/hostnamed
diff --git a/.gitignore b/.gitignore
index be44cb6..5669d74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+systemd-hostnamed
systemd-binfmt
systemd-getty-generator
systemd-nspawn
diff --git a/Makefile.am b/Makefile.am
index db28572..26412ab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -144,7 +144,8 @@ rootlibexec_PROGRAMS = \
systemd-ac-power \
systemd-detect-virt \
systemd-sysctl \
- systemd-binfmt
+ systemd-binfmt \
+ systemd-hostnamed
systemgenerator_PROGRAMS = \
systemd-getty-generator
@@ -177,10 +178,12 @@ dist_pkgsysconf_DATA = \
src/system.conf
dist_dbuspolicy_DATA = \
- src/org.freedesktop.systemd1.conf
+ src/org.freedesktop.systemd1.conf \
+ src/org.freedesktop.hostname1.conf
dist_dbussystemservice_DATA = \
- src/org.freedesktop.systemd1.service
+ src/org.freedesktop.systemd1.service \
+ src/org.freedesktop.hostname1.service
dist_udevrules_DATA = \
src/99-systemd.rules
@@ -282,6 +285,7 @@ nodist_systemunit_DATA = \
units/systemd-initctl.service \
units/systemd-logger.service \
units/systemd-shutdownd.service \
+ units/systemd-hostnamed.service \
units/systemd-kmsg-syslogd.service \
units/systemd-modules-load.service \
units/systemd-vconsole-setup.service \
@@ -326,6 +330,7 @@ EXTRA_DIST = \
units/systemd-initctl.service.in \
units/systemd-logger.service.in \
units/systemd-shutdownd.service.in \
+ units/systemd-hostnamed.service.in \
units/systemd-kmsg-syslogd.service.in \
units/systemd-modules-load.service.in \
units/systemd-vconsole-setup.service.in \
@@ -406,9 +411,12 @@ dist_doc_DATA = \
pkgconfigdata_DATA = \
systemd.pc
-polkitpolicy_DATA = \
+nodist_polkitpolicy_DATA = \
src/org.freedesktop.systemd1.policy
+dist_polkitpolicy_DATA = \
+ src/org.freedesktop.hostname1.policy
+
noinst_LTLIBRARIES = \
libsystemd-basic.la \
libsystemd-core.la \
@@ -571,6 +579,7 @@ MANPAGES = \
man/vconsole.conf.5 \
man/locale.conf.5 \
man/os-release.5 \
+ man/machine-info.5 \
man/modules-load.d.5 \
man/binfmt.d.5 \
man/sysctl.d.5 \
@@ -754,6 +763,19 @@ systemd_shutdownd_LDADD = \
libsystemd-basic.la \
libsystemd-daemon.la
+systemd_hostnamed_SOURCES = \
+ src/hostnamed.c \
+ src/dbus-common.c
+
+systemd_hostnamed_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(DBUS_CFLAGS)
+
+systemd_hostnamed_LDADD = \
+ libsystemd-basic.la \
+ libsystemd-daemon.la \
+ $(DBUS_LIBS)
+
systemd_shutdown_SOURCES = \
src/mount-setup.c \
src/umount.c \
@@ -1346,9 +1368,10 @@ install-data-hook:
$(LN_S) graphical.target runlevel5.target && \
$(LN_S) reboot.target runlevel6.target )
( cd $(DESTDIR)$(systemunitdir) && \
- rm -f default.target ctrl-alt-del.target && \
+ rm -f default.target ctrl-alt-del.target dbus-org.freedesktop.hostname1.service && \
$(LN_S) graphical.target default.target && \
- $(LN_S) reboot.target ctrl-alt-del.target )
+ $(LN_S) reboot.target ctrl-alt-del.target && \
+ $(LN_S) systemd-hostnamed.service dbus-org.freedesktop.hostname1.service )
( cd $(DESTDIR)$(systemunitdir)/multi-user.target.wants && \
rm -f getty.target systemd-user-sessions.service systemd-ask-password-wall.path && \
$(LN_S) ../getty.target getty.target && \
diff --git a/man/hostname.xml b/man/hostname.xml
index f226ef0..b8b05c8 100644
--- a/man/hostname.xml
+++ b/man/hostname.xml
@@ -44,7 +44,7 @@
<refnamediv>
<refname>hostname</refname>
- <refpurpose>local host name configuration file</refpurpose>
+ <refpurpose>Local host name configuration file</refpurpose>
</refnamediv>
<refsynopsisdiv>
@@ -62,10 +62,10 @@
newline-terminated host name string. The
host name may be a free-form string up to 64 characters
in length, however it is recommended that it consists
- only of 7bit ASCII characters and no spaces or dots,
- and limit itself to the format allowed for DNS domain
+ only of 7bit ASCII lower-case characters and no spaces or dots,
+ and limits itself to the format allowed for DNS domain
name labels, even though this is not a
- requirement.</para>
+ strict requirement.</para>
<para>Depending on the operating system other
configuration files might be checked for configuration
@@ -85,7 +85,10 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
diff --git a/man/machine-id.xml b/man/machine-id.xml
index fefeb66..98c0943 100644
--- a/man/machine-id.xml
+++ b/man/machine-id.xml
@@ -76,7 +76,7 @@
with a globally unique ID in the network, that does
not change even if the local network configuration
changes. Due to this and its greater length it is
- a more useful replacement than the
+ a more useful replacement for the
<citerefentry><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call POSIX specifies.</para>
</refsect1>
@@ -97,7 +97,9 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
diff --git a/man/machine-info.xml b/man/machine-info.xml
new file mode 100644
index 0000000..c6d3e92
--- /dev/null
+++ b/man/machine-info.xml
@@ -0,0 +1,147 @@
+<?xml version='1.0'?> <!--*-nxml-*-->
+<?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<!--
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd 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.
+
+ systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<refentry id="machine-info">
+ <refentryinfo>
+ <title>machine-info</title>
+ <productname>systemd</productname>
+
+ <authorgroup>
+ <author>
+ <contrib>Developer</contrib>
+ <firstname>Lennart</firstname>
+ <surname>Poettering</surname>
+ <email>lennart at poettering.net</email>
+ </author>
+ </authorgroup>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>machine-info</refentrytitle>
+ <manvolnum>5</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>machine-info</refname>
+ <refpurpose>Local machine information file</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <para><filename>/etc/machine-info</filename></para>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para>The <filename>/etc/machine-info</filename> file
+ contains machine meta data.</para>
+
+ <para>The basic file format of
+ <filename>machine-info</filename> is a
+ newline-separated list of environment-like
+ shell-compatible variable assignments. It is possible
+ to source the configuration from shell scripts,
+ however, beyond mere variable assignments no shell
+ features are supported, allowing applications to read
+ the file without implementing a shell compatible
+ execution engine.</para>
+
+ <para><filename>/etc/machine-info</filename> contains
+ meta data about the machine that is set by the user or
+ administrator.</para>
+
+ <para>Depending on the operating system other
+ configuration files might be checked for machine
+ information as well, however only as fallback.</para>
+ </refsect1>
+
+ <refsect1>
+ <title>Options</title>
+
+ <para>The following machine meta data parameters may
+ be set using
+ <filename>/etc/machine-info</filename>:</para>
+
+ <variablelist>
+
+ <varlistentry>
+ <term><varname>PRETTY_HOSTNAME=</varname></term>
+
+ <listitem><para>A pretty
+ human-readable UTF8 machine identifier
+ string. This should contain a name
+ like <literal>Lennart's
+ Laptop</literal> which is useful to
+ present to the user and does not
+ suffer by the syntax limitations of
+ internet domain names. If possible the
+ internet host name as configured in
+ <filename>/etc/hostname</filename>
+ should be kept similar to this
+ one. Example: if this value is
+ <literal>Lennart's Computer</literal>
+ an Internet host name of
+ <literal>lennarts-computer</literal>
+ might be a good choice. If this
+ parameter is not set an application
+ should fall back to the Internet host
+ name for presentation
+ purposes.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>ICON_NAME=</varname></term>
+
+ <listitem><para>An icon identifying
+ this machine according to the <ulink
+ url="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html">XDG
+ Icon Naming Specification</ulink>. If
+ this parameter is not set an
+ application should fall back to
+ <literal>computer</literal> or a
+ similar icon name.</para></listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1>
+ <title>Example</title>
+
+ <programlisting>PRETTY_NAME="Lennart's Computer"
+ICON_NAME=computer-laptop</programlisting>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+ <para>
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ </para>
+ </refsect1>
+
+</refentry>
diff --git a/man/os-release.xml b/man/os-release.xml
index 759c04d..1e4c067 100644
--- a/man/os-release.xml
+++ b/man/os-release.xml
@@ -182,10 +182,10 @@
<title>Example</title>
<programlisting>NAME=Fedora
-VERSION=15 (Rawhide)
+VERSION="15 (Rawhide)"
ID=fedora
VERSION_ID=15
-PRETTY_NAME=Fedora 15 (Rawhide)
+PRETTY_NAME="Fedora 15 (Rawhide)"
ANSI_COLOR=0;34</programlisting>
</refsect1>
@@ -193,7 +193,10 @@ ANSI_COLOR=0;34</programlisting>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>lsb_release</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>lsb_release</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
diff --git a/src/hostnamed.c b/src/hostnamed.c
new file mode 100644
index 0000000..4ba1d4a
--- /dev/null
+++ b/src/hostnamed.c
@@ -0,0 +1,689 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd 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.
+
+ systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <dbus/dbus.h>
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "util.h"
+#include "strv.h"
+#include "dbus-common.h"
+
+#define INTROSPECTION \
+ DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
+ "<node>\n" \
+ " <interface name=\"org.freedesktop.hostname1\">\n" \
+ " <property name=\"Hostname\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"StaticHostname\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"PrettyHostname\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"IconName\" type=\"s\" access=\"read\"/>\n" \
+ " <method name=\"SetHostname\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"SetStaticHostname\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"SetPrettyHostname\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"SetIconName\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " </interface>\n" \
+ BUS_PROPERTIES_INTERFACE \
+ BUS_INTROSPECTABLE_INTERFACE \
+ BUS_PEER_INTERFACE \
+ "</node>\n"
+
+#define INTERFACES_LIST \
+ BUS_GENERIC_INTERFACES_LIST \
+ "org.freedesktop.hostname1\0"
+
+enum {
+ PROP_HOSTNAME,
+ PROP_STATIC_HOSTNAME,
+ PROP_PRETTY_HOSTNAME,
+ PROP_ICON_NAME,
+ _PROP_MAX
+};
+
+static char *data[_PROP_MAX] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+static void free_data(void) {
+ int p;
+
+ for (p = 0; p < _PROP_MAX; p++) {
+ free(data[p]);
+ data[p] = NULL;
+ }
+}
+
+static int read_data(void) {
+ int r;
+
+ free_data();
+
+ data[PROP_HOSTNAME] = gethostname_malloc();
+ if (!data[PROP_HOSTNAME])
+ return -ENOMEM;
+
+ r = read_one_line_file("/etc/hostname", &data[PROP_STATIC_HOSTNAME]);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
+ r = parse_env_file("/etc/machine-info", NEWLINE,
+ "PRETTY_HOSTNAME", &data[PROP_PRETTY_HOSTNAME],
+ "ICON_NAME", &data[PROP_ICON_NAME],
+ NULL);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
+ return 0;
+}
+
+static const char* fallback_icon_name(void) {
+
+#if defined(__i386__) || defined(__x86_64__)
+ int r;
+ char *type;
+ unsigned t;
+#endif
+
+ if (detect_virtualization(NULL) > 0)
+ return "computer-vm";
+
+#if defined(__i386__) || defined(__x86_64__)
+ r = read_one_line_file("/sys/class/dmi/id/chassis_type", &type);
+ if (r < 0)
+ return NULL;
+
+ r = safe_atou(type, &t);
+ free(type);
+
+ if (r < 0)
+ return NULL;
+
+ /* We only list the really obvious cases here. The DMI data is
+ unreliable enough, so let's not do any additional guesswork
+ on top of that. */
+
+ switch (t) {
+
+ case 0x3:
+ case 0x4:
+ case 0x6:
+ case 0x7:
+ return "computer-desktop";
+
+ case 0x9:
+ case 0xA:
+ case 0xE:
+ return "computer-laptop";
+
+ case 0x11:
+ return "computer-server";
+ }
+
+#endif
+ return NULL;
+}
+
+static int write_data_hostname(void) {
+ const char *hn;
+
+ if (isempty(data[PROP_HOSTNAME]))
+ hn = "localhost";
+ else
+ hn = data[PROP_HOSTNAME];
+
+ if (sethostname(hn, strlen(hn)) < 0)
+ return -errno;
+
+ return 0;
+}
+
+static int write_data_static_hostname(void) {
+
+ if (isempty(data[PROP_STATIC_HOSTNAME])) {
+
+ if (unlink("/etc/hostname") < 0)
+ return errno == ENOENT ? 0 : -errno;
+
+ return 0;
+ }
+
+ return write_one_line_file("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
+}
+
+static int write_data_other(void) {
+ static const char * const name[_PROP_MAX] = {
+ [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
+ [PROP_ICON_NAME] = "ICON_NAME"
+ };
+
+ char **l = NULL;
+ int r, p;
+
+ r = load_env_file("/etc/machine-info", &l);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
+ for (p = 2; p < _PROP_MAX; p++) {
+ char *t, **u;
+
+ assert(name[p]);
+
+ if (isempty(data[p])) {
+ l = strv_env_unset(l, name[p]);
+ continue;
+ }
+
+ if (asprintf(&t, "%s=%s", name[p], strempty(data[p])) < 0) {
+ strv_free(l);
+ return -ENOMEM;
+ }
+
+ u = strv_env_set(l, t);
+ free(t);
+ strv_free(l);
+
+ if (!u)
+ return -ENOMEM;
+ l = u;
+ }
+
+ if (strv_isempty(l)) {
+
+ if (unlink("/etc/machine-info") < 0)
+ return errno == ENOENT ? 0 : -errno;
+
+ return 0;
+ }
+
+ r = write_env_file("/etc/machine-info", l);
+ strv_free(l);
+
+ return r;
+}
+
+/* This mimics dbus_bus_get_unix_user() */
+static pid_t get_unix_process_id(
+ DBusConnection *connection,
+ const char *name,
+ DBusError *error) {
+
+ DBusMessage *m = NULL, *reply = NULL;
+ uint32_t pid = 0;
+
+ m = dbus_message_new_method_call(
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "GetConnectionUnixProcessID");
+ if (!m) {
+ dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto finish;
+ }
+
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID)) {
+ dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto finish;
+ }
+
+ reply = dbus_connection_send_with_reply_and_block(connection, m, -1, error);
+ if (!reply)
+ goto finish;
+
+ if (dbus_set_error_from_message(error, reply))
+ goto finish;
+
+ if (!dbus_message_get_args(
+ reply, error,
+ DBUS_TYPE_UINT32, &pid,
+ DBUS_TYPE_INVALID))
+ goto finish;
+
+finish:
+ if (m)
+ dbus_message_unref(m);
+
+ if (reply)
+ dbus_message_unref(reply);
+
+ return (pid_t) pid;
+}
+
+static int verify_polkit(
+ DBusConnection *c,
+ DBusMessage *request,
+ const char *action,
+ bool interactive,
+ DBusError *error) {
+
+ DBusMessage *m = NULL, *reply = NULL;
+ const char *unix_process = "unix-process", *pid = "pid", *starttime = "start-time", *cancel_id = "";
+ const char *sender;
+ uint32_t flags = interactive ? 1 : 0;
+ pid_t pid_raw;
+ uint32_t pid_u32;
+ unsigned long long starttime_raw;
+ uint64_t starttime_u64;
+ DBusMessageIter iter_msg, iter_struct, iter_array, iter_dict, iter_variant;
+ int r;
+ dbus_bool_t authorized = FALSE;
+
+ assert(c);
+ assert(request);
+
+ sender = dbus_message_get_sender(request);
+ if (!sender)
+ return -EINVAL;
+
+ pid_raw = get_unix_process_id(c, sender, error);
+ if (pid_raw == 0)
+ return -EINVAL;
+
+ r = get_starttime_of_pid(pid_raw, &starttime_raw);
+ if (r < 0)
+ return r;
+
+ m = dbus_message_new_method_call(
+ "org.freedesktop.PolicyKit1",
+ "/org/freedesktop/PolicyKit1/Authority",
+ "org.freedesktop.PolicyKit1.Authority",
+ "CheckAuthorization");
+ if (!m)
+ return -ENOMEM;
+
+ dbus_message_iter_init_append(m, &iter_msg);
+
+ pid_u32 = (uint32_t) pid_raw;
+ starttime_u64 = (uint64_t) starttime_raw;
+
+ if (!dbus_message_iter_open_container(&iter_msg, DBUS_TYPE_STRUCT, NULL, &iter_struct) ||
+ !dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &unix_process) ||
+ !dbus_message_iter_open_container(&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_array) ||
+ !dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
+ !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &pid) ||
+ !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "u", &iter_variant) ||
+ !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT32, &pid_u32) ||
+ !dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
+ !dbus_message_iter_close_container(&iter_array, &iter_dict) ||
+ !dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
+ !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &starttime) ||
+ !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "t", &iter_variant) ||
+ !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT64, &starttime_u64) ||
+ !dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
+ !dbus_message_iter_close_container(&iter_array, &iter_dict) ||
+ !dbus_message_iter_close_container(&iter_struct, &iter_array) ||
+ !dbus_message_iter_close_container(&iter_msg, &iter_struct) ||
+ !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_STRING, &action) ||
+ !dbus_message_iter_open_container(&iter_msg, DBUS_TYPE_ARRAY, "{ss}", &iter_array) ||
+ !dbus_message_iter_close_container(&iter_msg, &iter_array) ||
+ !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_UINT32, &flags) ||
+ !dbus_message_iter_append_basic(&iter_msg, DBUS_TYPE_STRING, &cancel_id)) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ reply = dbus_connection_send_with_reply_and_block(c, m, -1, error);
+ if (!reply) {
+ r = -EIO;
+ goto finish;
+ }
+
+ if (dbus_set_error_from_message(error, reply)) {
+ r = -EIO;
+ goto finish;
+ }
+
+ if (!dbus_message_iter_init(reply, &iter_msg) ||
+ dbus_message_iter_get_arg_type(&iter_msg) != DBUS_TYPE_STRUCT) {
+ r = -EIO;
+ goto finish;
+ }
+
+ dbus_message_iter_recurse(&iter_msg, &iter_struct);
+
+ if (dbus_message_iter_get_arg_type(&iter_struct) != DBUS_TYPE_BOOLEAN) {
+ r = -EIO;
+ goto finish;
+ }
+
+ dbus_message_iter_get_basic(&iter_struct, &authorized);
+
+ r = authorized ? 0 : -EPERM;
+
+finish:
+
+ if (m)
+ dbus_message_unref(m);
+
+ if (reply)
+ dbus_message_unref(reply);
+
+ return r;
+}
+
+static int bus_hostname_append_icon_name(DBusMessageIter *i, const char *property, void *userdata) {
+ const char *name;
+
+ assert(i);
+ assert(property);
+
+ if (isempty(data[PROP_ICON_NAME]))
+ name = fallback_icon_name();
+ else
+ name = data[PROP_ICON_NAME];
+
+ return bus_property_append_string(i, property, (void*) name);
+}
+
+static DBusHandlerResult hostname_message_handler(
+ DBusConnection *connection,
+ DBusMessage *message,
+ void *userdata) {
+
+ const BusProperty properties[] = {
+ { "org.freedesktop.hostname1", "Hostname", bus_property_append_string, "s", data[PROP_HOSTNAME]},
+ { "org.freedesktop.hostname1", "StaticHostname", bus_property_append_string, "s", data[PROP_STATIC_HOSTNAME]},
+ { "org.freedesktop.hostname1", "PrettyHostname", bus_property_append_string, "s", data[PROP_PRETTY_HOSTNAME]},
+ { "org.freedesktop.hostname1", "IconName", bus_hostname_append_icon_name, "s", data[PROP_ICON_NAME]},
+ { NULL, NULL, NULL, NULL, NULL }
+ };
+
+ DBusMessage *reply = NULL, *changed = NULL;
+ DBusError error;
+ int r;
+
+ assert(connection);
+ assert(message);
+
+ dbus_error_init(&error);
+
+ if (dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetHostname")) {
+ const char *name;
+ dbus_bool_t interactive;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_BOOLEAN, &interactive,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
+
+ if (isempty(name))
+ name = data[PROP_STATIC_HOSTNAME];
+
+ if (isempty(name))
+ name = "localhost";
+
+ if (!hostname_is_valid(name))
+ return bus_send_error_reply(connection, message, NULL, -EINVAL);
+
+ if (!streq_ptr(name, data[PROP_HOSTNAME])) {
+ char *h;
+
+ r = verify_polkit(connection, message, "org.freedesktop.hostname1.set-hostname", interactive, &error);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ h = strdup(name);
+ if (!h)
+ goto oom;
+
+ free(data[PROP_HOSTNAME]);
+ data[PROP_HOSTNAME] = h;
+
+ r = write_data_hostname();
+ if (r < 0)
+ return bus_send_error_reply(connection, message, NULL, r);
+
+ log_info("Changed host name to '%s'", data[PROP_HOSTNAME]);
+
+ changed = bus_properties_changed_new(
+ "/org/freedesktop/hostname1",
+ "org.freedesktop.hostname1",
+ "Hostname\0");
+ if (!changed)
+ goto oom;
+ }
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetStaticHostname")) {
+ const char *name;
+ dbus_bool_t interactive;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_BOOLEAN, &interactive,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
+
+ if (isempty(name))
+ name = NULL;
+
+ if (!streq_ptr(name, data[PROP_STATIC_HOSTNAME])) {
+
+ r = verify_polkit(connection, message, "org.freedesktop.hostname1.set-static-hostname", interactive, &error);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ if (isempty(name)) {
+ free(data[PROP_STATIC_HOSTNAME]);
+ data[PROP_STATIC_HOSTNAME] = NULL;
+ } else {
+ char *h;
+
+ if (!hostname_is_valid(name))
+ return bus_send_error_reply(connection, message, NULL, -EINVAL);
+
+ h = strdup(name);
+ if (!h)
+ goto oom;
+
+ free(data[PROP_STATIC_HOSTNAME]);
+ data[PROP_STATIC_HOSTNAME] = h;
+ }
+
+ r = write_data_static_hostname();
+ if (r < 0)
+ return bus_send_error_reply(connection, message, NULL, r);
+
+ log_info("Changed static host name to '%s'", data[PROP_HOSTNAME]);
+
+ changed = bus_properties_changed_new(
+ "/org/freedesktop/hostname1",
+ "org.freedesktop.hostname1",
+ "StaticHostname\0");
+ if (!changed)
+ goto oom;
+ }
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetPrettyHostname") ||
+ dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetIconName")) {
+
+ const char *name;
+ dbus_bool_t interactive;
+ int k;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_BOOLEAN, &interactive,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
+
+ if (isempty(name))
+ name = NULL;
+
+ k = streq(dbus_message_get_member(message), "SetPrettyHostname") ? PROP_PRETTY_HOSTNAME : PROP_ICON_NAME;
+
+ if (!streq_ptr(name, data[k])) {
+
+ r = verify_polkit(connection, message, "org.freedesktop.hostname1.set-machine-info", interactive, &error);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ if (isempty(name)) {
+ free(data[k]);
+ data[k] = NULL;
+ } else {
+ char *h;
+
+ h = strdup(name);
+ if (!h)
+ goto oom;
+
+ free(data[k]);
+ data[k] = h;
+ }
+
+ r = write_data_other();
+ if (r < 0)
+ return bus_send_error_reply(connection, message, NULL, r);
+
+ log_info("Changed %s to '%s'", k == PROP_PRETTY_HOSTNAME ? "pretty host name" : "icon name", data[k]);
+
+ changed = bus_properties_changed_new(
+ "/org/freedesktop/hostname1",
+ "org.freedesktop.hostname1",
+ k == PROP_PRETTY_HOSTNAME ? "PrettyHostname\0" : "IconName\0");
+ if (!changed)
+ goto oom;
+ }
+
+ } else
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ if (!dbus_connection_send(connection, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+ reply = NULL;
+
+ if (changed) {
+
+ if (!dbus_connection_send(connection, changed, NULL))
+ goto oom;
+
+ dbus_message_unref(changed);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ if (changed)
+ dbus_message_unref(changed);
+
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+int main(int argc, char *argv[]) {
+ const DBusObjectPathVTable hostname_vtable = {
+ .message_function = hostname_message_handler
+ };
+
+ DBusConnection *bus = NULL;
+ DBusError error;
+ int r;
+
+ dbus_error_init(&error);
+
+ log_set_target(LOG_TARGET_AUTO);
+ log_parse_environment();
+ log_open();
+
+ if (argc != 1) {
+ log_error("This program takes no arguments.");
+ r = -EINVAL;
+ goto finish;
+ }
+
+ umask(0022);
+
+ r = read_data();
+ if (r < 0) {
+ log_error("Failed to read hostname data: %s", strerror(-r));
+ goto finish;
+ }
+
+ bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ log_error("Failed to get system D-Bus connection: %s", error.message);
+ r = -ECONNREFUSED;
+ goto finish;
+ }
+
+ if (!dbus_connection_register_object_path(bus, "/org/freedesktop/hostname1", &hostname_vtable, NULL)) {
+ log_error("Not enough memory");
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (dbus_bus_request_name(bus, "org.freedesktop.hostname1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
+ log_error("Failed to register name on bus: %s", error.message);
+ goto finish;
+ }
+
+ while (dbus_connection_read_write_dispatch(bus, -1))
+ ;
+
+ r = 0;
+
+finish:
+ free_data();
+
+ if (bus) {
+ dbus_connection_flush(bus);
+ dbus_connection_close(bus);
+ dbus_connection_unref(bus);
+ }
+
+ dbus_error_free(&error);
+
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/src/org.freedesktop.hostname1.conf b/src/org.freedesktop.hostname1.conf
new file mode 100644
index 0000000..eb241c0
--- /dev/null
+++ b/src/org.freedesktop.hostname1.conf
@@ -0,0 +1,27 @@
+<?xml version="1.0"?> <!--*-nxml-*-->
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+
+<!--
+ This file is part of systemd.
+
+ systemd 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.
+-->
+
+<busconfig>
+
+ <policy user="root">
+ <allow own="org.freedesktop.hostname1"/>
+ <allow send_destination="org.freedesktop.hostname1"/>
+ <allow receive_sender="org.freedesktop.hostname1"/>
+ </policy>
+
+ <policy context="default">
+ <allow send_destination="org.freedesktop.hostname1"/>
+ <allow receive_sender="org.freedesktop.hostname1"/>
+ </policy>
+
+</busconfig>
diff --git a/src/org.freedesktop.hostname1.policy b/src/org.freedesktop.hostname1.policy
new file mode 100644
index 0000000..148874f
--- /dev/null
+++ b/src/org.freedesktop.hostname1.policy
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?> <!--*-nxml-*-->
+<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
+
+<!--
+ This file is part of systemd.
+
+ systemd 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.
+-->
+
+<policyconfig>
+
+ <vendor>The systemd Project</vendor>
+ <vendor_url>http://www.freedesktop.org/wiki/Software/systemd</vendor_url>
+
+ <action id="org.freedesktop.hostname1.set-hostname">
+ <description>Set host name</description>
+ <message>Authentication is required to set the local host name.</message>
+ <defaults>
+ <allow_any>auth_admin_keep</allow_any>
+ <allow_inactive>auth_admin_keep</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.hostname1.set-static-hostname">
+ <description>Set static host name</description>
+ <message>Authentication is required to set the statically configured local host name.</message>
+ <defaults>
+ <allow_any>auth_admin_keep</allow_any>
+ <allow_inactive>auth_admin_keep</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.hostname1.set-machine-info">
+ <description>Set machine information</description>
+ <message>Authentication is required to set local machine information.</message>
+ <defaults>
+ <allow_any>auth_admin_keep</allow_any>
+ <allow_inactive>auth_admin_keep</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
+</policyconfig>
diff --git a/src/org.freedesktop.hostname1.service b/src/org.freedesktop.hostname1.service
new file mode 100644
index 0000000..42e4adb
--- /dev/null
+++ b/src/org.freedesktop.hostname1.service
@@ -0,0 +1,12 @@
+# This file is part of systemd.
+#
+# systemd 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.
+
+[D-BUS Service]
+Name=org.freedesktop.hostname1
+Exec=/bin/false
+User=root
+SystemdService=dbus-org.freedesktop.hostname1.service
diff --git a/src/strv.c b/src/strv.c
index 1c15ee8..71b77c9 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -525,6 +525,32 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) {
return r;
}
+char **strv_env_unset(char **l, const char *p) {
+
+ char **f, **t;
+
+ if (!l)
+ return NULL;
+
+ assert(p);
+
+ /* Drops every occurrence of the env var setting p in the
+ * string list. edits in-place. */
+
+ for (f = t = l; *f; f++) {
+
+ if (env_match(*f, p)) {
+ free(*f);
+ continue;
+ }
+
+ *(t++) = *f;
+ }
+
+ *t = NULL;
+ return l;
+}
+
char **strv_env_set(char **x, const char *p) {
char **k, **r;
diff --git a/src/strv.h b/src/strv.h
index 064576c..46436a5 100644
--- a/src/strv.h
+++ b/src/strv.h
@@ -59,6 +59,7 @@ char **strv_env_merge(unsigned n_lists, ...);
char **strv_env_delete(char **x, unsigned n_lists, ...);
char **strv_env_set(char **x, const char *p);
+char **strv_env_unset(char **l, const char *p);
char *strv_env_get_with_length(char **l, const char *name, size_t k);
char *strv_env_get(char **x, const char *n);
diff --git a/src/util.c b/src/util.c
index bec6e0c..c2173c7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -496,6 +496,64 @@ int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
return 0;
}
+int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
+ int r;
+ FILE *f;
+ char fn[PATH_MAX], line[LINE_MAX], *p;
+
+ assert(pid > 0);
+ assert(st);
+
+ assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
+ char_array_0(fn);
+
+ if (!(f = fopen(fn, "r")))
+ return -errno;
+
+ if (!(fgets(line, sizeof(line), f))) {
+ r = -errno;
+ fclose(f);
+ return r;
+ }
+
+ fclose(f);
+
+ /* Let's skip the pid and comm fields. The latter is enclosed
+ * in () but does not escape any () in its value, so let's
+ * skip over it manually */
+
+ if (!(p = strrchr(line, ')')))
+ return -EIO;
+
+ p++;
+
+ if (sscanf(p, " "
+ "%*c " /* state */
+ "%*d " /* ppid */
+ "%*d " /* pgrp */
+ "%*d " /* session */
+ "%*d " /* tty_nr */
+ "%*d " /* tpgid */
+ "%*u " /* flags */
+ "%*u " /* minflt */
+ "%*u " /* cminflt */
+ "%*u " /* majflt */
+ "%*u " /* cmajflt */
+ "%*u " /* utime */
+ "%*u " /* stime */
+ "%*d " /* cutime */
+ "%*d " /* cstime */
+ "%*d " /* priority */
+ "%*d " /* nice */
+ "%*d " /* num_threads */
+ "%*d " /* itrealvalue */
+ "%llu " /* starttime */,
+ st) != 1)
+ return -EIO;
+
+ return 0;
+}
+
int write_one_line_file(const char *fn, const char *line) {
FILE *f;
int r;
@@ -776,6 +834,29 @@ finish:
return r;
}
+int write_env_file(const char *fname, char **l) {
+
+ char **i;
+ FILE *f;
+ int r;
+
+ f = fopen(fname, "we");
+ if (!f)
+ return -errno;
+
+ STRV_FOREACH(i, l) {
+ fputs(*i, f);
+ fputc('\n', f);
+ }
+
+ fflush(f);
+
+ r = ferror(f) ? -errno : 0;
+ fclose(f);
+
+ return r;
+}
+
char *truncate_nl(char *s) {
assert(s);
diff --git a/src/util.h b/src/util.h
index 946179a..fcaeac4 100644
--- a/src/util.h
+++ b/src/util.h
@@ -196,6 +196,7 @@ char *split_quoted(const char *c, size_t *l, char **state);
char **split_path_and_make_absolute(const char *p);
pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
+int get_starttime_of_pid(pid_t pid, unsigned long long *st);
int write_one_line_file(const char *fn, const char *line);
int read_one_line_file(const char *fn, char **line);
@@ -203,6 +204,7 @@ int read_full_file(const char *fn, char **contents);
int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
int load_env_file(const char *fname, char ***l);
+int write_env_file(const char *fname, char **l);
char *strappend(const char *s, const char *suffix);
char *strnappend(const char *s, const char *suffix, size_t length);
diff --git a/units/.gitignore b/units/.gitignore
index cbf9f25..fe23b12 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -1,3 +1,4 @@
+systemd-hostnamed.service
console-shell.service
systemd-sysctl.service
systemd-ask-password-console.service
diff --git a/units/systemd-hostnamed.service.in b/units/systemd-hostnamed.service.in
new file mode 100644
index 0000000..32a3ab5
--- /dev/null
+++ b/units/systemd-hostnamed.service.in
@@ -0,0 +1,16 @@
+# This file is part of systemd.
+#
+# systemd 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.
+
+# See systemd.special(7) for details
+
+[Unit]
+Description=Hostname Service
+
+[Service]
+ExecStart=@rootlibexecdir@/systemd-hostnamed
+Type=dbus
+BusName=org.freedesktop.hostname1
commit 25e3655a00ba41424c95222aba71c543e84fd3e3
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:58:52 2011 +0200
units: wording fix
diff --git a/units/systemd-shutdownd.service.in b/units/systemd-shutdownd.service.in
index 2214caf..657365a 100644
--- a/units/systemd-shutdownd.service.in
+++ b/units/systemd-shutdownd.service.in
@@ -8,7 +8,7 @@
# See systemd.special(7) for details
[Unit]
-Description=Delayed Shutdown Daemon
+Description=Delayed Shutdown Service
DefaultDependencies=no
[Service]
commit 42549a5a6ac5ca2d3e830b3ed1df2dec501bc692
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:58:43 2011 +0200
units: order quotacheck after remount-rootfs
diff --git a/units/fsck-root.service.in b/units/fsck-root.service.in
index 8f4adc4..7b3529d 100644
--- a/units/fsck-root.service.in
+++ b/units/fsck-root.service.in
@@ -9,7 +9,7 @@
Description=File System Check on Root Device
DefaultDependencies=no
After=systemd-readahead-collect.service systemd-readahead-replay.service
-Before=local-fs.target shutdown.target remount-rootfs.service quotacheck.service
+Before=local-fs.target shutdown.target
# Dracut informs us with this flag file if the root fsck was already run
ConditionPathExists=!/run/initramfs/root-fsck
diff --git a/units/quotacheck.service.in b/units/quotacheck.service.in
index ed1ddc5..27dcb1e 100644
--- a/units/quotacheck.service.in
+++ b/units/quotacheck.service.in
@@ -8,7 +8,7 @@
[Unit]
Description=File System Quota Check
DefaultDependencies=no
-After=systemd-readahead-collect.service systemd-readahead-replay.service
+After=systemd-readahead-collect.service systemd-readahead-replay.service remount-rootfs.service
Before=local-fs.target shutdown.target
ConditionPathExists=/sbin/quotacheck
diff --git a/units/remount-rootfs.service b/units/remount-rootfs.service
index 3130901..e95023f 100644
--- a/units/remount-rootfs.service
+++ b/units/remount-rootfs.service
@@ -9,7 +9,7 @@
Description=Remount Root FS
DefaultDependencies=no
Conflicts=shutdown.target
-After=systemd-readahead-collect.service systemd-readahead-replay.service
+After=systemd-readahead-collect.service systemd-readahead-replay.service fsck-root.service
Before=local-fs.target shutdown.target
[Service]
commit 9beb3f4d5c527f995e0e44308d7372fa4ea5470f
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:57:23 2011 +0200
hostname: split out hostname validation into util.c
diff --git a/src/hostname-setup.c b/src/hostname-setup.c
index e9869bb..ab49767 100644
--- a/src/hostname-setup.c
+++ b/src/hostname-setup.c
@@ -40,25 +40,8 @@
#define FILENAME "/etc/conf.d/hostname"
#endif
-static char* strip_bad_chars(char *s) {
- char *p, *d;
-
- for (p = s, d = s; *p; p++)
- if ((*p >= 'a' && *p <= 'z') ||
- (*p >= 'A' && *p <= 'Z') ||
- (*p >= '0' && *p <= '9') ||
- *p == '-' ||
- *p == '_' ||
- *p == '.')
- *(d++) = *p;
-
- *d = 0;
-
- return s;
-}
-
static int read_and_strip_hostname(const char *path, char **hn) {
- char *s, *k;
+ char *s;
int r;
assert(path);
@@ -67,20 +50,14 @@ static int read_and_strip_hostname(const char *path, char **hn) {
if ((r = read_one_line_file(path, &s)) < 0)
return r;
- k = strdup(strstrip(s));
- free(s);
-
- if (!k)
- return -ENOMEM;
-
- strip_bad_chars(k);
+ hostname_cleanup(s);
- if (k[0] == 0) {
- free(k);
+ if (isempty(s)) {
+ free(s);
return -ENOENT;
}
- *hn = k;
+ *hn = s;
return 0;
}
@@ -118,9 +95,9 @@ static int read_distro_hostname(char **hn) {
goto finish;
}
- strip_bad_chars(k);
+ hostname_cleanup(k);
- if (k[0] == 0) {
+ if (isempty(k)) {
free(k);
r = -ENOENT;
goto finish;
diff --git a/src/util.c b/src/util.c
index fb8df84..bec6e0c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -4248,6 +4248,59 @@ int have_effective_cap(int value) {
return r;
}
+char* strshorten(char *s, size_t l) {
+ assert(s);
+
+ if (l < strlen(s))
+ s[l] = 0;
+
+ return s;
+}
+
+static bool hostname_valid_char(char c) {
+ return
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ c == '-' ||
+ c == '_' ||
+ c == '.';
+}
+
+bool hostname_is_valid(const char *s) {
+ const char *p;
+
+ if (isempty(s))
+ return false;
+
+ for (p = s; *p; p++)
+ if (!hostname_valid_char(*p))
+ return false;
+
+ if (p-s > HOST_NAME_MAX)
+ return false;
+
+ return true;
+}
+
+char* hostname_cleanup(char *s) {
+ char *p, *d;
+
+ for (p = s, d = s; *p; p++)
+ if ((*p >= 'a' && *p <= 'z') ||
+ (*p >= 'A' && *p <= 'Z') ||
+ (*p >= '0' && *p <= '9') ||
+ *p == '-' ||
+ *p == '_' ||
+ *p == '.')
+ *(d++) = *p;
+
+ *d = 0;
+
+ strshorten(s, HOST_NAME_MAX);
+ return s;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
diff --git a/src/util.h b/src/util.h
index 72ddd36..946179a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -117,6 +117,10 @@ static inline bool is_path_absolute(const char *p) {
return *p == '/';
}
+static inline bool isempty(const char *p) {
+ return !p || !p[0];
+}
+
bool endswith(const char *s, const char *postfix);
bool startswith(const char *s, const char *prefix);
bool startswith_no_case(const char *s, const char *prefix);
@@ -398,6 +402,11 @@ void parse_syslog_priority(char **p, int *priority);
int have_effective_cap(int value);
+bool hostname_is_valid(const char *s);
+char* hostname_cleanup(char *s);
+
+char* strshorten(char *s, size_t l);
+
#define NULSTR_FOREACH(i, l) \
for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
commit f653f683d8994ca4b33f48d6adf2c6ee3c58e13e
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:56:16 2011 +0200
cryptsetup: simplifications
diff --git a/src/cryptsetup-generator.c b/src/cryptsetup-generator.c
index b57c0b7..f7c3f23 100644
--- a/src/cryptsetup-generator.c
+++ b/src/cryptsetup-generator.c
@@ -33,6 +33,11 @@ static bool has_option(const char *haystack, const char *needle) {
const char *f = haystack;
size_t l;
+ assert(needle);
+
+ if (!haystack)
+ return false;
+
l = strlen(needle);
while ((f = strstr(f, needle))) {
@@ -121,12 +126,12 @@ static int create_disk(
name, u, strempty(password), strempty(options),
name);
- if (options && has_option(options, "tmp"))
+ if (has_option(options, "tmp"))
fprintf(f,
"ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'\n",
name);
- if (options && has_option(options, "swap"))
+ if (has_option(options, "swap"))
fprintf(f,
"ExecStartPost=/sbin/mkswap '/dev/mapper/%s'\n",
name);
@@ -144,7 +149,7 @@ static int create_disk(
goto fail;
}
- if (!options || !has_option(options, "noauto")) {
+ if (!has_option(options, "noauto")) {
if (asprintf(&to, "%s/%s.wants/%s", arg_dest, d, n) < 0) {
r = -ENOMEM;
@@ -162,7 +167,7 @@ static int create_disk(
free(to);
to = NULL;
- if (!options || !has_option(options, "nofail")) {
+ if (!has_option(options, "nofail")) {
if (asprintf(&to, "%s/cryptsetup.target.wants/%s", arg_dest, n) < 0) {
r = -ENOMEM;
commit bfebab7f69cb23f3a488f02bc2be9c8309808221
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:54:49 2011 +0200
dbus: split out object management code into dbus-common, and simplify it
diff --git a/Makefile.am b/Makefile.am
index 6a5c491..db28572 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -481,7 +481,8 @@ libsystemd_core_la_SOURCES = \
src/namespace.c \
src/tcpwrap.c \
src/cgroup-util.c \
- src/condition.c
+ src/condition.c \
+ src/dbus-common.c
libsystemd_core_la_CFLAGS = \
$(AM_CFLAGS) \
diff --git a/src/dbus-automount.c b/src/dbus-automount.c
index eccad37..8268425 100644
--- a/src/dbus-automount.c
+++ b/src/dbus-automount.c
@@ -21,6 +21,7 @@
#include "dbus-unit.h"
#include "dbus-automount.h"
+#include "dbus-common.h"
#define BUS_AUTOMOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Automount\">\n" \
@@ -52,5 +53,5 @@ DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBus
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-common.c b/src/dbus-common.c
index dcce10e..b23373c 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -26,11 +26,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>
+#include <string.h>
#include "log.h"
#include "dbus-common.h"
#include "util.h"
#include "def.h"
+#include "strv.h"
int bus_check_peercred(DBusConnection *c) {
int fd;
@@ -232,3 +234,448 @@ const char *bus_error_message(const DBusError *error) {
return error->message;
}
+
+DBusHandlerResult bus_default_message_handler(
+ DBusConnection *c,
+ DBusMessage *message,
+ const char *introspection,
+ const char *interfaces,
+ const BusProperty *properties) {
+
+ DBusError error;
+ DBusMessage *reply = NULL;
+ int r;
+
+ assert(c);
+ assert(message);
+
+ dbus_error_init(&error);
+
+ if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
+ goto oom;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
+ const char *interface, *property;
+ const BusProperty *p;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_STRING, &property,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+
+ for (p = properties; p->property; p++)
+ if (streq(p->interface, interface) && streq(p->property, property))
+ break;
+
+ if (p->property) {
+ DBusMessageIter iter, sub;
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
+ goto oom;
+
+ if ((r = p->append(&sub, property, (void*) p->data)) < 0) {
+
+ if (r == -ENOMEM)
+ goto oom;
+
+ dbus_message_unref(reply);
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+ } else {
+ if (!nulstr_contains(interfaces, interface))
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ else
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
+
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
+ const char *interface;
+ const BusProperty *p;
+ DBusMessageIter iter, sub, sub2, sub3;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+
+ if (interface[0] && !nulstr_contains(interfaces, interface)) {
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
+ goto oom;
+
+ for (p = properties; p->property; p++) {
+ if (interface[0] && !streq(p->interface, interface))
+ continue;
+
+ if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
+ !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
+ goto oom;
+
+ if ((r = p->append(&sub3, p->property, (void*) p->data)) < 0) {
+
+ if (r == -ENOMEM)
+ goto oom;
+
+ dbus_message_unref(reply);
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!dbus_message_iter_close_container(&sub2, &sub3) ||
+ !dbus_message_iter_close_container(&sub, &sub2))
+ goto oom;
+ }
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && properties) {
+ const char *interface, *property;
+ DBusMessageIter iter;
+ const BusProperty *p;
+
+ if (!dbus_message_iter_init(message, &iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &interface);
+
+ if (!dbus_message_iter_next(&iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &property);
+
+ if (!dbus_message_iter_next(&iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT ||
+ dbus_message_iter_has_next(&iter))
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ for (p = properties; p->property; p++)
+ if (streq(p->interface, interface) && streq(p->property, property))
+ break;
+
+ if (p->set) {
+ DBusMessageIter sub;
+ char *sig;
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ if (!(sig = dbus_message_iter_get_signature(&sub)))
+ goto oom;
+
+ if (!streq(sig, p->signature)) {
+ dbus_free(sig);
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+ }
+
+ dbus_free(sig);
+
+ if ((r = p->set(&sub, property)) < 0) {
+ if (r == -ENOMEM)
+ goto oom;
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+ } else {
+ if (p->property)
+ dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
+ else if (!nulstr_contains(interfaces, interface))
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ else
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
+
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ } else if (!nulstr_contains(interfaces, dbus_message_get_interface(message))) {
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ if (reply) {
+ if (!dbus_connection_send(c, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+int bus_property_append_string(DBusMessageIter *i, const char *property, void *data) {
+ const char *t = data;
+
+ assert(i);
+ assert(property);
+
+ if (!t)
+ t = "";
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data) {
+ DBusMessageIter sub;
+ char **t = data;
+
+ assert(i);
+ assert(property);
+
+ if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
+ return -ENOMEM;
+
+ STRV_FOREACH(t, t)
+ if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t))
+ return -ENOMEM;
+
+ if (!dbus_message_iter_close_container(i, &sub))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data) {
+ bool *b = data;
+ dbus_bool_t db;
+
+ assert(i);
+ assert(property);
+ assert(b);
+
+ db = *b;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ /* Let's ensure that pid_t is actually 64bit, and hence this
+ * function can be used for usec_t */
+ assert_cc(sizeof(uint64_t) == sizeof(usec_t));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ /* Let's ensure that pid_t and mode_t is actually 32bit, and
+ * hence this function can be used for pid_t/mode_t */
+ assert_cc(sizeof(uint32_t) == sizeof(pid_t));
+ assert_cc(sizeof(uint32_t) == sizeof(mode_t));
+ assert_cc(sizeof(uint32_t) == sizeof(unsigned));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ assert_cc(sizeof(int32_t) == sizeof(int));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_size(DBusMessageIter *i, const char *property, void *data) {
+ uint64_t u;
+
+ assert(i);
+ assert(property);
+ assert(data);
+
+ u = (uint64_t) *(size_t*) data;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data) {
+ uint64_t u;
+
+ assert(i);
+ assert(property);
+ assert(data);
+
+ u = (uint64_t) *(unsigned long*) data;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
+const char *bus_errno_to_dbus(int error) {
+
+ switch(error) {
+
+ case -EINVAL:
+ return DBUS_ERROR_INVALID_ARGS;
+
+ case -ENOMEM:
+ return DBUS_ERROR_NO_MEMORY;
+
+ case -EPERM:
+ case -EACCES:
+ return DBUS_ERROR_ACCESS_DENIED;
+
+ case -ESRCH:
+ return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN;
+
+ case -ENOENT:
+ return DBUS_ERROR_FILE_NOT_FOUND;
+
+ case -EEXIST:
+ return DBUS_ERROR_FILE_EXISTS;
+
+ case -ETIMEDOUT:
+ case -ETIME:
+ return DBUS_ERROR_TIMEOUT;
+
+ case -EIO:
+ return DBUS_ERROR_IO_ERROR;
+
+ case -ENETRESET:
+ case -ECONNABORTED:
+ case -ECONNRESET:
+ return DBUS_ERROR_DISCONNECTED;
+ }
+
+ return DBUS_ERROR_FAILED;
+}
+
+DBusHandlerResult bus_send_error_reply(DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
+ DBusMessage *reply = NULL;
+ const char *name, *text;
+
+ if (berror && dbus_error_is_set(berror)) {
+ name = berror->name;
+ text = berror->message;
+ } else {
+ name = bus_errno_to_dbus(error);
+ text = strerror(-error);
+ }
+
+ if (!(reply = dbus_message_new_error(message, name, text)))
+ goto oom;
+
+ if (!dbus_connection_send(c, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+
+ if (berror)
+ dbus_error_free(berror);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ if (berror)
+ dbus_error_free(berror);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties) {
+ DBusMessage *m;
+ DBusMessageIter iter, sub;
+ const char *i;
+
+ assert(interface);
+ assert(properties);
+
+ if (!(m = dbus_message_new_signal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged")))
+ goto oom;
+
+ dbus_message_iter_init_append(m, &iter);
+
+ /* We won't send any property values, since they might be
+ * large and sometimes not cheap to generated */
+
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) ||
+ !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub) ||
+ !dbus_message_iter_close_container(&iter, &sub) ||
+ !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub))
+ goto oom;
+
+ NULSTR_FOREACH(i, properties)
+ if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &i))
+ goto oom;
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+
+ return m;
+
+oom:
+ if (m)
+ dbus_message_unref(m);
+
+ return NULL;
+}
diff --git a/src/dbus-common.h b/src/dbus-common.h
index 76333cd..729519c 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -24,6 +24,65 @@
#include <dbus/dbus.h>
+#ifndef DBUS_ERROR_UNKNOWN_OBJECT
+#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
+#endif
+
+#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
+#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
+#endif
+
+#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
+#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
+#endif
+
+#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
+#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
+#endif
+
+#define BUS_PROPERTIES_INTERFACE \
+ " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
+ " <method name=\"Get\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <method name=\"GetAll\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
+ " </method>\n" \
+ " <method name=\"Set\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <signal name=\"PropertiesChanged\">\n" \
+ " <arg type=\"s\" name=\"interface\"/>\n" \
+ " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
+ " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
+ " </signal>\n" \
+ " </interface>\n"
+
+#define BUS_INTROSPECTABLE_INTERFACE \
+ " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
+ " <method name=\"Introspect\">\n" \
+ " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " </interface>\n"
+
+#define BUS_PEER_INTERFACE \
+ "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
+ " <method name=\"Ping\"/>\n" \
+ " <method name=\"GetMachineId\">\n" \
+ " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ "</interface>\n"
+
+#define BUS_GENERIC_INTERFACES_LIST \
+ "org.freedesktop.DBus.Properties\0" \
+ "org.freedesktop.DBus.Introspectable\0" \
+ "org.freedesktop.DBus.Peer\0"
+
int bus_check_peercred(DBusConnection *c);
int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
@@ -33,4 +92,64 @@ int bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
const char *bus_error_message(const DBusError *error);
+typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
+typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property);
+
+typedef struct BusProperty {
+ const char *interface; /* interface of the property */
+ const char *property; /* name of the property */
+ BusPropertyCallback append; /* Function that is called to serialize this property */
+ const char *signature;
+ const void *data; /* The data of this property */
+ BusPropertySetCallback set; /* Optional: Function that is called to set this property */
+} BusProperty;
+
+DBusHandlerResult bus_send_error_reply(
+ DBusConnection *c,
+ DBusMessage *message,
+ DBusError *bus_error,
+ int error);
+
+DBusHandlerResult bus_default_message_handler(
+ DBusConnection *c,
+ DBusMessage *message,
+ const char *introspection,
+ const char *interfaces,
+ const BusProperty *properties);
+
+int bus_property_append_string(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_size(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data);
+
+#define bus_property_append_int bus_property_append_int32
+#define bus_property_append_pid bus_property_append_uint32
+#define bus_property_append_mode bus_property_append_uint32
+#define bus_property_append_unsigned bus_property_append_uint32
+#define bus_property_append_usec bus_property_append_uint64
+
+#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
+ int function(DBusMessageIter *i, const char *property, void *data) { \
+ const char *value; \
+ type *field = data; \
+ \
+ assert(i); \
+ assert(property); \
+ \
+ value = name##_to_string(*field); \
+ \
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
+ return -ENOMEM; \
+ \
+ return 0; \
+ }
+
+const char *bus_errno_to_dbus(int error);
+
+DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
+
#endif
diff --git a/src/dbus-device.c b/src/dbus-device.c
index b046eae..f85ad2d 100644
--- a/src/dbus-device.c
+++ b/src/dbus-device.c
@@ -21,6 +21,7 @@
#include "dbus-unit.h"
#include "dbus-device.h"
+#include "dbus-common.h"
#define BUS_DEVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Device\">\n" \
@@ -53,5 +54,5 @@ DBusHandlerResult bus_device_message_handler(Unit *u, DBusConnection *c, DBusMes
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-execute.c b/src/dbus-execute.c
index 3cb09c2..3f8fafe 100644
--- a/src/dbus-execute.c
+++ b/src/dbus-execute.c
@@ -27,17 +27,17 @@
#include "missing.h"
#include "ioprio.h"
#include "strv.h"
+#include "dbus-common.h"
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_kill_mode, kill_mode, KillMode);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput);
-int bus_execute_append_env_files(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data) {
char **env_files = data, **j;
DBusMessageIter sub, sub2;
- assert(m);
assert(i);
assert(property);
@@ -66,11 +66,10 @@ int bus_execute_append_env_files(Manager *m, DBusMessageIter *i, const char *pro
return 0;
}
-int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_oom_score_adjust(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -101,11 +100,10 @@ int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const ch
return 0;
}
-int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_nice(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -121,11 +119,10 @@ int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property
return 0;
}
-int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_ioprio(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -141,11 +138,10 @@ int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *proper
return 0;
}
-int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_cpu_sched_policy(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -161,11 +157,10 @@ int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const ch
return 0;
}
-int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -187,12 +182,11 @@ int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const
return 0;
}
-int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_affinity(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
dbus_bool_t b;
DBusMessageIter sub;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -214,11 +208,10 @@ int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *prop
return 0;
}
-int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_timer_slack_nsec(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
uint64_t u;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -234,11 +227,10 @@ int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const ch
return 0;
}
-int bus_execute_append_capability_bs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
uint64_t normal, inverted;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -249,16 +241,15 @@ int bus_execute_append_capability_bs(Manager *m, DBusMessageIter *i, const char
normal = *(uint64_t*) data;
inverted = ~normal;
- return bus_property_append_uint64(m, i, property, &inverted);
+ return bus_property_append_uint64(i, property, &inverted);
}
-int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_capabilities(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
char *t = NULL;
const char *s;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -282,12 +273,11 @@ int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *
return 0;
}
-int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int r;
uint64_t u;
- assert(m);
assert(i);
assert(property);
assert(c);
@@ -311,11 +301,10 @@ int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *prope
return 0;
}
-int bus_execute_append_command(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_command(DBusMessageIter *i, const char *property, void *data) {
ExecCommand *c = data;
DBusMessageIter sub, sub2, sub3;
- assert(m);
assert(i);
assert(property);
diff --git a/src/dbus-execute.h b/src/dbus-execute.h
index 548738a..ed66390 100644
--- a/src/dbus-execute.h
+++ b/src/dbus-execute.h
@@ -161,20 +161,20 @@
#define BUS_EXEC_COMMAND_PROPERTY(interface, command, name) \
{ interface, name, bus_execute_append_command, "a(sasbttttuii)", (command) }
-int bus_execute_append_output(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_input(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_capability_bs(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_command(Manager *m, DBusMessageIter *u, const char *property, void *data);
-int bus_execute_append_kill_mode(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_env_files(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_output(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_input(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_oom_score_adjust(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_nice(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_ioprio(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_cpu_sched_policy(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_affinity(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_timer_slack_nsec(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_capabilities(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_command(DBusMessageIter *u, const char *property, void *data);
+int bus_execute_append_kill_mode(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data);
#endif
diff --git a/src/dbus-job.c b/src/dbus-job.c
index 908ddba..2308be3 100644
--- a/src/dbus-job.c
+++ b/src/dbus-job.c
@@ -24,6 +24,7 @@
#include "dbus.h"
#include "log.h"
#include "dbus-job.h"
+#include "dbus-common.h"
#define BUS_JOB_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Job\">\n" \
@@ -55,12 +56,11 @@ const char bus_job_interface[] _introspect_("Job") = BUS_JOB_INTERFACE;
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_state, job_state, JobState);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_type, job_type, JobType);
-static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_job_append_unit(DBusMessageIter *i, const char *property, void *data) {
Job *j = data;
DBusMessageIter sub;
char *p;
- assert(m);
assert(i);
assert(property);
assert(j);
@@ -103,7 +103,7 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connec
job_finish_and_invalidate(j, JOB_CANCELED);
} else
- return bus_default_message_handler(j->manager, connection, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
if (reply) {
if (!dbus_connection_send(connection, reply, NULL))
@@ -201,10 +201,10 @@ static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBu
dbus_error_init(&e);
dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown job");
- return bus_send_error_reply(m, connection, message, &e, r);
+ return bus_send_error_reply(connection, message, &e, r);
}
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
return bus_job_message_dispatch(j, connection, message);
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index e1bf9fd..4224afa 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -28,6 +28,7 @@
#include "strv.h"
#include "bus-errors.h"
#include "build.h"
+#include "dbus-common.h"
#define BUS_MANAGER_INTERFACE_BEGIN \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n"
@@ -219,13 +220,14 @@ const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFA
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
-static int bus_manager_append_tainted(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) {
const char *t;
+ Manager *m = data;
char buf[LINE_MAX] = "", *e = buf, *p = NULL;
- assert(m);
assert(i);
assert(property);
+ assert(m);
if (m->taint_usr)
e = stpcpy(e, "usr-separate-fs ");
@@ -246,10 +248,9 @@ static int bus_manager_append_tainted(Manager *m, DBusMessageIter *i, const char
return 0;
}
-static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_log_target(DBusMessageIter *i, const char *property, void *data) {
const char *t;
- assert(m);
assert(i);
assert(property);
@@ -261,10 +262,9 @@ static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const c
return 0;
}
-static int bus_manager_set_log_target(Manager *m, DBusMessageIter *i, const char *property) {
+static int bus_manager_set_log_target(DBusMessageIter *i, const char *property) {
const char *t;
- assert(m);
assert(i);
assert(property);
@@ -273,10 +273,9 @@ static int bus_manager_set_log_target(Manager *m, DBusMessageIter *i, const char
return log_set_target_from_string(t);
}
-static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) {
const char *t;
- assert(m);
assert(i);
assert(property);
@@ -288,10 +287,9 @@ static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const ch
return 0;
}
-static int bus_manager_set_log_level(Manager *m, DBusMessageIter *i, const char *property) {
+static int bus_manager_set_log_level(DBusMessageIter *i, const char *property) {
const char *t;
- assert(m);
assert(i);
assert(property);
@@ -300,12 +298,13 @@ static int bus_manager_set_log_level(Manager *m, DBusMessageIter *i, const char
return log_set_max_level_from_string(t);
}
-static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_n_names(DBusMessageIter *i, const char *property, void *data) {
+ Manager *m = data;
uint32_t u;
- assert(m);
assert(i);
assert(property);
+ assert(m);
u = hashmap_size(m->units);
@@ -315,12 +314,13 @@ static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char
return 0;
}
-static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_n_jobs(DBusMessageIter *i, const char *property, void *data) {
+ Manager *m = data;
uint32_t u;
- assert(m);
assert(i);
assert(property);
+ assert(m);
u = hashmap_size(m->jobs);
@@ -330,12 +330,13 @@ static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char
return 0;
}
-static int bus_manager_append_progress(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_progress(DBusMessageIter *i, const char *property, void *data) {
double d;
+ Manager *m = data;
- assert(m);
assert(i);
assert(property);
+ assert(m);
if (dual_timestamp_is_set(&m->finish_timestamp))
d = 1.0;
@@ -377,13 +378,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
{ "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
{ "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64, "t", &m->finish_timestamp.realtime },
{ "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
- { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", NULL, bus_manager_set_log_level},
- { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", NULL, bus_manager_set_log_target},
- { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", NULL },
+ { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", m, bus_manager_set_log_level },
+ { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", m, bus_manager_set_log_target },
+ { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", m },
{ "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", NULL },
{ "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32, "u", &m->n_installed_jobs },
{ "org.freedesktop.systemd1.Manager", "NFailedJobs", bus_property_append_uint32, "u", &m->n_failed_jobs },
- { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", NULL },
+ { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", m },
{ "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
{ "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
{ "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
@@ -425,11 +426,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -452,11 +453,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
&error,
DBUS_TYPE_UINT32, &pid,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -479,10 +480,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -529,21 +530,21 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((mode = kill_mode_from_string(smode)) < 0 ||
(who = kill_who_from_string(swho)) < 0 ||
signo <= 0 ||
signo >= _NSIG)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -557,11 +558,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
&error,
DBUS_TYPE_UINT32, &id,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(j = manager_get_job(m, id))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -599,11 +600,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
unit_reset_failed(u);
@@ -765,7 +766,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if ((r = set_put(s, client)) < 0) {
free(client);
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -776,7 +777,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
free(client);
@@ -823,13 +824,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BOOLEAN, &cleanup,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (name && name[0] == 0)
name = NULL;
if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -930,7 +931,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (m->running_as == MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -942,7 +943,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -954,7 +955,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -966,7 +967,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -978,7 +979,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
@@ -993,7 +994,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
e = strv_env_merge(2, m->environment, l);
@@ -1017,7 +1018,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
e = strv_env_delete(m->environment, 1, l);
@@ -1035,7 +1036,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
m->environment = e;
} else
- return bus_default_message_handler(m, connection, message, NULL, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
if (job_type != _JOB_TYPE_INVALID) {
const char *name, *smode, *old_name = NULL;
@@ -1061,24 +1062,24 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
DBUS_TYPE_INVALID);
if (!b)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (old_name)
if (!(u = manager_get_unit(m, old_name)) ||
!u->meta.job ||
u->meta.job->type != JOB_START) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
}
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (reload_if_possible && unit_can_reload(u)) {
if (job_type == JOB_RESTART)
@@ -1092,11 +1093,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
(u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
}
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
goto oom;
diff --git a/src/dbus-mount.c b/src/dbus-mount.c
index 5fb9a3f..cfbfd45 100644
--- a/src/dbus-mount.c
+++ b/src/dbus-mount.c
@@ -24,6 +24,7 @@
#include "dbus-unit.h"
#include "dbus-mount.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_MOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
@@ -65,11 +66,10 @@ const char bus_mount_invalidating_properties[] =
"ExecRemount\0"
"ControlPID\0";
-static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
@@ -89,11 +89,10 @@ static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *pro
return 0;
}
-static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
@@ -113,11 +112,10 @@ static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *
return 0;
}
-static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
@@ -138,6 +136,7 @@ static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *pro
}
DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
+
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", u->mount.where },
@@ -154,5 +153,5 @@ DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMess
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-path.c b/src/dbus-path.c
index 1e757a3..1523879 100644
--- a/src/dbus-path.c
+++ b/src/dbus-path.c
@@ -24,6 +24,7 @@
#include "dbus-unit.h"
#include "dbus-path.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_PATH_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Path\">\n" \
@@ -49,12 +50,11 @@
const char bus_path_interface[] _introspect_("Path") = BUS_PATH_INTERFACE;
-static int bus_path_append_paths(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_path_append_paths(DBusMessageIter *i, const char *property, void *data) {
Path *p = data;
DBusMessageIter sub, sub2;
PathSpec *k;
- assert(m);
assert(i);
assert(property);
assert(p);
@@ -78,11 +78,10 @@ static int bus_path_append_paths(Manager *m, DBusMessageIter *i, const char *pro
return 0;
}
-static int bus_path_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_path_append_unit(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *t;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -102,5 +101,5 @@ DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessa
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-service.c b/src/dbus-service.c
index 9c3d73c..3486623 100644
--- a/src/dbus-service.c
+++ b/src/dbus-service.c
@@ -24,6 +24,7 @@
#include "dbus-unit.h"
#include "dbus-execute.h"
#include "dbus-service.h"
+#include "dbus-common.h"
#ifdef HAVE_SYSV_COMPAT
#define BUS_SERVICE_SYSV_INTERFACE_FRAGMENT \
@@ -129,5 +130,5 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connectio
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-snapshot.c b/src/dbus-snapshot.c
index cc12b1b..0c2f349 100644
--- a/src/dbus-snapshot.c
+++ b/src/dbus-snapshot.c
@@ -21,6 +21,7 @@
#include "dbus-unit.h"
#include "dbus-snapshot.h"
+#include "dbus-common.h"
#define BUS_SNAPSHOT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Snapshot\">\n" \
@@ -45,6 +46,7 @@
const char bus_snapshot_interface[] _introspect_("Snapshot") = BUS_SNAPSHOT_INTERFACE;
DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
+
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Snapshot", "Cleanup", bus_property_append_bool, "b", &u->snapshot.cleanup },
@@ -64,7 +66,7 @@ DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusM
goto oom;
} else
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
if (reply) {
if (!dbus_connection_send(c, reply, NULL))
diff --git a/src/dbus-socket.c b/src/dbus-socket.c
index 5b068b4..88727bb 100644
--- a/src/dbus-socket.c
+++ b/src/dbus-socket.c
@@ -24,6 +24,7 @@
#include "dbus-unit.h"
#include "dbus-socket.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_SOCKET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Socket\">\n" \
@@ -113,5 +114,5 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMes
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-swap.c b/src/dbus-swap.c
index 079912a..988ca58 100644
--- a/src/dbus-swap.c
+++ b/src/dbus-swap.c
@@ -25,6 +25,7 @@
#include "dbus-unit.h"
#include "dbus-swap.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_SWAP_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Swap\">\n" \
@@ -60,11 +61,10 @@ const char bus_swap_invalidating_properties[] =
"ExecDeactivate\0"
"ControlPID\0";
-static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_swap_append_priority(DBusMessageIter *i, const char *property, void *data) {
Swap *s = data;
dbus_int32_t j;
- assert(m);
assert(i);
assert(property);
assert(s);
@@ -96,5 +96,5 @@ DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessa
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-target.c b/src/dbus-target.c
index 1cbeccb..1e00f2d 100644
--- a/src/dbus-target.c
+++ b/src/dbus-target.c
@@ -23,6 +23,7 @@
#include "dbus-unit.h"
#include "dbus-target.h"
+#include "dbus-common.h"
#define BUS_TARGET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Target\">\n" \
@@ -50,5 +51,5 @@ DBusHandlerResult bus_target_message_handler(Unit *u, DBusConnection *c, DBusMes
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-timer.c b/src/dbus-timer.c
index e44f4e2..abcbe6f 100644
--- a/src/dbus-timer.c
+++ b/src/dbus-timer.c
@@ -24,6 +24,7 @@
#include "dbus-unit.h"
#include "dbus-timer.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_TIMER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Timer\">\n" \
@@ -52,12 +53,11 @@ const char bus_timer_invalidating_properties[] =
"Timers\0"
"NextElapseUSec\0";
-static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_timer_append_timers(DBusMessageIter *i, const char *property, void *data) {
Timer *p = data;
DBusMessageIter sub, sub2;
TimerValue *k;
- assert(m);
assert(i);
assert(property);
assert(p);
@@ -99,11 +99,10 @@ static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *p
return 0;
}
-static int bus_timer_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_timer_append_unit(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *t;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -122,5 +121,5 @@ DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMess
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
diff --git a/src/dbus-unit.c b/src/dbus-unit.c
index b5daa66..ad8e9a1 100644
--- a/src/dbus-unit.c
+++ b/src/dbus-unit.c
@@ -25,6 +25,7 @@
#include "log.h"
#include "dbus-unit.h"
#include "bus-errors.h"
+#include "dbus-common.h"
const char bus_unit_interface[] _introspect_("Unit") = BUS_UNIT_INTERFACE;
@@ -39,7 +40,7 @@ const char bus_unit_interface[] _introspect_("Unit") = BUS_UNIT_INTERFACE;
"Job\0" \
"NeedDaemonReload\0"
-int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data) {
char *t;
Iterator j;
DBusMessageIter sub;
@@ -58,11 +59,10 @@ int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property,
return 0;
}
-int bus_unit_append_following(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data, *f;
const char *d;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -76,7 +76,7 @@ int bus_unit_append_following(Manager *m, DBusMessageIter *i, const char *proper
return 0;
}
-int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_dependencies(DBusMessageIter *i, const char *property, void *data) {
Unit *u;
Iterator j;
DBusMessageIter sub;
@@ -95,11 +95,10 @@ int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *pro
return 0;
}
-int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_description(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *d;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -114,11 +113,10 @@ int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *prop
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_load_state, unit_load_state, UnitLoadState);
-int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *state;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -131,11 +129,10 @@ int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *pro
return 0;
}
-int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *state;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -148,11 +145,10 @@ int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *proper
return 0;
}
-int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -166,11 +162,10 @@ int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *proper
return 0;
}
-int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -187,11 +182,10 @@ int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *propert
return 0;
}
-int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -204,11 +198,10 @@ int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *prope
return 0;
}
-int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -222,12 +215,11 @@ int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *prop
return 0;
}
-int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
DBusMessageIter sub;
char *p;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -270,13 +262,12 @@ int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, vo
return 0;
}
-int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
char *t;
CGroupBonding *cgb;
bool success;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -295,7 +286,7 @@ int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *p
return success ? 0 : -ENOMEM;
}
-int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
CGroupBonding *cgb;
DBusMessageIter sub;
@@ -323,11 +314,10 @@ int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property
return 0;
}
-int bus_unit_append_need_daemon_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
@@ -380,16 +370,16 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((mode = kill_mode_from_string(smode)) < 0 ||
(who = kill_who_from_string(swho)) < 0 ||
signo <= 0 ||
signo >= _NSIG)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -417,7 +407,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
(u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
}
if (!dbus_message_get_args(
@@ -425,7 +415,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
&error,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (reload_if_possible && unit_can_reload(u)) {
if (job_type == JOB_RESTART)
@@ -436,11 +426,11 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
}
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -571,10 +561,10 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DB
dbus_error_init(&e);
dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown unit");
- return bus_send_error_reply(m, connection, message, &e, r);
+ return bus_send_error_reply(connection, message, &e, r);
}
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
return bus_unit_message_dispatch(u, connection, message);
diff --git a/src/dbus-unit.h b/src/dbus-unit.h
index b578ff9..a2a9323 100644
--- a/src/dbus-unit.h
+++ b/src/dbus-unit.h
@@ -170,21 +170,21 @@
{ "org.freedesktop.systemd1.Unit", "ConditionTimestampMonotonic", bus_property_append_usec,"t", &u->meta.condition_timestamp.monotonic }, \
{ "org.freedesktop.systemd1.Unit", "ConditionResult", bus_property_append_bool, "b", &u->meta.condition_result }
-int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_following(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_load_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_need_daemon_reload(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_dependencies(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_description(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_load_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data);
void bus_unit_send_change_signal(Unit *u);
void bus_unit_send_removed_signal(Unit *u);
diff --git a/src/dbus.c b/src/dbus.c
index 6f43c41..1907560 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -44,6 +44,7 @@
#include "dbus-path.h"
#include "bus-errors.h"
#include "special.h"
+#include "dbus-common.h"
#define CONNECTIONS_MAX 52
@@ -69,7 +70,6 @@ const char *const bus_interface_table[] = {
NULL
};
-static const char *error_to_dbus(int error);
static void bus_done_api(Manager *m);
static void bus_done_system(Manager *m);
static void bus_done_private(Manager *m);
@@ -406,7 +406,7 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
goto oom;
- id = error.name ? error.name : error_to_dbus(r);
+ id = error.name ? error.name : bus_errno_to_dbus(r);
text = bus_error(&error, r);
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
@@ -1214,289 +1214,6 @@ oom:
return -ENOMEM;
}
-DBusHandlerResult bus_default_message_handler(
- Manager *m,
- DBusConnection *c,
- DBusMessage *message,
- const char *introspection,
- const char *interfaces,
- const BusProperty *properties) {
-
- DBusError error;
- DBusMessage *reply = NULL;
- int r;
-
- assert(m);
- assert(c);
- assert(message);
-
- dbus_error_init(&error);
-
- if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
- const char *interface, *property;
- const BusProperty *p;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_STRING, &property,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
-
- for (p = properties; p->property; p++)
- if (streq(p->interface, interface) && streq(p->property, property))
- break;
-
- if (p->property) {
- DBusMessageIter iter, sub;
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- dbus_message_iter_init_append(reply, &iter);
-
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
- goto oom;
-
- if ((r = p->append(m, &sub, property, (void*) p->data)) < 0) {
-
- if (r == -ENOMEM)
- goto oom;
-
- dbus_message_unref(reply);
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
- } else {
- if (!nulstr_contains(interfaces, interface))
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- else
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
-
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
- const char *interface;
- const BusProperty *p;
- DBusMessageIter iter, sub, sub2, sub3;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
-
- if (interface[0] && !nulstr_contains(interfaces, interface)) {
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- dbus_message_iter_init_append(reply, &iter);
-
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
- goto oom;
-
- for (p = properties; p->property; p++) {
- if (interface[0] && !streq(p->interface, interface))
- continue;
-
- if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
- !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
- goto oom;
-
- if ((r = p->append(m, &sub3, p->property, (void*) p->data)) < 0) {
-
- if (r == -ENOMEM)
- goto oom;
-
- dbus_message_unref(reply);
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!dbus_message_iter_close_container(&sub2, &sub3) ||
- !dbus_message_iter_close_container(&sub, &sub2))
- goto oom;
- }
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && properties) {
- const char *interface, *property;
- DBusMessageIter iter;
- const BusProperty *p;
-
- if (!dbus_message_iter_init(message, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- dbus_message_iter_get_basic(&iter, &interface);
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- dbus_message_iter_get_basic(&iter, &property);
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT ||
- dbus_message_iter_has_next(&iter))
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- for (p = properties; p->property; p++)
- if (streq(p->interface, interface) && streq(p->property, property))
- break;
-
- if (p->set) {
- DBusMessageIter sub;
- char *sig;
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (!(sig = dbus_message_iter_get_signature(&sub)))
- goto oom;
-
- if (!streq(sig, p->signature)) {
- dbus_free(sig);
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
- }
-
- dbus_free(sig);
-
- if ((r = p->set(m, &sub, property)) < 0) {
- if (r == -ENOMEM)
- goto oom;
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
- } else {
- if (p->property)
- dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
- else if (!nulstr_contains(interfaces, interface))
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- else
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
-
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- } else if (!nulstr_contains(interfaces, dbus_message_get_interface(message))) {
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- if (reply) {
- if (!dbus_connection_send(c, reply, NULL))
- goto oom;
-
- dbus_message_unref(reply);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-oom:
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
-
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
-static const char *error_to_dbus(int error) {
-
- switch(error) {
-
- case -EINVAL:
- return DBUS_ERROR_INVALID_ARGS;
-
- case -ENOMEM:
- return DBUS_ERROR_NO_MEMORY;
-
- case -EPERM:
- case -EACCES:
- return DBUS_ERROR_ACCESS_DENIED;
-
- case -ESRCH:
- return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN;
-
- case -ENOENT:
- return DBUS_ERROR_FILE_NOT_FOUND;
-
- case -EEXIST:
- return DBUS_ERROR_FILE_EXISTS;
-
- case -ETIMEDOUT:
- case -ETIME:
- return DBUS_ERROR_TIMEOUT;
-
- case -EIO:
- return DBUS_ERROR_IO_ERROR;
-
- case -ENETRESET:
- case -ECONNABORTED:
- case -ECONNRESET:
- return DBUS_ERROR_DISCONNECTED;
- }
-
- return DBUS_ERROR_FAILED;
-}
-
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
- DBusMessage *reply = NULL;
- const char *name, *text;
-
- if (berror && dbus_error_is_set(berror)) {
- name = berror->name;
- text = berror->message;
- } else {
- name = error_to_dbus(error);
- text = strerror(-error);
- }
-
- if (!(reply = dbus_message_new_error(message, name, text)))
- goto oom;
-
- if (!dbus_connection_send(c, reply, NULL))
- goto oom;
-
- dbus_message_unref(reply);
-
- if (berror)
- dbus_error_free(berror);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-
-oom:
- if (reply)
- dbus_message_unref(reply);
-
- if (berror)
- dbus_error_free(berror);
-
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
int bus_broadcast(Manager *m, DBusMessage *message) {
bool oom = false;
Iterator i;
@@ -1516,140 +1233,6 @@ int bus_broadcast(Manager *m, DBusMessage *message) {
return oom ? -ENOMEM : 0;
}
-int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- const char *t = data;
-
- assert(m);
- assert(i);
- assert(property);
-
- if (!t)
- t = "";
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- DBusMessageIter sub;
- char **t = data;
-
- assert(m);
- assert(i);
- assert(property);
-
- if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
- return -ENOMEM;
-
- STRV_FOREACH(t, t)
- if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t))
- return -ENOMEM;
-
- if (!dbus_message_iter_close_container(i, &sub))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- bool *b = data;
- dbus_bool_t db;
-
- assert(m);
- assert(i);
- assert(property);
- assert(b);
-
- db = *b;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- /* Let's ensure that pid_t is actually 64bit, and hence this
- * function can be used for usec_t */
- assert_cc(sizeof(uint64_t) == sizeof(usec_t));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- /* Let's ensure that pid_t and mode_t is actually 32bit, and
- * hence this function can be used for pid_t/mode_t */
- assert_cc(sizeof(uint32_t) == sizeof(pid_t));
- assert_cc(sizeof(uint32_t) == sizeof(mode_t));
- assert_cc(sizeof(uint32_t) == sizeof(unsigned));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- assert_cc(sizeof(int32_t) == sizeof(int));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- uint64_t u;
-
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- u = (uint64_t) *(size_t*) data;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- uint64_t u;
-
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- u = (uint64_t) *(unsigned long*) data;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
- return -ENOMEM;
-
- return 0;
-}
-
int bus_parse_strv(DBusMessage *m, char ***_l) {
DBusMessageIter iter, sub;
unsigned n = 0, i = 0;
@@ -1722,41 +1305,3 @@ bool bus_connection_has_subscriber(Manager *m, DBusConnection *c) {
return !set_isempty(BUS_CONNECTION_SUBSCRIBED(m, c));
}
-
-DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties) {
- DBusMessage *m;
- DBusMessageIter iter, sub;
- const char *i;
-
- assert(interface);
- assert(properties);
-
- if (!(m = dbus_message_new_signal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged")))
- goto oom;
-
- dbus_message_iter_init_append(m, &iter);
-
- /* We won't send any property values, since they might be
- * large and sometimes not cheap to generated */
-
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) ||
- !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub) ||
- !dbus_message_iter_close_container(&iter, &sub) ||
- !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub))
- goto oom;
-
- NULSTR_FOREACH(i, properties)
- if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &i))
- goto oom;
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
-
- return m;
-
-oom:
- if (m)
- dbus_message_unref(m);
-
- return NULL;
-}
diff --git a/src/dbus.h b/src/dbus.h
index f93ad62..57a2b38 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -24,79 +24,8 @@
#include <dbus/dbus.h>
-#ifndef DBUS_ERROR_UNKNOWN_OBJECT
-#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
-#endif
-
-#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
-#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
-#endif
-
-#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
-#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
-#endif
-
-#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
-#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
-#endif
-
#include "manager.h"
-typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);
-typedef int (*BusPropertySetCallback)(Manager *m, DBusMessageIter *iter, const char *property);
-
-typedef struct BusProperty {
- const char *interface; /* interface of the property */
- const char *property; /* name of the property */
- BusPropertyCallback append; /* Function that is called to serialize this property */
- const char *signature;
- const void *data; /* The data of this property */
- BusPropertySetCallback set; /* Function that is called to set this property */
-} BusProperty;
-
-#define BUS_PROPERTIES_INTERFACE \
- " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
- " <method name=\"Get\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
- " </method>\n" \
- " <method name=\"GetAll\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
- " </method>\n" \
- " <method name=\"Set\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
- " </method>\n" \
- " <signal name=\"PropertiesChanged\">\n" \
- " <arg type=\"s\" name=\"interface\"/>\n" \
- " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
- " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
- " </signal>\n" \
- " </interface>\n"
-
-#define BUS_INTROSPECTABLE_INTERFACE \
- " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
- " <method name=\"Introspect\">\n" \
- " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
- " </method>\n" \
- " </interface>\n"
-
-#define BUS_PEER_INTERFACE \
- "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
- " <method name=\"Ping\"/>\n" \
- " <method name=\"GetMachineId\">\n" \
- " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
- " </method>\n" \
- "</interface>\n"
-
-#define BUS_GENERIC_INTERFACES_LIST \
- "org.freedesktop.DBus.Properties\0" \
- "org.freedesktop.DBus.Introspectable\0" \
- "org.freedesktop.DBus.Peer\0"
-
int bus_init(Manager *m, bool try_bus_connect);
void bus_done(Manager *m);
@@ -107,50 +36,13 @@ void bus_timeout_event(Manager *m, Watch *w, int events);
int bus_query_pid(Manager *m, const char *name);
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const char *interfaces, const BusProperty *properties);
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
-
int bus_broadcast(Manager *m, DBusMessage *message);
-int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data);
-
-#define bus_property_append_int bus_property_append_int32
-#define bus_property_append_pid bus_property_append_uint32
-#define bus_property_append_mode bus_property_append_uint32
-#define bus_property_append_unsigned bus_property_append_uint32
-#define bus_property_append_usec bus_property_append_uint64
-
-#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
- int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \
- const char *value; \
- type *field = data; \
- \
- assert(m); \
- assert(i); \
- assert(property); \
- \
- value = name##_to_string(*field); \
- \
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
- return -ENOMEM; \
- \
- return 0; \
- }
-
int bus_parse_strv(DBusMessage *m, char ***_l);
bool bus_has_subscriber(Manager *m);
bool bus_connection_has_subscriber(Manager *m, DBusConnection *c);
-DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
-
#define BUS_CONNECTION_SUBSCRIBED(m, c) dbus_connection_get_data((c), (m)->subscribed_data_slot)
#define BUS_PENDING_CALL_NAME(m, p) dbus_pending_call_get_data((p), (m)->name_data_slot)
commit e1830b12ae8d97a1baaabe28d9ee28c77835463d
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:50:40 2011 +0200
strv: properly override settings in env_append()
diff --git a/src/strv.c b/src/strv.c
index 0afd986..1c15ee8 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -528,6 +528,9 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) {
char **strv_env_set(char **x, const char *p) {
char **k, **r;
+ char* m[2] = { (char*) p, NULL };
+
+ /* Overrides the env var setting of p, returns a new copy */
if (!(r = new(char*, strv_length(x)+2)))
return NULL;
@@ -536,7 +539,7 @@ char **strv_env_set(char **x, const char *p) {
if (env_append(r, &k, x) < 0)
goto fail;
- if (!(*(k++) = strdup(p)))
+ if (env_append(r, &k, m) < 0)
goto fail;
*k = NULL;
commit 5d6ab905c00342d012aed559a859b373512e4650
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:50:10 2011 +0200
strv: detect non-assignments in env blocks properly in env_append()
diff --git a/src/strv.c b/src/strv.c
index c8ebb64..0afd986 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -358,7 +358,10 @@ char **strv_remove(char **l, const char *s) {
if (!l)
return NULL;
- /* Drops every occurrence of s in the string list */
+ assert(s);
+
+ /* Drops every occurrence of s in the string list, edits
+ * in-place. */
for (f = t = l; *f; f++) {
@@ -387,7 +390,12 @@ static int env_append(char **r, char ***k, char **a) {
for (; *a; a++) {
char **j;
- size_t n = strcspn(*a, "=") + 1;
+ size_t n;
+
+ n = strcspn(*a, "=");
+
+ if ((*a)[n] == '=')
+ n++;
for (j = r; j < *k; j++)
if (strncmp(*j, *a, n) == 0)
commit ede27aab11cda3f55c2cd2e1e28e2385b3f64453
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:49:20 2011 +0200
strv: handle empty lists in strv_copy() properly
diff --git a/src/strv.c b/src/strv.c
index c5f8df0..c8ebb64 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -70,9 +70,10 @@ char **strv_copy(char **l) {
if (!(r = new(char*, strv_length(l)+1)))
return NULL;
- for (k = r; *l; k++, l++)
- if (!(*k = strdup(*l)))
- goto fail;
+ if (l)
+ for (k = r; *l; k++, l++)
+ if (!(*k = strdup(*l)))
+ goto fail;
*k = NULL;
return r;
commit 6f9a471aa677ff4048aea168d7cea3697cf51fb3
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:48:02 2011 +0200
util: truncate newline inside of read_one_line_file() already
diff --git a/src/cgroups-agent.c b/src/cgroups-agent.c
index e0868b6..7f001e6 100644
--- a/src/cgroups-agent.c
+++ b/src/cgroups-agent.c
@@ -43,7 +43,6 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
-
/* We send this event to the private D-Bus socket and then the
* system instance will forward this to the system bus. We do
* this to avoid an activation loop when we start dbus when we
@@ -94,7 +93,6 @@ finish:
dbus_connection_unref(bus);
}
-
if (m)
dbus_message_unref(m);
diff --git a/src/getty-generator.c b/src/getty-generator.c
index f49f9ea..683775a 100644
--- a/src/getty-generator.c
+++ b/src/getty-generator.c
@@ -86,7 +86,6 @@ int main(int argc, char *argv[]) {
if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) {
const char *tty;
- truncate_nl(active);
if ((tty = strrchr(active, ' ')))
tty ++;
else
diff --git a/src/util.c b/src/util.c
index 39c9db7..fb8df84 100644
--- a/src/util.c
+++ b/src/util.c
@@ -550,6 +550,8 @@ int read_one_line_file(const char *fn, char **line) {
goto finish;
}
+ truncate_nl(c);
+
*line = c;
r = 0;
@@ -797,7 +799,6 @@ int get_process_name(pid_t pid, char **name) {
if (r < 0)
return r;
- truncate_nl(*name);
return 0;
}
@@ -3199,8 +3200,7 @@ void status_welcome(void) {
if (r != -ENOENT)
log_warning("Failed to read /etc/system-release: %s", strerror(-r));
- } else
- truncate_nl(pretty_name);
+ }
}
if (!ansi_color && pretty_name) {
@@ -3221,8 +3221,7 @@ void status_welcome(void) {
if (r != -ENOENT)
log_warning("Failed to read /etc/SuSE-release: %s", strerror(-r));
- } else
- truncate_nl(pretty_name);
+ }
}
if (!ansi_color)
@@ -3235,8 +3234,7 @@ void status_welcome(void) {
if (r != -ENOENT)
log_warning("Failed to read /etc/gentoo-release: %s", strerror(-r));
- } else
- truncate_nl(pretty_name);
+ }
}
if (!ansi_color)
@@ -3249,8 +3247,7 @@ void status_welcome(void) {
if (r != -ENOENT)
log_warning("Failed to read /etc/altlinux-release: %s", strerror(-r));
- } else
- truncate_nl(pretty_name);
+ }
}
if (!ansi_color)
@@ -3267,7 +3264,6 @@ void status_welcome(void) {
if (r != -ENOENT)
log_warning("Failed to read /etc/debian_version: %s", strerror(-r));
} else {
- truncate_nl(version);
pretty_name = strappend("Debian ", version);
free(version);
@@ -3826,8 +3822,6 @@ const char *default_term_for_tty(const char *tty) {
* TERM */
if (streq(tty, "console"))
if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) {
- truncate_nl(active);
-
/* If multiple log outputs are configured the
* last one is what /dev/console points to */
if ((tty = strrchr(active, ' ')))
commit 8480e784f176a4911e22497e01bfbdf084342520
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Apr 16 01:45:45 2011 +0200
util: modernize get_parent_of_pid() a bit
diff --git a/src/util.c b/src/util.c
index 75ad56f..39c9db7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -456,11 +456,11 @@ int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
char fn[PATH_MAX], line[LINE_MAX], *p;
long unsigned ppid;
- assert(pid >= 0);
+ assert(pid > 0);
assert(_ppid);
assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
- fn[sizeof(fn)-1] = 0;
+ char_array_0(fn);
if (!(f = fopen(fn, "r")))
return -errno;
commit 9072492933eaacbcd8daed3f9baf90583dd22574
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 02:36:02 2011 +0200
crypto: let the cryptsetup binary handles its own configurable timeouts
diff --git a/src/cryptsetup-generator.c b/src/cryptsetup-generator.c
index 9b62e6a..b57c0b7 100644
--- a/src/cryptsetup-generator.c
+++ b/src/cryptsetup-generator.c
@@ -115,6 +115,7 @@ static int create_disk(
"\n[Service]\n"
"Type=oneshot\n"
"RemainAfterExit=yes\n"
+ "TimeoutSec=0\n" /* the binary handles timeouts anyway */
"ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
"ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
name, u, strempty(password), strempty(options),
diff --git a/src/cryptsetup.c b/src/cryptsetup.c
index f52a41b..4ef9606 100644
--- a/src/cryptsetup.c
+++ b/src/cryptsetup.c
@@ -40,7 +40,7 @@ static char *opt_hash = NULL;
static unsigned opt_tries = 0;
static bool opt_readonly = false;
static bool opt_verify = false;
-static usec_t opt_timeout = 0;
+static usec_t opt_timeout = DEFAULT_TIMEOUT_USEC;
/* Options Debian's crypttab knows we don't:
commit ef9eb0a8976140654827d479af1f4256fae6afe3
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 02:32:42 2011 +0200
logger,initctl: use global exit timeout
diff --git a/src/def.h b/src/def.h
index c23cd33..958d1eb 100644
--- a/src/def.h
+++ b/src/def.h
@@ -27,6 +27,8 @@
#define DEFAULT_TIMEOUT_USEC (3*USEC_PER_MINUTE)
#define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC)
+#define DEFAULT_EXIT_USEC (5*USEC_PER_MINUTE)
+
#define SYSTEMD_CGROUP_CONTROLLER "name=systemd"
#define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
diff --git a/src/initctl.c b/src/initctl.c
index 15da459..dd74314 100644
--- a/src/initctl.c
+++ b/src/initctl.c
@@ -42,9 +42,10 @@
#include "special.h"
#include "sd-daemon.h"
#include "dbus-common.h"
+#include "def.h"
#define SERVER_FD_MAX 16
-#define TIMEOUT ((int) (10*MSEC_PER_SEC))
+#define TIMEOUT_MSEC ((int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))
typedef struct Fifo Fifo;
@@ -388,7 +389,7 @@ int main(int argc, char *argv[]) {
if ((k = epoll_wait(server.epoll_fd,
&event, 1,
- TIMEOUT)) < 0) {
+ TIMEOUT_MSEC)) < 0) {
if (errno == EINTR)
continue;
diff --git a/src/logger.c b/src/logger.c
index faa6c97..81196db 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -37,10 +37,11 @@
#include "list.h"
#include "sd-daemon.h"
#include "tcpwrap.h"
+#include "def.h"
#define STREAMS_MAX 4096
#define SERVER_FD_MAX 16
-#define TIMEOUT ((int) (5*60*MSEC_PER_SEC))
+#define TIMEOUT_MSEC ((int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))
typedef struct Stream Stream;
@@ -661,7 +662,7 @@ int main(int argc, char *argv[]) {
if ((k = epoll_wait(server.epoll_fd,
&event, 1,
- server.n_streams <= 0 ? TIMEOUT : -1)) < 0) {
+ server.n_streams <= 0 ? TIMEOUT_MSEC : -1)) < 0) {
if (errno == EINTR)
continue;
commit 7f434cf4c9a72c3291a8603a3e91dd66dde4d640
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 02:30:43 2011 +0200
ask-password: use default timeout
diff --git a/man/systemd-ask-password.xml b/man/systemd-ask-password.xml
index 7a6498d..50aec34 100644
--- a/man/systemd-ask-password.xml
+++ b/man/systemd-ask-password.xml
@@ -128,7 +128,8 @@
<term><option>--timeout=</option></term>
<listitem><para>Specify the query
- timeout in seconds.</para></listitem>
+ timeout in seconds. Defaults to
+ 3min.</para></listitem>
</varlistentry>
<varlistentry>
diff --git a/src/ask-password.c b/src/ask-password.c
index 6330369..5162f62 100644
--- a/src/ask-password.c
+++ b/src/ask-password.c
@@ -40,11 +40,12 @@
#include "util.h"
#include "strv.h"
#include "ask-password-api.h"
+#include "def.h"
static const char *arg_icon = NULL;
static const char *arg_message = NULL;
static bool arg_use_tty = true;
-static usec_t arg_timeout = 60 * USEC_PER_SEC;
+static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC;
static bool arg_accept_cached = false;
static bool arg_multiple = false;
commit 4fe60156fc45e34c7bcba4779123e15620532dff
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 02:23:51 2011 +0200
manager: drop all pending jobs when isolating
diff --git a/src/manager.c b/src/manager.c
index dfd33b0..495c8e6 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1187,13 +1187,27 @@ static void transaction_minimize_impact(Manager *m) {
} while (again);
}
-static int transaction_apply(Manager *m) {
+static int transaction_apply(Manager *m, JobMode mode) {
Iterator i;
Job *j;
int r;
/* Moves the transaction jobs to the set of active jobs */
+ if (mode == JOB_ISOLATE) {
+
+ /* When isolating first kill all installed jobs which
+ * aren't part of the new transaction */
+ HASHMAP_FOREACH(j, m->jobs, i) {
+ assert(j->installed);
+
+ if (hashmap_get(m->transaction_jobs, j->unit))
+ continue;
+
+ job_finish_and_invalidate(j, JOB_CANCELED);
+ }
+ }
+
HASHMAP_FOREACH(j, m->transaction_jobs, i) {
/* Assume merged */
assert(!j->transaction_prev);
@@ -1322,7 +1336,7 @@ static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
}
/* Tenth step: apply changes */
- if ((r = transaction_apply(m)) < 0) {
+ if ((r = transaction_apply(m, mode)) < 0) {
log_warning("Failed to apply transaction: %s", strerror(-r));
goto rollback;
}
commit c8f4d7642b743c79328e10e8fb2d9b58e9f6b999
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 03:55:03 2011 +0200
manager: introduce IgnoreOnIsolate flag so that we can keep systemd-logger around when isolating
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 0fc2fbe..65a76be 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -461,6 +461,16 @@
</varlistentry>
<varlistentry>
+ <term><varname>IgnoreOnIsolate=</varname></term>
+
+ <listitem><para>Takes a boolean
+ argument. If <option>true</option>
+ this unit will not be stopped when
+ isolating another unit. Defaults to
+ <option>false</option>.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><varname>StopWhenUnneeded=</varname></term>
<listitem><para>Takes a boolean
diff --git a/src/automount.c b/src/automount.c
index f6f83d4..33c962e 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -58,6 +58,8 @@ static void automount_init(Unit *u) {
a->pipe_watch.type = WATCH_INVALID;
a->directory_mode = 0755;
+
+ a->meta.ignore_on_isolate = true;
}
static void repeat_unmout(const char *path) {
diff --git a/src/dbus-unit.h b/src/dbus-unit.h
index b9f0895..b578ff9 100644
--- a/src/dbus-unit.h
+++ b/src/dbus-unit.h
@@ -93,15 +93,18 @@
" <property name=\"ActiveExitTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"InactiveEnterTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"InactiveEnterTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
- " <property name=\"CanReload\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"CanStart\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"CanStop\" type=\"b\" access=\"read\"/>\n" \
+ " <property name=\"CanReload\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"CanIsolate\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"Job\" type=\"(uo)\" access=\"read\"/>\n" \
" <property name=\"StopWhenUnneeded\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"RefuseManualStart\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"RefuseManualStop\" type=\"b\" access=\"read\"/>\n" \
+ " <property name=\"AllowIsolate\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"DefaultDependencies\" type=\"b\" access=\"read\"/>\n" \
+ " <property name=\"OnFailureIsolate\" type=\"b\" access=\"read\"/>\n" \
+ " <property name=\"IgnoreOnIsolate\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"DefaultControlGroup\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"ControlGroup\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"NeedDaemonReload\" type=\"b\" access=\"read\"/>\n" \
@@ -158,6 +161,7 @@
{ "org.freedesktop.systemd1.Unit", "AllowIsolate", bus_property_append_bool, "b", &u->meta.allow_isolate }, \
{ "org.freedesktop.systemd1.Unit", "DefaultDependencies", bus_property_append_bool, "b", &u->meta.default_dependencies }, \
{ "org.freedesktop.systemd1.Unit", "OnFailureIsolate", bus_property_append_bool, "b", &u->meta.on_failure_isolate }, \
+ { "org.freedesktop.systemd1.Unit", "IgnoreOnIsolate", bus_property_append_bool, "b", &u->meta.ignore_on_isolate }, \
{ "org.freedesktop.systemd1.Unit", "DefaultControlGroup", bus_unit_append_default_cgroup, "s", u }, \
{ "org.freedesktop.systemd1.Unit", "ControlGroup", bus_unit_append_cgroups, "as", u }, \
{ "org.freedesktop.systemd1.Unit", "NeedDaemonReload", bus_unit_append_need_daemon_reload, "b", u }, \
diff --git a/src/device.c b/src/device.c
index 41c96ce..d507b70 100644
--- a/src/device.c
+++ b/src/device.c
@@ -70,6 +70,8 @@ static void device_init(Unit *u) {
* happen for the other units since their operations time out
* anyway. */
d->meta.job_timeout = DEFAULT_TIMEOUT_USEC;
+
+ d->meta.ignore_on_isolate = true;
}
static void device_done(Unit *u) {
@@ -583,7 +585,6 @@ const UnitVTable device_vtable = {
.no_instances = true,
.no_snapshots = true,
- .no_isolate = true,
.init = device_init,
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 3440d91..a7e16ca 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1861,6 +1861,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "AllowIsolate", config_parse_bool, 0, &u->meta.allow_isolate, "Unit" },
{ "DefaultDependencies", config_parse_bool, 0, &u->meta.default_dependencies, "Unit" },
{ "OnFailureIsolate", config_parse_bool, 0, &u->meta.on_failure_isolate, "Unit" },
+ { "IgnoreOnIsolate", config_parse_bool, 0, &u->meta.ignore_on_isolate, "Unit" },
{ "JobTimeoutSec", config_parse_usec, 0, &u->meta.job_timeout, "Unit" },
{ "ConditionPathExists", config_parse_condition_path, CONDITION_PATH_EXISTS, u, "Unit" },
{ "ConditionPathIsDirectory", config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u, "Unit" },
diff --git a/src/manager.c b/src/manager.c
index e723a1e..dfd33b0 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1619,7 +1619,7 @@ static int transaction_add_isolate_jobs(Manager *m) {
if (u->meta.id != k)
continue;
- if (UNIT_VTABLE(u)->no_isolate)
+ if (u->meta.ignore_on_isolate)
continue;
/* No need to stop inactive jobs */
diff --git a/src/mount.c b/src/mount.c
index d7a300e..2b19f49 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -80,6 +80,8 @@ static void mount_init(Unit *u) {
m->timer_watch.type = WATCH_INVALID;
m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
+
+ m->meta.ignore_on_isolate = true;
}
static void mount_unwatch_control_pid(Mount *m) {
@@ -1763,7 +1765,6 @@ const UnitVTable mount_vtable = {
.no_alias = true,
.no_instances = true,
- .no_isolate = true,
.show_status = true,
.init = mount_init,
diff --git a/src/swap.c b/src/swap.c
index c32f608..ef001a9 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -90,6 +90,8 @@ static void swap_unset_proc_swaps(Swap *s) {
s->timer_watch.type = WATCH_INVALID;
s->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
+
+ s->meta.ignore_on_isolate = true;
}
static void swap_unwatch_control_pid(Swap *s) {
@@ -1339,7 +1341,6 @@ const UnitVTable swap_vtable = {
.no_alias = true,
.no_instances = true,
- .no_isolate = true,
.show_status = true,
.init = swap_init,
diff --git a/src/unit.c b/src/unit.c
index f50477f..d7405b9 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -664,12 +664,14 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
"%s\tRefuseManualStart: %s\n"
"%s\tRefuseManualStop: %s\n"
"%s\tDefaultDependencies: %s\n"
- "%s\tOnFailureIsolate: %s\n",
+ "%s\tOnFailureIsolate: %s\n"
+ "%s\tIgnoreOnIsolate: %s\n",
prefix, yes_no(u->meta.stop_when_unneeded),
prefix, yes_no(u->meta.refuse_manual_start),
prefix, yes_no(u->meta.refuse_manual_stop),
prefix, yes_no(u->meta.default_dependencies),
- prefix, yes_no(u->meta.on_failure_isolate));
+ prefix, yes_no(u->meta.on_failure_isolate),
+ prefix, yes_no(u->meta.ignore_on_isolate));
LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
fprintf(f, "%s\tControlGroup: %s:%s\n",
diff --git a/src/unit.h b/src/unit.h
index 2c5cacd..43bbe67 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -210,6 +210,9 @@ struct Meta {
/* Isolate OnFailure unit */
bool on_failure_isolate;
+ /* Ignore this unit when isolating */
+ bool ignore_on_isolate;
+
/* Did the last condition check suceed? */
bool condition_result;
@@ -367,9 +370,6 @@ struct UnitVTable {
/* Exclude from automatic gc */
bool no_gc:1;
- /* Exclude from stopping on isolation requests */
- bool no_isolate:1;
-
/* Show status updates on the console */
bool show_status:1;
};
diff --git a/units/systemd-logger.socket b/units/systemd-logger.socket
index 8debd09..7178cc8 100644
--- a/units/systemd-logger.socket
+++ b/units/systemd-logger.socket
@@ -12,5 +12,10 @@ Description=Stdio Syslog Bridge Socket
DefaultDependencies=no
Before=sockets.target
+# Mount and swap units need this. If this socket unit is removed by an
+# isolate request the mount and and swap units would be removed too,
+# hence let's exclude this from isolate requests.
+IgnoreOnIsolate=yes
+
[Socket]
ListenStream=/run/systemd/logger
commit cfcab435088205b520d244e6111e33b98579181d
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Apr 14 02:57:13 2011 +0200
units: never pull in sysinit from utmp, so that we can shutdown from emergency mode without pulling in sysinit
diff --git a/units/syslog.target b/units/syslog.target
index 8b1626e..825b26e 100644
--- a/units/syslog.target
+++ b/units/syslog.target
@@ -12,3 +12,8 @@
[Unit]
Description=Syslog
+
+# Avoid that we conflict with shutdown.target, so that we can stay
+# until the very end and do not cancel shutdown.target if we should
+# hapen to be activated very late.
+DefaultDependencies=no
diff --git a/units/systemd-update-utmp-runlevel.service.in b/units/systemd-update-utmp-runlevel.service.in
index 865a153..614c759 100644
--- a/units/systemd-update-utmp-runlevel.service.in
+++ b/units/systemd-update-utmp-runlevel.service.in
@@ -8,7 +8,6 @@
[Unit]
Description=Notify Audit System and Update UTMP about System Runlevel Changes
DefaultDependencies=no
-Wants=local-fs.target sysinit.target
After=local-fs.target sysinit.target auditd.service runlevel1.target runlevel2.target runlevel3.target runlevel4.target runlevel5.target systemd-tmpfiles-setup.service
Before=poweroff.service reboot.service halt.service
diff --git a/units/systemd-update-utmp-shutdown.service.in b/units/systemd-update-utmp-shutdown.service.in
index c30d86d..e7c3c04 100644
--- a/units/systemd-update-utmp-shutdown.service.in
+++ b/units/systemd-update-utmp-shutdown.service.in
@@ -8,7 +8,6 @@
[Unit]
Description=Notify Audit System and Update UTMP about System Shutdown
DefaultDependencies=no
-Wants=local-fs.target sysinit.target
After=local-fs.target sysinit.target auditd.service systemd-update-utmp-runlevel.service
Before=poweroff.service reboot.service halt.service
commit 5010903819a6918c04e6cffa0edea6865cf3d5ef
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 22:22:10 2011 +0200
cryptsetup: add trailing \n
diff --git a/src/cryptsetup-generator.c b/src/cryptsetup-generator.c
index 00f4800..9b62e6a 100644
--- a/src/cryptsetup-generator.c
+++ b/src/cryptsetup-generator.c
@@ -122,12 +122,12 @@ static int create_disk(
if (options && has_option(options, "tmp"))
fprintf(f,
- "ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'",
+ "ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'\n",
name);
if (options && has_option(options, "swap"))
fprintf(f,
- "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'",
+ "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'\n",
name);
fflush(f);
commit d718bbb51bd811212c149f5ac3e9233907ebb36e
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 22:21:17 2011 +0200
manager: downgrade a few log messages
diff --git a/src/manager.c b/src/manager.c
index ad627fc..e723a1e 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1167,13 +1167,13 @@ static void transaction_minimize_impact(Manager *m) {
continue;
if (stops_running_service)
- log_info("%s/%s would stop a running service.", j->unit->meta.id, job_type_to_string(j->type));
+ log_debug("%s/%s would stop a running service.", j->unit->meta.id, job_type_to_string(j->type));
if (changes_existing_job)
- log_info("%s/%s would change existing job.", j->unit->meta.id, job_type_to_string(j->type));
+ log_debug("%s/%s would change existing job.", j->unit->meta.id, job_type_to_string(j->type));
/* Ok, let's get rid of this */
- log_info("Deleting %s/%s to minimize impact.", j->unit->meta.id, job_type_to_string(j->type));
+ log_debug("Deleting %s/%s to minimize impact.", j->unit->meta.id, job_type_to_string(j->type));
transaction_delete_job(m, j, true);
again = true;
commit 57bd42336e345cd295004e5a7e0fc9500979332c
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 23:36:23 2011 +0200
units: require syslog.socket from the logger because we simply fail if we don't have it
diff --git a/units/systemd-logger.service.in b/units/systemd-logger.service.in
index f82db15..484df7a 100644
--- a/units/systemd-logger.service.in
+++ b/units/systemd-logger.service.in
@@ -10,6 +10,7 @@
[Unit]
Description=Stdio Syslog Bridge
DefaultDependencies=no
+Requires=syslog.socket
After=syslog.socket
[Service]
commit 530add9d622fcd0a4ea70e0657ed4596d40f1e8f
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 23:31:37 2011 +0200
logger: adjust socket description to match service
diff --git a/units/systemd-logger.socket b/units/systemd-logger.socket
index 389b507..8debd09 100644
--- a/units/systemd-logger.socket
+++ b/units/systemd-logger.socket
@@ -8,7 +8,7 @@
# See systemd.special(7) for details
[Unit]
-Description=Stream Logging Socket
+Description=Stdio Syslog Bridge Socket
DefaultDependencies=no
Before=sockets.target
commit 1b5e66919d7ba5f8d307c4ac04f14e8c0c56d36e
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 23:30:33 2011 +0200
units: set stdout of kmsg syslogd to /dev/null
diff --git a/units/systemd-kmsg-syslogd.service.in b/units/systemd-kmsg-syslogd.service.in
index b81e4a3..aea7583 100644
--- a/units/systemd-kmsg-syslogd.service.in
+++ b/units/systemd-kmsg-syslogd.service.in
@@ -14,4 +14,5 @@ DefaultDependencies=no
[Service]
ExecStart=@rootlibexecdir@/systemd-kmsg-syslogd
NotifyAccess=all
+StandardOutput=null
Sockets=syslog.socket
commit 7f62e3774c08a9c14d9f69de1ae8830e94f8f1ec
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 13 23:29:51 2011 +0200
units: add --no-block when starting normal service after shell exited
diff --git a/units/emergency.service b/units/emergency.service
index a97ec5e..eff5261 100644
--- a/units/emergency.service
+++ b/units/emergency.service
@@ -19,7 +19,7 @@ WorkingDirectory=/root
ExecStartPre=-/bin/plymouth quit
ExecStartPre=-/bin/echo 'Welcome to emergency mode. Use "systemctl default" or ^D to activate default mode.'
ExecStart=-/sbin/sulogin
-ExecStopPost=/bin/systemctl --fail default
+ExecStopPost=/bin/systemctl --fail --no-block default
StandardInput=tty-force
KillMode=process
diff --git a/units/rescue.service.m4 b/units/rescue.service.m4
index 241c750..b48d085 100644
--- a/units/rescue.service.m4
+++ b/units/rescue.service.m4
@@ -26,7 +26,7 @@ m4_ifdef(`TARGET_MANDRIVA',
`EnvironmentFile=/etc/sysconfig/init
ExecStart=-/bin/bash -c "exec ${SINGLE}"',
`ExecStart=-/sbin/sulogin'))
-ExecStopPost=-/bin/systemctl --fail default
+ExecStopPost=-/bin/systemctl --fail --no-block default
StandardInput=tty-force
KillMode=process
More information about the systemd-commits
mailing list