[systemd-commits] 5 commits - Makefile.am man/daemon.xml man/systemd.path.xml man/systemd.service.xml man/systemd.socket.xml man/systemd.special.xml.in man/systemd.target.xml man/systemd.timer.xml man/systemd.unit.xml src/automount.c src/load-fragment.c src/mount.c src/path.c src/service.c src/snapshot.c src/socket.c src/special.h src/swap.c src/target.c src/timer.c src/unit.c src/unit.h units/arch units/dbus.target.in units/emergency.service units/fedora units/gentoo units/getty at .service.m4 units/.gitignore units/session units/suse units/syslog.target.in units/systemd-initctl.service.in units/systemd-initctl.socket units/systemd-logger.service.in units/systemd-logger.socket

Lennart Poettering lennart at kemper.freedesktop.org
Sat Jul 3 10:54:12 PDT 2010


 Makefile.am                      |   12 -
 man/daemon.xml                   |  369 ++++++++++++++++++++++++++++++++++-----
 man/systemd.path.xml             |   11 +
 man/systemd.service.xml          |   69 ++++---
 man/systemd.socket.xml           |   15 +
 man/systemd.special.xml.in       |   81 +++++---
 man/systemd.target.xml           |   14 +
 man/systemd.timer.xml            |   11 +
 man/systemd.unit.xml             |   36 +++
 src/automount.c                  |    5 
 src/load-fragment.c              |    1 
 src/mount.c                      |    6 
 src/path.c                       |   11 -
 src/service.c                    |   66 ++++--
 src/snapshot.c                   |   16 -
 src/socket.c                     |   21 +-
 src/special.h                    |    2 
 src/swap.c                       |    5 
 src/target.c                     |   42 ++++
 src/timer.c                      |    6 
 src/unit.c                       |   77 +++++++-
 src/unit.h                       |   14 +
 units/.gitignore                 |    1 
 units/arch/halt.service          |    1 
 units/arch/poweroff.service      |    1 
 units/arch/rc-local.service      |    7 
 units/arch/reboot.service        |    1 
 units/arch/sysinit.service       |    1 
 units/dbus.target.in             |   17 +
 units/emergency.service          |    1 
 units/fedora/halt.service        |    1 
 units/fedora/killall.service     |    1 
 units/fedora/poweroff.service    |    1 
 units/fedora/prefdm.service      |    6 
 units/fedora/rc-local.service    |    7 
 units/fedora/reboot.service      |    1 
 units/fedora/sysinit.service     |    1 
 units/gentoo/halt.service        |    1 
 units/gentoo/killall.service     |    1 
 units/gentoo/poweroff.service    |    1 
 units/gentoo/reboot.service      |    1 
 units/gentoo/xdm.service         |    9 
 units/getty at .service.m4          |    8 
 units/session/exit.service.in    |    1 
 units/suse/halt.service          |    1 
 units/suse/poweroff.service      |    1 
 units/suse/reboot.service        |    1 
 units/syslog.target.in           |    5 
 units/systemd-initctl.service.in |    1 
 units/systemd-initctl.socket     |    1 
 units/systemd-logger.service.in  |    1 
 units/systemd-logger.socket      |    1 
 52 files changed, 776 insertions(+), 196 deletions(-)

New commits:
commit 62adf224d1d3e225de072a2815dd50e973230f5c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jul 3 19:54:00 2010 +0200

    man: various man page updates

diff --git a/man/daemon.xml b/man/daemon.xml
index 1cddf38..853b3bb 100644
--- a/man/daemon.xml
+++ b/man/daemon.xml
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd.special">
+<refentry id="daemon">
 
         <refentryinfo>
                 <title>daemon</title>
@@ -55,8 +55,9 @@
                 functionality to other processes. Traditionally,
                 daemons are implemented following a scheme originating
                 in SysV Unix. Modern daemons should follow a simpler
-                yet more powerful scheme here called "new-style"
-                daemons, as implemented by systemd. </para>
+                yet more powerful scheme (here called "new-style"
+                daemons), as implemented by
+                <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>. </para>
 
                 <refsect2>
                         <title>SysV Daemons</title>
@@ -64,7 +65,7 @@
                         <para>When a traditional SysV daemon
                         starts, it should execute the following steps
                         as part of the initialization. Note that these
-                        steps are unnecessary for new-style daemons,
+                        steps are unnecessary for new-style daemons (see below),
                         and should only be implemented if compatibility
                         with SysV is essential.</para>
 
@@ -80,7 +81,7 @@
                                 <filename>/proc/self/fd</filename>,
                                 with a fallback of iterating from file
                                 descriptor 3 to the value returned by
-                                getrlimit() for
+                                <function>getrlimit()</function> for
                                 RLIMIT_NOFILE.</para></listitem>
 
                                 <listitem><para>Reset all signal
@@ -91,23 +92,30 @@
                                 SIG_DFL.</para></listitem>
 
                                 <listitem><para>Reset the signal mask
-                                using sigprocmask().</para></listitem>
+                                using
+                                <function>sigprocmask()</function>.</para></listitem>
 
-                                <listitem><para>Call fork(),
+                                <listitem><para>Sanitize the
+                                environment block, removing or
+                                resetting environment variables that
+                                might negatively impact daemon
+                                runtime.</para></listitem>
+
+                                <listitem><para>Call <function>fork()</function>,
                                 to create a background
                                 process.</para></listitem>
 
                                 <listitem><para>In the child, call
-                                setsid() to detach from any terminal
-                                and create an independent
-                                session.</para></listitem>
+                                <function>setsid()</function> to
+                                detach from any terminal and create an
+                                independent session.</para></listitem>
 
                                 <listitem><para>In the child, call
-                                fork() again, to ensure the daemon can
-                                never re-aquire a terminal
-                                again.</para></listitem>
+                                <function>fork()</function> again, to
+                                ensure the daemon can never re-aquire
+                                a terminal again.</para></listitem>
 
-                                <listitem><para>Call exit() in the
+                                <listitem><para>Call <function>exit()</function> in the
                                 first child, so that only the second
                                 child (the actual daemon process)
                                 stays around. This ensures that the
@@ -122,7 +130,7 @@
 
                                 <listitem><para>In the daemon process,
                                 reset the umask to 0, so that the file
-                                modes passed to open(), mkdir() and
+                                modes passed to <function>open()</function>, <function>mkdir()</function> and
                                 suchlike directly control the access
                                 mode of the created files and
                                 directories.</para></listitem>
@@ -135,6 +143,23 @@
                                 unmounted.</para></listitem>
 
                                 <listitem><para>In the daemon process,
+                                write the daemon PID (as returned by
+                                <function>getpid()</function>) to a
+                                PID file, for example
+                                <filename>/var/run/foobar.pid</filename>
+                                (for a hypothetical daemon "foobar"),
+                                to ensure that the daemon cannot be
+                                started more than once. This must be
+                                implemented in race-free fashion so
+                                that the PID file is only updated when
+                                at the same time it is verified that
+                                the PID previously stored in the PID
+                                file no longer exists or belongs to a
+                                foreign process. Commonly some kind of
+                                file locking is employed to implement
+                                this logic.</para></listitem>
+
+                                <listitem><para>In the daemon process,
                                 drop privileges, if possible and
                                 applicable.</para></listitem>
 
@@ -144,21 +169,25 @@
                                 complete. This can be implemented via
                                 an unnamed pipe or similar
                                 communication channel that is created
-                                before the first fork() and available
-                                in both processes.</para></listitem>
+                                before the first
+                                <function>fork()</function> and hence
+                                available in both the original and the
+                                daemon process.</para></listitem>
 
-                                <listitem><para>Call exit() in the
+                                <listitem><para>Call
+                                <function>exit()</function> in the
                                 original process. The process that
                                 invoked the daemon must be able to
-                                rely that this exit() happens after
-                                initialization is complete and all
-                                external communication channels
+                                rely that this
+                                <function>exit()</function> happens
+                                after initialization is complete and
+                                all external communication channels
                                 established and
                                 accessible.</para></listitem>
                         </orderedlist>
 
-                        <para>The BSD daemon() function should not be
-                        used, as it does only a subset of these steps.</para>
+                        <para>The BSD <function>daemon()</function> function should not be
+                        used, as it implements only a subset of these steps.</para>
 
                         <para>A daemon that needs to provide
                         compatibility with SysV systems should
@@ -190,6 +219,17 @@
                         execute them when run as new-style
                         service.</para>
 
+                        <para>Note that new-style init systems
+                        guarantee execution of daemon processes in
+                        clean process contexts: it is guaranteed that
+                        the environment block is sanitized, that the
+                        signal handlers and mask is reset and that no
+                        left-over file descriptors are passed. Daemons
+                        will be executed in their own session, and
+                        STDIN/STDOUT/STDERR connected to
+                        <filename>/dev/null</filename> unless
+                        otherwise configured. The umask is reset.</para>
+
                         <para>It is recommended for new-style daemons
                         to implement the following:</para>
 
@@ -207,9 +247,10 @@
                                 this is used by the init system to
                                 detect service errors and problems. It
                                 is recommended to follow the exit code
-                                scheme as defined in LSB
-                                recommendations for SysV init scripts
-                                (http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html).</para></listitem>
+                                scheme as defined in the <ulink
+                                url="http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html">LSB
+                                recommendations for SysV init
+                                scripts</ulink>.</para></listitem>
 
                                 <listitem><para>As much as possible,
                                 rely on systemd's functionality to
@@ -220,7 +261,10 @@
                                 implementing your own, rely on
                                 systemd's privilege dropping code
                                 instead of implementing it in the
-                                daemon, and similar.</para></listitem>
+                                daemon, and similar. See
+                                <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                                for the available
+                                controls.</para></listitem>
 
                                 <listitem><para>If possible and
                                 applicable expose the daemon's control
@@ -239,8 +283,8 @@
                                 boot-up speed; your daemon can be
                                 restarted on failure, without losing
                                 any bus requests, as the bus queues
-                                requests for activatable
-                                services.</para></listitem>
+                                requests for activatable services. See
+                                below for details.</para></listitem>
 
                                 <listitem><para>If your daemon
                                 provides services to other local
@@ -255,20 +299,21 @@
                                 protocols (such as syslog, DNS) a
                                 daemon implementing socket-based
                                 activation can be restarted without
-                                losing a single
-                                request.</para></listitem>
+                                losing a single request. See below for
+                                details.</para></listitem>
 
                                 <listitem><para>If applicable a daemon
                                 should notify the init system about
-                                startup completion or status
-                                updates via the sd_notify()
+                                startup completion or status updates
+                                via the
+                                <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                                 interface.</para></listitem>
 
                                 <listitem><para>Instead of using the
-                                syslog() call to log directly to the
+                                <function>syslog()</function> call to log directly to the
                                 system logger, a new-style daemon may
                                 choose to simply log to STDERR via
-                                fprintf(), which is then forwarded to
+                                <function>fprintf()</function>, which is then forwarded to
                                 syslog by the init system. If log
                                 priorities are necessary these can be
                                 encoded by prefixing individual log
@@ -276,30 +321,259 @@
                                 (for log priority 4 "WARNING" in the
                                 syslog priority scheme), following a
                                 similar style as the Linux kernel's
-                                printk() priority system. In fact, using
-                                this style of logging also enables the
-                                init system to optionally direct all
-                                application logging to the kernel log
-                                buffer (kmsg), as accessible via
-                                dmesg.</para></listitem>
+                                <function>printk()</function> priority system. In fact,
+                                using this style of logging also
+                                enables the init system to optionally
+                                direct all application logging to the
+                                kernel log buffer (kmsg), as
+                                accessible via
+                                <citerefentry><refentrytitle>dmesg</refentrytitle><manvolnum>1</manvolnum></citerefentry>. This
+                                kind of logging may be enabled by
+                                setting
+                                <varname>StandardError=syslog</varname>
+                                in the service unit file. For details
+                                see
+                                <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+                                and
+                                <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para></listitem>
 
                         </orderedlist>
+
+                        <para>These recommendations are similar but
+                        not identical to the <ulink
+                        url="http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/LaunchOnDemandDaemons.html#//apple_ref/doc/uid/TP40001762-104738">Apple
+                        MacOS X Daemon Requirements</ulink>.</para>
                 </refsect2>
 
                 <refsect2>
-                        <title>Bus Activation</title>
+                        <title>Socket-Based Activation</title>
                 </refsect2>
 
                 <refsect2>
-                        <title>Socket Activation</title>
+                        <title>Bus-Based Activation</title>
                 </refsect2>
 
                 <refsect2>
-                        <title>Writing Service Files</title>
+                        <title>Path-Based Activation</title>
+                </refsect2>
+
+                <refsect2>
+                        <title>Writing Systemd Unit Files</title>
+
+                        <para>When writing systemd unit files, it is
+                        recommended to consider the following
+                        suggestions:</para>
+
+                        <orderedlist>
+                                <listitem><para>If possible do not use
+                                the <varname>Type=forking</varname>
+                                setting in service files. But if you
+                                do, make sure to set the PID file path
+                                using <varname>PIDFile=</varname>. See
+                                <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                                for details.</para></listitem>
+
+                                <listitem><para>If your daemon
+                                registers a D-Bus name on the bus,
+                                make sure to use
+                                <varname>Type=dbus</varname> if
+                                possible.</para></listitem>
+
+                                <listitem><para>Make sure to set a
+                                good human-readable description string
+                                with
+                                <varname>Description=</varname>.</para></listitem>
+
+                                <listitem><para>Do not disable
+                                <varname>DefaultDependencies=</varname>,
+                                unless you really know what you do and
+                                your unit is involved in early boot or
+                                late system shutdown.</para></listitem>
+
+                                <listitem><para>Normally, little if
+                                any dependencies should need to
+                                be defined explicitly. However, if you
+                                do configure explicit dependencies, only refer to
+                                unit names listed on
+                                <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+                                or names introduced by your own
+                                package to keep the unit file
+                                operating
+                                system-independent.</para></listitem>
+
+                                <listitem><para>Make sure to include
+                                an <literal>[Install]</literal> section including
+                                installation information for the unit
+                                file. See
+                                <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                                for details. To activate your service
+                                on boot make sure to add a
+                                <varname>WantedBy=multi-user.target</varname>
+                                or
+                                <varname>WantedBy=graphical.target</varname> directive.</para></listitem>
+
+                        </orderedlist>
                 </refsect2>
 
                 <refsect2>
                         <title>Installing Service Files</title>
+
+                        <para>At the build installation time
+                        (e.g. <command>make install</command> during
+                        package build) packages are recommended to
+                        install their systemd unit files in the
+                        directory returned by <command>pkg-config
+                        systemd
+                        --variable=systemdsystemnunitdir</command>
+                        (for system services),
+                        resp. <command>pkg-config systemd
+                        --variable=systemdsessionunitdir</command>
+                        (for session services). This will make the
+                        services available in the system on explicit
+                        request but not activate them automatically
+                        during boot. Optionally, during package
+                        installation (e.g. <command>rpm -i</command>
+                        by the administrator) symlinks should be
+                        created in the systemd configuration
+                        directories via the
+                        <citerefentry><refentrytitle>systemd-install</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                        tool, to activate them automatically on
+                        boot.</para>
+
+                        <para>Packages using
+                        <citerefentry><refentrytitle>autoconf</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                        are recommended to use a configure script
+                        excerpt like the following to determine the
+                        unit installation path during source
+                        configuration:</para>
+
+                        <programlisting>PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemdsystemunitdir],
+        AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+        [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
+AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])</programlisting>
+
+                        <para>This snippet allows automatic
+                        installation of the unit files on systemd
+                        machines, and optionally allows their
+                        installation even on machines lacking
+                        systemd. (Modification of this snippet for the
+                        session unit directory is left as excercise to the
+                        reader.)</para>
+
+                        <para>Additionally, to ensure that
+                        <command>make distcheck</command> continues to
+                        work, it is recommended to add the following
+                        to the top-level <filename>Makefile.am</filename>
+                        file in
+                        <citerefentry><refentrytitle>automake</refentrytitle><manvolnum>1</manvolnum></citerefentry>-based
+                        projects:</para>
+
+                        <programlisting>DISTCHECK_CONFIGURE_FLAGS = \
+        --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)</programlisting>
+
+                        <para>Finally, unit files should be installed in the system with an automake excerpt like the following:</para>
+
+                        <programlisting>if HAVE_SYSTEMD
+systemdsystemunit_DATA = \
+        foobar.socket \
+        foobar.service
+endif</programlisting>
+
+                        <para>In the
+                        <citerefentry><refentrytitle>rpm</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+                        <filename>.spec</filename> file use a snippet like
+                        the following to enable/disable the service
+                        during installation/deinstallation. Consult
+                        the packaging guidelines of your distribution
+                        for details and the equivalent for other
+                        packaging managers:</para>
+
+                        <programlisting>%post
+/usr/bin/systemd-install enable foobar.service foobar.socket >/dev/null 2>&amp;1 || :
+
+%preun
+if [ "$1" -eq 0 ]; then
+        /usr/bin/systemd-install disable foobar.service foobar.socket >/dev/null 2>&amp;1 || :
+fi</programlisting>
+
+                </refsect2>
+
+                <refsect2>
+                        <title>Porting Existing Daemons</title>
+
+                        <para>Since new-style init systems such as
+                        systemd are compatible with traditional SysV
+                        init systems it is not strictly necessary to
+                        port existing daemons to the new
+                        style. However doing this offers additional
+                        functionality to the daemons as well as it
+                        simplifies integration into new-style init
+                        systems.</para>
+
+                        <para>To port an existing SysV compatible
+                        daemon the following steps are
+                        recommended:</para>
+
+                        <orderedlist>
+                                <listitem><para>If not already
+                                implemented, add an optional command
+                                line switch to the daemon to disable
+                                daemonization. This is useful not only
+                                for using the daemon in new-style init
+                                systems, but also to ease debugging.</para></listitem>
+
+                                <listitem><para>If the daemon offers
+                                interfaces to other software running
+                                on the local system via local AF_UNIX
+                                sockets, consider implementing
+                                socket-based activation (see
+                                above). Usually a minimal patch is
+                                sufficient to implement this: Extend
+                                the socket creation in the daemon code
+                                so that
+                                <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                                is checked for already passed sockets
+                                first. If sockets are passed
+                                (i.e. when
+                                <function>sd_listen_fds()</function>
+                                returns a positive value), skip the
+                                socket createn step and use the passed
+                                sockets. Secondly, ensure that the
+                                file-system socket nodes for local
+                                AF_UNIX sockets used in the
+                                socket-based activation are not
+                                removed when the daemon shuts down, if
+                                sockets have been passed. Third, if
+                                the daemon normally closes all
+                                remaining open file descriptors as
+                                part of its initialization, the
+                                sockets passed from the init system
+                                must be spared. Since new-style init
+                                systems guarantee that no left-over
+                                file descriptors are passed to
+                                executed processes, it might be a good
+                                choice to simply skip the closing of
+                                all remaining open file descriptors if
+                                file descriptors are
+                                passed.</para></listitem>
+
+                                <listitem><para>Write and install a
+                                systemd unit file for the service (and
+                                the sockets if socket-based activation
+                                is used, as well as a path unit file,
+                                if the daemon processes a spool
+                                directory), see above for
+                                details.</para></listitem>
+
+                                <listitem><para>If the daemon exposes
+                                interfaces via D-Bus, write and
+                                install a D-Bus activation file for
+                                the service, see above for
+                                details.</para></listitem>
+                        </orderedlist>
+
                 </refsect2>
 
         </refsect1>
@@ -309,8 +583,11 @@
                 <title>See Also</title>
                 <para>
                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
-                        <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-                        <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                        <citerefentry><refentrytitle>systemd-install</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 </para>
         </refsect1>
 
diff --git a/man/systemd.path.xml b/man/systemd.path.xml
index 7721900..d910d2c 100644
--- a/man/systemd.path.xml
+++ b/man/systemd.path.xml
@@ -87,6 +87,17 @@
                 <para>If an path unit is beneath another mount
                 point in the file system hierarchy, a dependency
                 between both units is created automatically.</para>
+
+                <para>Unless <varname>DefaultDependencies=</varname>
+                is set to <option>false</option>, path units will
+                implicitly have dependencies of type
+                <varname>Conflicts=</varname> and
+                <varname>Before=</varname> on
+                <filename>shutdown.target</filename>. These ensure
+                that path units are terminated cleanly prior to system
+                shutdown. Only path units involved with early boot or
+                late system shutdown should disable this
+                option.</para>
         </refsect1>
 
         <refsect1>
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
index b01641f..91d6d09 100644
--- a/man/systemd.service.xml
+++ b/man/systemd.service.xml
@@ -64,27 +64,44 @@
                 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
                 for the common options of all unit configuration
                 files. The common configuration items are configured
-                in the generic [Unit] and [Install] sections. The
-                service specific configuration options are configured
-                in the [Service] section.</para>
+                in the generic <literal>[Unit]</literal> and
+                <literal>[Install]</literal> sections. The service
+                specific configuration options are configured in the
+                <literal>[Service]</literal> section.</para>
 
                 <para>Additional options are listed in
                 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
                 which define the execution environment the commands
                 are executed in.</para>
+
+                <para>Unless <varname>DefaultDependencies=</varname>
+                is set to <option>false</option>, service units will
+                implicitly have dependencies of type
+                <varname>Requires=</varname> and
+                <varname>After=</varname> on
+                <filename>basic.target</filename> as well as
+                dependencies of type <varname>Conflicts=</varname> and
+                <varname>Before=</varname> on
+                <filename>shutdown.target</filename>. These ensure
+                that normal service units pull in basic system
+                initialization, and are terminated cleanly prior to
+                system shutdown. Only services involved with early
+                boot or late system shutdown should disable this
+                option.</para>
         </refsect1>
 
         <refsect1>
                 <title>Options</title>
 
-                <para>Service files must include a [Service] section,
-                which carries information about the service and the
-                process it supervises. A number of options that may be
-                used in this section are shared with other unit
-                types. These options are documented in
+                <para>Service files must include a
+                <literal>[Service]</literal> section, which carries
+                information about the service and the process it
+                supervises. A number of options that may be used in
+                this section are shared with other unit types. These
+                options are documented in
                 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. The
-                options specific to the [Service] section of service
-                units are the following:</para>
+                options specific to the <literal>[Service]</literal>
+                section of service units are the following:</para>
 
                 <variablelist>
                         <varlistentry>
@@ -143,14 +160,18 @@
 
                                 <para>Behaviour of
                                 <option>dbus</option> is similar to
-                                <option>simple</option>, however it
-                                is expected that the daemon acquires a
+                                <option>simple</option>, however it is
+                                expected that the daemon acquires a
                                 name on the D-Bus bus, as configured
                                 by
                                 <varname>BusName=</varname>. systemd
                                 will proceed starting follow-up units
                                 after the D-Bus bus name has been
-                                acquired.</para>
+                                acquired. Service units with this
+                                option configured implicitly have
+                                dependencies on the
+                                <filename>dbus.target</filename>
+                                unit.</para>
 
                                 <para>Behaviour of
                                 <option>notify</option> is similar to
@@ -163,10 +184,13 @@
                                 starting follow-up units after this
                                 notification message has been sent. If
                                 this option is used
-                                <option>NotifyAccess=</option> (see
+                                <varname>NotifyAccess=</varname> (see
                                 below) must be set to open access to
                                 the notification socket provided by
-                                systemd.</para>
+                                systemd. If
+                                <varname>NotifyAccess=</varname> is not
+                                set, it will be implicitly set to
+                                <option>main</option>.</para>
                                 </listitem>
                         </varlistentry>
 
@@ -220,11 +244,12 @@
                                 services. This option may not be
                                 specified more than once. Optionally,
                                 if the absolute file name is prefixed
-                                with @, the second token will be
-                                passed as argv[0] to the executed
-                                process, followed by the further
-                                arguments specified. Unless
-                                <option>Type=forking</option> is set,
+                                with <literal>@</literal>, the second
+                                token will be passed as
+                                <literal>argv[0]</literal> to the
+                                executed process, followed by the
+                                further arguments specified. Unless
+                                <varname>Type=forking</varname> is set,
                                 the process started via this command
                                 line will be considered the main
                                 process of the
@@ -312,7 +337,7 @@
                                 forcibly via SIGTERM, and after
                                 another delay of this time with
                                 SIGKILL. (See
-                                <option>KillMode=</option>
+                                <varname>KillMode=</varname>
                                 below.) Takes a unit-less value in seconds, or a
                                 time span value such as "5min
                                 20s". Pass 0 to disable the timeout
@@ -450,7 +475,7 @@
                                 <para>Processes will first be
                                 terminated via SIGTERM. If then after
                                 a delay (configured via the
-                                <option>TimeoutSec=</option> option)
+                                <varname>TimeoutSec=</varname> option)
                                 processes still remain, the
                                 termination request is repeated with
                                 the SIGKILL signal. See
diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index 986ef8c..6154b30 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -95,6 +95,21 @@
                 which services are instantiated for each incoming
                 connection.</para>
 
+                <para>Unless <varname>DefaultDependencies=</varname>
+                is set to <option>false</option>, socket units will
+                implicitly have dependencies of type
+                <varname>Requires=</varname> and
+                <varname>After=</varname> on
+                <filename>sysinit.target</filename> as well as
+                dependencies of type <varname>Conflicts=</varname> and
+                <varname>Before=</varname> on
+                <filename>shutdown.target</filename>. These ensure
+                that socket units pull in basic system
+                initialization, and are terminated cleanly prior to
+                system shutdown. Only sockets involved with early
+                boot or late system shutdown should disable this
+                option.</para>
+
                 <para>Socket units may be used to implement on-demand
                 starting of services, as well as parallelized starting
                 of services.</para>
diff --git a/man/systemd.special.xml.in b/man/systemd.special.xml.in
index 79c6db1..49dc389 100644
--- a/man/systemd.special.xml.in
+++ b/man/systemd.special.xml.in
@@ -51,6 +51,7 @@
                 <para><filename>basic.target</filename>,
                 <filename>ctrl-alt-del.target</filename>,
                 <filename>@SPECIAL_DBUS_SERVICE@</filename>,
+                <filename>dbus.target</filename>,
                 <filename>default.target</filename>,
                 <filename>display-manager.service</filename>,
                 <filename>emergency.service</filename>,
@@ -78,8 +79,8 @@
                 <filename>sockets.target</filename>,
                 <filename>swap.target</filename>,
                 <filename>sysinit.target</filename>,
-                <filename>syslog.target</filename>,
                 <filename>@SPECIAL_SYSLOG_SERVICE@</filename>,
+                <filename>syslog.target</filename>,
                 <filename>systemd-initctl.service</filename>,
                 <filename>systemd-initctl.socket</filename>,
                 <filename>systemd-logger.service</filename>,
@@ -141,6 +142,28 @@
                                         up systemd will connect to it
                                         and register its
                                         service.</para>
+
+                                        <para>Units should generally
+                                        avoid depending on this unit
+                                        directly and instead refer to
+                                        the
+                                        <filename>dbus.target</filename>
+                                        unit instead, which pulls this
+                                        one in directly or indirectly
+                                        via socket-based activation.</para>
+                                </listitem>
+                        </varlistentry>
+                        <varlistentry>
+                                <term><filename>dbus.target</filename></term>
+                                <listitem>
+                                        <para>Administrators should
+                                        ensure that this target pulls
+                                        in a service unit with the
+                                        name or alias of
+                                        <filename>@SPECIAL_DBUS_SERVICE@</filename>
+                                        (or a socket unit that
+                                        activates this
+                                        service).</para>
                                 </listitem>
                         </varlistentry>
                         <varlistentry>
@@ -523,28 +546,6 @@
                                 </listitem>
                         </varlistentry>
                         <varlistentry>
-                                <term><filename>syslog.target</filename></term>
-                                <listitem>
-                                        <para>systemd automatically
-                                        adds dependencies of type
-                                        After for this target unit to
-                                        all SysV init script service
-                                        units with an LSB header
-                                        referring to the
-                                        <literal>$syslog</literal>
-                                        facility.</para>
-
-                                        <para>Administrators should
-                                        ensure that this target pulls
-                                        in a service unit with the
-                                        name or alias of
-                                        <filename>@SPECIAL_SYSLOG_SERVICE@</filename>
-                                        (or a socket unit that
-                                        activates this
-                                        service).</para>
-                                </listitem>
-                        </varlistentry>
-                        <varlistentry>
                                 <term><filename>sysinit.target</filename></term>
                                 <listitem>
                                         <para>A special target unit
@@ -571,11 +572,37 @@
                                         and use it for logging if it
                                         has been configured for
                                         that.</para>
-                                        <para>Applications should
-                                        generally not depend on this
-                                        service, and depend on
+
+                                        <para>Units should generally
+                                        avoid depending on this unit
+                                        directly and instead refer to
+                                        the
                                         <filename>syslog.target</filename>
-                                        instead.</para>
+                                        unit instead, which pulls this
+                                        one in directly or indirectly
+                                        via socket-based activation.</para>
+                                </listitem>
+                        </varlistentry>
+                        <varlistentry>
+                                <term><filename>syslog.target</filename></term>
+                                <listitem>
+                                        <para>systemd automatically
+                                        adds dependencies of type
+                                        After for this target unit to
+                                        all SysV init script service
+                                        units with an LSB header
+                                        referring to the
+                                        <literal>$syslog</literal>
+                                        facility.</para>
+
+                                        <para>Administrators should
+                                        ensure that this target pulls
+                                        in a service unit with the
+                                        name or alias of
+                                        <filename>@SPECIAL_SYSLOG_SERVICE@</filename>
+                                        (or a socket unit that
+                                        activates this
+                                        service).</para>
                                 </listitem>
                         </varlistentry>
                         <varlistentry>
diff --git a/man/systemd.target.xml b/man/systemd.target.xml
index 88a9e6e..6f3bc18 100644
--- a/man/systemd.target.xml
+++ b/man/systemd.target.xml
@@ -76,12 +76,22 @@
                 dependencies between units. Among other things, target
                 units are a more flexible replacement for SysV
                 runlevels in the classic SysV init system. (And for
-                compatibility reasons there exist special
+                compatibility reasons special
                 target units such as
-                <filename>runlevel3.target</filename> which are used by
+                <filename>runlevel3.target</filename> exist which are used by
                 the SysV runlevel compatibility code in systemd. See
                 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
                 for details).</para>
+
+                <para>Unless
+                <varname>DefaultDependencies=</varname> is set to
+                <option>false</option>, target units will
+                implicitly complement all configured dependencies of type
+                <varname>Wants=</varname>,
+                <varname>Requires=</varname>,
+                <varname>RequiresOverridable=</varname> with
+                dependencies of type <varname>After=</varname>.
+                </para>
         </refsect1>
 
         <refsect1>
diff --git a/man/systemd.timer.xml b/man/systemd.timer.xml
index 7a4cd34..ef89693 100644
--- a/man/systemd.timer.xml
+++ b/man/systemd.timer.xml
@@ -76,6 +76,17 @@
                 matching service <filename>foo.service</filename>. The
                 unit to activate may be controlled by
                 <varname>Unit=</varname> (see below).</para>
+
+                <para>Unless <varname>DefaultDependencies=</varname>
+                is set to <option>false</option>, timer units will
+                implicitly have dependencies of type
+                <varname>Conflicts=</varname> and
+                <varname>Before=</varname> on
+                <filename>shutdown.target</filename>. These ensure
+                that timer units are stopped cleanly prior to system
+                shutdown. Only timer units involved with early boot or
+                late system shutdown should disable this
+                option.</para>
         </refsect1>
 
         <refsect1>
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 9c4269f..26272c4 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -215,10 +215,10 @@
                         <varlistentry>
                                 <term><varname>Description=</varname></term>
                                 <listitem><para>A free-form string
-                                describing the unit. This is intended for use
-                                in UIs wanting to show
-                                descriptive information along with the
-                                unit name.</para></listitem>
+                                describing the unit. This is intended
+                                for use in UIs to show descriptive
+                                information along with the unit
+                                name.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
@@ -451,6 +451,34 @@
                                 <option>false</option>.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>DefaultDependencies=</varname></term>
+
+                                <listitem><para>Takes a boolean
+                                argument. If <option>true</option>
+                                (the default), a few default
+                                dependencies will implicitly be
+                                created for the unit. The actual
+                                dependencies created depend on the
+                                unit type. For example, for service
+                                units, these dependencies ensure that
+                                the service is started only after
+                                basic system initialization is
+                                complete and is properly terminated on
+                                system shutdown. See the respective
+                                man pages for details. Generally, only
+                                services involved with early boot or
+                                late shutdown should set this option
+                                to <option>false</option>. It is
+                                highly recommended to leave this
+                                option enabled for the majority of
+                                common units. If set to
+                                <option>false</option> this option
+                                does not disable all implicit
+                                dependencies, just non-essential
+                                ones.</para></listitem>
+                        </varlistentry>
+
                 </variablelist>
 
                 <para>Unit file may include a [Install] section, which
commit af65a09126e216d468592f069aee50dfe0382d3a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jul 3 19:53:37 2010 +0200

    units: update shipped unit files for DefaultDependencies=

diff --git a/Makefile.am b/Makefile.am
index 013f424..d1ce02c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -146,7 +146,8 @@ nodist_systemunit_DATA = \
 	units/multi-user.target \
 	units/systemd-initctl.service \
 	units/systemd-logger.service \
-	units/syslog.target
+	units/syslog.target \
+	units/dbus.target
 
 dist_sessionunit_DATA = \
 	units/session/default.target
@@ -164,6 +165,7 @@ EXTRA_DIST = \
 	units/systemd-initctl.service.in \
 	units/systemd-logger.service.in \
 	units/syslog.target.in \
+	units/dbus.target.in \
 	units/session/exit.service.in \
 	systemd.pc.in
 
@@ -738,8 +740,8 @@ if TARGET_FEDORA
 		rm -f display-manager.service && \
 		$(LN_S) $(systemunitdir)/prefdm.service display-manager.service )
 	( cd $(DESTDIR)$(pkgsysconfdir)/system/graphical.target.wants && \
-		rm -f display-manager.service && \
-		$(LN_S) ../display-manager.service display-manager.service )
+		rm -f prefdm.service && \
+		$(LN_S) ../prefdm.service prefdm.service )
 	( cd $(DESTDIR)$(pkgsysconfdir)/system/multi-user.target.wants && \
 		rm -f rc-local.service && \
 		$(LN_S) $(systemunitdir)/rc-local.service rc-local.service )
@@ -754,8 +756,8 @@ if TARGET_GENTOO
 		rm -f display-manager.service && \
 		$(LN_S) $(systemunitdir)/xdm.service display-manager.service )
 	( cd $(DESTDIR)$(pkgsysconfdir)/system/graphical.target.wants && \
-		rm -f display-manager.service && \
-		$(LN_S) ../display-manager.service display-manager.service )
+		rm -f prefdm.service && \
+		$(LN_S) ../prefdm.service prefdm.service )
 endif
 
 DISTCHECK_CONFIGURE_FLAGS = \
diff --git a/units/.gitignore b/units/.gitignore
index ea85dc0..75d3bfd 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -6,3 +6,4 @@ graphical.target
 multi-user.target
 getty at .service
 remote-fs.target
+dbus.target
diff --git a/units/arch/halt.service b/units/arch/halt.service
index 445ca48..96553f1 100644
--- a/units/arch/halt.service
+++ b/units/arch/halt.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Halt
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/arch/poweroff.service b/units/arch/poweroff.service
index 3ca8f30..d6e42e1 100644
--- a/units/arch/poweroff.service
+++ b/units/arch/poweroff.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Power-Off
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/arch/rc-local.service b/units/arch/rc-local.service
index 45b6e16..596861a 100644
--- a/units/arch/rc-local.service
+++ b/units/arch/rc-local.service
@@ -7,10 +7,6 @@
 
 [Unit]
 Description=/etc/rc.local Compatibility
-Requires=basic.target
-After=basic.target
-Conflicts=shutdown.target
-Before=getty at tty1.service
 
 [Service]
 ExecStart=/etc/rc.local
@@ -18,3 +14,6 @@ ExectStop=/etc/rc.local.shutdown
 TimeoutSec=0
 StandardInput=tty
 ValidNoProcess=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/units/arch/reboot.service b/units/arch/reboot.service
index 4aa7dc2..b2c1884 100644
--- a/units/arch/reboot.service
+++ b/units/arch/reboot.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Reboot
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/arch/sysinit.service b/units/arch/sysinit.service
index 8be50d7..1a19baf 100644
--- a/units/arch/sysinit.service
+++ b/units/arch/sysinit.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=System Initialization
+DefaultDependencies=no
 Before=local-fs.target remote-fs.target swap.target sockets.target
 Conflicts=shutdown.target
 Before=shutdown.target
diff --git a/units/dbus.target.in b/units/dbus.target.in
new file mode 100644
index 0000000..6faf58d
--- /dev/null
+++ b/units/dbus.target.in
@@ -0,0 +1,17 @@
+#  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=D-Bus
+
+# As soon as D-Bus has native files this explicit dependency should be
+# dropped, and replaced by an alias symlink in the .wants/ directory,
+# to either the .service or .socket unit of the D-Bus service.
+Requires=@SPECIAL_DBUS_SERVICE@
+After=@SPECIAL_DBUS_SERVICE@
diff --git a/units/emergency.service b/units/emergency.service
index 924723f..83b7d72 100644
--- a/units/emergency.service
+++ b/units/emergency.service
@@ -9,6 +9,7 @@
 
 [Unit]
 Description=Emergency Shell
+DefaultDependencies=no
 
 [Service]
 ExecStart=/bin/sh
diff --git a/units/fedora/halt.service b/units/fedora/halt.service
index 50373d4..815c8fb 100644
--- a/units/fedora/halt.service
+++ b/units/fedora/halt.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Halt
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/fedora/killall.service b/units/fedora/killall.service
index 84c56cb..8ccbbce 100644
--- a/units/fedora/killall.service
+++ b/units/fedora/killall.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Kill All Processes
+DefaultDependencies=no
 After=shutdown.target
 OnlyByDependency=yes
 
diff --git a/units/fedora/poweroff.service b/units/fedora/poweroff.service
index f237e32..2149dbf 100644
--- a/units/fedora/poweroff.service
+++ b/units/fedora/poweroff.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Power-Off
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/fedora/prefdm.service b/units/fedora/prefdm.service
index 2f4333f..89a96be 100644
--- a/units/fedora/prefdm.service
+++ b/units/fedora/prefdm.service
@@ -7,13 +7,11 @@
 
 [Unit]
 Description=Display Manager
-Before=graphical.target
-Requires=basic.target
-After=basic.target syslog.target messagebus.service haldaemon.service
-Conflicts=shutdown.target
+After=syslog.target dbus.target haldaemon.service
 
 [Service]
 ExecStart=/etc/X11/prefdm -nodaemon
 
 [Install]
 Alias=display-manager.service
+WantedBy=graphical.target
diff --git a/units/fedora/rc-local.service b/units/fedora/rc-local.service
index 58b5982..c2d2e00 100644
--- a/units/fedora/rc-local.service
+++ b/units/fedora/rc-local.service
@@ -7,10 +7,6 @@
 
 [Unit]
 Description=/etc/rc.local Compatibility
-Requires=basic.target
-After=basic.target
-Conflicts=shutdown.target
-Before=getty at tty1.service
 
 # The rcN.d symlink uses the name "local" while the script itself is
 # called "rc.local", hence carry both names here.
@@ -22,3 +18,6 @@ TimeoutSec=0
 StandardInput=tty
 ValidNoProcess=yes
 SysVStartPriority=99
+
+[Install]
+WantedBy=multi-user.target
diff --git a/units/fedora/reboot.service b/units/fedora/reboot.service
index b99dfdc..31aa74e 100644
--- a/units/fedora/reboot.service
+++ b/units/fedora/reboot.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Reboot
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/fedora/sysinit.service b/units/fedora/sysinit.service
index 5981552..884de8d 100644
--- a/units/fedora/sysinit.service
+++ b/units/fedora/sysinit.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=System Initialization
+DefaultDependencies=no
 Before=local-fs.target remote-fs.target swap.target sockets.target
 Conflicts=shutdown.target
 Before=shutdown.target
diff --git a/units/gentoo/halt.service b/units/gentoo/halt.service
index c5d9604..ecf4cff 100644
--- a/units/gentoo/halt.service
+++ b/units/gentoo/halt.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Halt
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/gentoo/killall.service b/units/gentoo/killall.service
index 626e9d1..ce4d99e 100644
--- a/units/gentoo/killall.service
+++ b/units/gentoo/killall.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Kill All Processes
+DefaultDependencies=no
 After=shutdown.target
 OnlyByDependency=yes
 
diff --git a/units/gentoo/poweroff.service b/units/gentoo/poweroff.service
index 2cc645e..2ae1fd7 100644
--- a/units/gentoo/poweroff.service
+++ b/units/gentoo/poweroff.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Power-Off
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/gentoo/reboot.service b/units/gentoo/reboot.service
index fdca6f8..353fb4b 100644
--- a/units/gentoo/reboot.service
+++ b/units/gentoo/reboot.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Reboot
+DefaultDependencies=no
 Requires=shutdown.target killall.service
 After=shutdown.target killall.service
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/gentoo/xdm.service b/units/gentoo/xdm.service
index ac1df75..b94c6a8 100644
--- a/units/gentoo/xdm.service
+++ b/units/gentoo/xdm.service
@@ -7,10 +7,11 @@
 
 [Unit]
 Description=Display Manager
-Before=graphical.target
-Requires=basic.target
-After=basic.target syslog.target dbus.service hald.service
-Conflicts=shutdown.target
+After=syslog.target dbus.target hald.service
 
 [Service]
 ExecStart=/etc/init.d/xdm start
+
+[Install]
+Alias=display-manager.service
+WantedBy=graphical.target
diff --git a/units/getty at .service.m4 b/units/getty at .service.m4
index 5f6944f..f1f7f32 100644
--- a/units/getty at .service.m4
+++ b/units/getty at .service.m4
@@ -14,8 +14,12 @@ m4_dnl
 [Unit]
 Description=Getty on %I
 Before=getty.target
-After=basic.target
-Conflicts=shutdown.target
+m4_ifdef(`TARGET_FEDORA',
+After=rc-local.service
+)m4_dnl
+m4_ifdef(`TARGET_ARCH',
+After=rc-local.service
+)m4_dnl
 
 [Service]
 Environment=TERM=linux
diff --git a/units/session/exit.service.in b/units/session/exit.service.in
index 86c8bbc..1f515a7 100644
--- a/units/session/exit.service.in
+++ b/units/session/exit.service.in
@@ -1,5 +1,6 @@
 [Unit]
 Description=Exit
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 
diff --git a/units/suse/halt.service b/units/suse/halt.service
index bc237f0..fbcf154 100644
--- a/units/suse/halt.service
+++ b/units/suse/halt.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Halt
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/suse/poweroff.service b/units/suse/poweroff.service
index a68c10c..3da6cf1 100644
--- a/units/suse/poweroff.service
+++ b/units/suse/poweroff.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Power-Off
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/suse/reboot.service b/units/suse/reboot.service
index 3dbb469..902648c 100644
--- a/units/suse/reboot.service
+++ b/units/suse/reboot.service
@@ -7,6 +7,7 @@
 
 [Unit]
 Description=Reboot
+DefaultDependencies=no
 Requires=shutdown.target
 After=shutdown.target
 Conflicts=dev-hugepages.automount dev-mqueue.automount proc-sys-fs-binfmt_misc.automount sys-kernel-debug.automount sys-kernel-security.automount
diff --git a/units/syslog.target.in b/units/syslog.target.in
index 3057eda..b9c4f18 100644
--- a/units/syslog.target.in
+++ b/units/syslog.target.in
@@ -9,5 +9,10 @@
 
 [Unit]
 Description=Syslog
+
+# As soon as all syslog services have native unit files this explicit
+# dependency should be dropped, and replaced by alias symlinks in the
+# .wants/ directory, to either the .service or .socket unit of the
+# syslog service.
 Requires=@SPECIAL_SYSLOG_SERVICE@
 After=@SPECIAL_SYSLOG_SERVICE@
diff --git a/units/systemd-initctl.service.in b/units/systemd-initctl.service.in
index 7450e07..6d56e12 100644
--- a/units/systemd-initctl.service.in
+++ b/units/systemd-initctl.service.in
@@ -9,6 +9,7 @@
 
 [Unit]
 Description=systemd /dev/initctl Compatibility Daemon
+DefaultDependencies=no
 
 [Service]
 ExecStart=@rootlibexecdir@/systemd-initctl
diff --git a/units/systemd-initctl.socket b/units/systemd-initctl.socket
index 26b526c..3db2683 100644
--- a/units/systemd-initctl.socket
+++ b/units/systemd-initctl.socket
@@ -9,6 +9,7 @@
 
 [Unit]
 Description=systemd /dev/initctl Compatibility Socket
+DefaultDependencies=no
 After=sysinit.target
 Before=sockets.target
 
diff --git a/units/systemd-logger.service.in b/units/systemd-logger.service.in
index 2004438..2a9ec21 100644
--- a/units/systemd-logger.service.in
+++ b/units/systemd-logger.service.in
@@ -9,6 +9,7 @@
 
 [Unit]
 Description=systemd Logging Daemon
+DefaultDependencies=no
 After=@SPECIAL_SYSLOG_SERVICE@
 
 [Service]
diff --git a/units/systemd-logger.socket b/units/systemd-logger.socket
index 44684ce..57a590d 100644
--- a/units/systemd-logger.socket
+++ b/units/systemd-logger.socket
@@ -9,6 +9,7 @@
 
 [Unit]
 Description=systemd Logging Socket
+DefaultDependencies=no
 After=sysinit.target
 Before=sockets.target
 
commit daf32cc791f26e2a9849e25b94304839e20fcc3b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jul 3 19:51:24 2010 +0200

    snapshot: downgrade automatic dependencies from Requires to Wants

diff --git a/src/snapshot.c b/src/snapshot.c
index 399aaea..ba72edc 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -122,8 +122,8 @@ static int snapshot_serialize(Unit *u, FILE *f, FDSet *fds) {
 
         unit_serialize_item(u, f, "state", snapshot_state_to_string(s->state));
         unit_serialize_item(u, f, "cleanup", yes_no(s->cleanup));
-        SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
-                unit_serialize_item(u, f, "requires", other->meta.id);
+        SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
+                unit_serialize_item(u, f, "wants", other->meta.id);
 
         return 0;
 }
@@ -152,12 +152,9 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value
                 else
                         s->cleanup = r;
 
-        } else if (streq(key, "requires")) {
+        } else if (streq(key, "wants")) {
 
-                if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, value, NULL, true)) < 0)
-                        return r;
-
-                if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, value, NULL, true)) < 0)
+                if ((r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, value, NULL, true)) < 0)
                         return r;
         } else
                 log_debug("Unknown serialization key '%s'", key);
@@ -237,10 +234,7 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
                 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
                         continue;
 
-                if ((r = unit_add_dependency(u, UNIT_REQUIRES, other, true)) < 0)
-                        goto fail;
-
-                if ((r = unit_add_dependency(u, UNIT_AFTER, other, true)) < 0)
+                if ((r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_WANTS, other, true)) < 0)
                         goto fail;
         }
 
commit a40eb73224e237f758d38847ae216c019425ebac
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jul 3 19:48:33 2010 +0200

    unit: add DefaultDependencies= setting
    
    In order to simplify writing of unit files introduce default
    dependencies that are added to all units unless explictly disabled in a
    unit. This option can be switched off for select units that are involved
    in early boot-up ot late system shutdown,
    
    This should simplify service files for most normal daemons, but breaks
    existing service files for software involved in early boot (notably
    udev), which need to be updated for a DefaultDependencies=no setting)

diff --git a/src/load-fragment.c b/src/load-fragment.c
index 49b577f..e5c7ba2 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1506,6 +1506,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "RecursiveStop",          config_parse_bool,            &u->meta.recursive_stop,                         "Unit"    },
                 { "StopWhenUnneeded",       config_parse_bool,            &u->meta.stop_when_unneeded,                     "Unit"    },
                 { "OnlyByDependency",       config_parse_bool,            &u->meta.only_by_dependency,                     "Unit"    },
+                { "DefaultDependencies",    config_parse_bool,            &u->meta.default_dependencies,                   "Unit"    },
 
                 { "PIDFile",                config_parse_path,            &u->service.pid_file,                            "Service" },
                 { "ExecStartPre",           config_parse_exec,            u->service.exec_command+SERVICE_EXEC_START_PRE,  "Service" },
diff --git a/src/path.c b/src/path.c
index 56936fd..30d946d 100644
--- a/src/path.c
+++ b/src/path.c
@@ -29,6 +29,7 @@
 #include "unit-name.h"
 #include "path.h"
 #include "dbus-path.h"
+#include "special.h"
 
 static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
         [PATH_DEAD] = UNIT_INACTIVE,
@@ -120,6 +121,11 @@ static int path_load(Unit *u) {
 
                 if ((r = path_add_mount_links(p)) < 0)
                         return r;
+
+                /* Path units shouldn't stay around on shutdown */
+                if (p->meta.default_dependencies)
+                        if ((r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0)
+                                return r;
         }
 
         return path_verify(p);
diff --git a/src/service.c b/src/service.c
index cbc9c95..04ed684 100644
--- a/src/service.c
+++ b/src/service.c
@@ -665,20 +665,18 @@ static int service_load_sysv_path(Service *s, const char *path) {
         if ((r = sysv_exec_commands(s)) < 0)
                 goto finish;
 
-        if (!s->sysv_runlevels || chars_intersect(RUNLEVELS_UP, s->sysv_runlevels)) {
+        if (s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels)) {
                 /* If there a runlevels configured for this service
                  * but none of the standard ones, then we assume this
                  * is some special kind of service (which might be
                  * needed for early boot) and don't create any links
                  * to it. */
 
-                if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_BASIC_TARGET, NULL, true)) < 0 ||
-                    (r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_BASIC_TARGET, NULL, true)) < 0)
-                        goto finish;
+                s->meta.default_dependencies = false;
 
-        } else
                 /* Don't timeout special services during boot (like fsck) */
                 s->timeout_usec = 0;
+        }
 
         /* Special setting for all SysV services */
         s->type = SERVICE_FORKING;
@@ -827,6 +825,30 @@ static int service_verify(Service *s) {
         return 0;
 }
 
+static int service_add_default_dependencies(Service *s) {
+        int r;
+
+        assert(s);
+
+        /* Add a number of automatic dependencies useful for the
+         * majority of services. */
+
+        /* First, pull in base system */
+        if (s->meta.manager->running_as == MANAGER_SYSTEM) {
+
+                if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_BASIC_TARGET, NULL, true)) < 0)
+                        return r;
+
+        } else if (s->meta.manager->running_as == MANAGER_SESSION) {
+
+                if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SOCKETS_TARGET, NULL, true)) < 0)
+                        return r;
+        }
+
+        /* Second, activate normal shutdown */
+        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
+}
+
 static int service_load(Unit *u) {
         int r;
         Service *s = SERVICE(u);
@@ -867,11 +889,19 @@ static int service_load(Unit *u) {
                                 return r;
 
                         if ((r = unit_watch_bus_name(u, s->bus_name)) < 0)
-                            return r;
+                                return r;
                 }
 
                 if (s->type == SERVICE_NOTIFY && s->notify_access == NOTIFY_NONE)
                         s->notify_access = NOTIFY_MAIN;
+
+                if (s->type == SERVICE_DBUS || s->bus_name)
+                        if ((r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, SPECIAL_DBUS_TARGET, NULL, true)) < 0)
+                                return r;
+
+                if (s->meta.default_dependencies)
+                        if ((r = service_add_default_dependencies(s)) < 0)
+                                return r;
         }
 
         return service_verify(s);
diff --git a/src/socket.c b/src/socket.c
index 91eea7d..03e556c 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -37,6 +37,7 @@
 #include "unit-name.h"
 #include "dbus-socket.h"
 #include "missing.h"
+#include "special.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
@@ -241,6 +242,17 @@ static int socket_add_device_link(Socket *s) {
         return r;
 }
 
+static int socket_add_default_dependencies(Socket *s) {
+        int r;
+        assert(s);
+
+        if (s->meta.manager->running_as == MANAGER_SYSTEM)
+                if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
+                        return r;
+
+        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
+}
+
 static int socket_load(Unit *u) {
         Socket *s = SOCKET(u);
         int r;
@@ -273,6 +285,10 @@ static int socket_load(Unit *u) {
 
                 if ((r = unit_add_default_cgroup(u)) < 0)
                         return r;
+
+                if (s->meta.default_dependencies)
+                        if ((r = socket_add_default_dependencies(s)) < 0)
+                                return r;
         }
 
         return socket_verify(s);
diff --git a/src/special.h b/src/special.h
index 2d5bc7b..8cb500b 100644
--- a/src/special.h
+++ b/src/special.h
@@ -46,7 +46,9 @@
 #define SPECIAL_RTC_SET_TARGET "rtc-set.target"           /* LSB's $time */
 #define SPECIAL_DISPLAY_MANAGER_SERVICE "display-manager.service"       /* Debian's $x-display-manager */
 #define SPECIAL_MAIL_TRANSFER_AGENT_TARGET "mail-transfer-agent.target" /* Debian's $mail-{transport|transfer-agent */
+#define SPECIAL_DBUS_TARGET "dbus.target"
 #define SPECIAL_BASIC_TARGET "basic.target"
+#define SPECIAL_SOCKETS_TARGET "sockets.target"
 #define SPECIAL_SYSINIT_TARGET "sysinit.target"
 #define SPECIAL_RESCUE_TARGET "rescue.target"
 #define SPECIAL_EXIT_SERVICE "exit.service"
diff --git a/src/target.c b/src/target.c
index fba9956..f8df6fb 100644
--- a/src/target.c
+++ b/src/target.c
@@ -50,6 +50,46 @@ static void target_set_state(Target *t, TargetState state) {
         unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state]);
 }
 
+static int target_add_default_dependencies(Target *t) {
+        Iterator i;
+        Unit *other;
+        int r;
+
+        /* Imply ordering for requirement dependencies
+         * on target units. */
+
+        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES], i)
+                if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0)
+                        return r;
+        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
+                if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0)
+                        return r;
+        SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i)
+                if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0)
+                        return r;
+
+        return 0;
+}
+
+static int target_load(Unit *u) {
+        Target *t = TARGET(u);
+        int r;
+
+        assert(t);
+
+        if ((r = unit_load_fragment_and_dropin(u)) < 0)
+                return r;
+
+        /* This is a new unit? Then let's add in some extras */
+        if (u->meta.load_state == UNIT_LOADED) {
+                if (u->meta.default_dependencies)
+                        if ((r = target_add_default_dependencies(t)) < 0)
+                                return r;
+        }
+
+        return 0;
+}
+
 static int target_coldplug(Unit *u) {
         Target *t = TARGET(u);
 
@@ -177,7 +217,7 @@ DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState);
 const UnitVTable target_vtable = {
         .suffix = ".target",
 
-        .load = unit_load_fragment_and_dropin,
+        .load = target_load,
         .coldplug = target_coldplug,
 
         .dump = target_dump,
diff --git a/src/timer.c b/src/timer.c
index f0005f5..e3c916b 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -25,6 +25,7 @@
 #include "unit-name.h"
 #include "timer.h"
 #include "dbus-timer.h"
+#include "special.h"
 
 static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
         [TIMER_DEAD] = UNIT_INACTIVE,
@@ -89,6 +90,11 @@ static int timer_load(Unit *u) {
 
                 if ((r = unit_add_dependency(u, UNIT_BEFORE, t->unit, true)) < 0)
                         return r;
+
+                /* Timers shouldn't stay around on shutdown */
+                if (t->meta.default_dependencies)
+                        if ((r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0)
+                                return r;
         }
 
         return timer_verify(t);
diff --git a/src/unit.c b/src/unit.c
index 8c495b4..8f5ae8a 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -69,6 +69,7 @@ Unit *unit_new(Manager *m) {
         u->meta.manager = m;
         u->meta.type = _UNIT_TYPE_INVALID;
         u->meta.deserialized_job = _JOB_TYPE_INVALID;
+        u->meta.default_dependencies = true;
 
         return u;
 }
@@ -593,8 +594,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                 "%s\tActive Enter Timestamp: %s\n"
                 "%s\tActive Exit Timestamp: %s\n"
                 "%s\tInactive Enter Timestamp: %s\n"
-                "%s\tGC Check Good: %s\n"
-                "%s\tOnly By Dependency: %s\n",
+                "%s\tGC Check Good: %s\n",
                 prefix, u->meta.id,
                 prefix, unit_description(u),
                 prefix, strna(u->meta.instance),
@@ -604,8 +604,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                 prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_enter_timestamp.realtime)),
                 prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->meta.active_exit_timestamp.realtime)),
                 prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->meta.inactive_enter_timestamp.realtime)),
-                prefix, yes_no(unit_check_gc(u)),
-                prefix, yes_no(u->meta.only_by_dependency));
+                prefix, yes_no(unit_check_gc(u)));
 
         SET_FOREACH(t, u->meta.names, i)
                 fprintf(f, "%s\tName: %s\n", prefix, t);
@@ -623,9 +622,13 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
         if (u->meta.load_state == UNIT_LOADED) {
                 fprintf(f,
                         "%s\tRecursive Stop: %s\n"
-                        "%s\tStop When Unneeded: %s\n",
+                        "%s\tStopWhenUnneeded: %s\n"
+                        "%s\tOnlyByDependency: %s\n"
+                        "%s\tDefaultDependencies: %s\n",
                         prefix, yes_no(u->meta.recursive_stop),
-                        prefix, yes_no(u->meta.stop_when_unneeded));
+                        prefix, yes_no(u->meta.stop_when_unneeded),
+                        prefix, yes_no(u->meta.only_by_dependency),
+                        prefix, yes_no(u->meta.default_dependencies));
 
                 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 d3dd5de..b6351d5 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -142,9 +142,6 @@ struct Meta {
         UnitLoadState load_state;
         Unit *merged_into;
 
-        /* Refuse manual starting, allow starting only indirectly via dependency. */
-        bool only_by_dependency;
-
         char *id; /* One name is special because we use it for identification. Points to an entry in the names set */
         char *instance;
 
@@ -190,6 +187,12 @@ struct Meta {
         /* Garbage collect us we nobody wants or requires us anymore */
         bool stop_when_unneeded;
 
+        /* Refuse manual starting, allow starting only indirectly via dependency. */
+        bool only_by_dependency;
+
+        /* Create default depedencies */
+        bool default_dependencies;
+
         /* When deserializing, temporarily store the job type for this
          * unit here, if there was a job scheduled */
         int deserialized_job; /* This is actually of type JobType */
commit 2c966c038dc32ef39baa176371395cde4e541d01
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jul 3 19:46:38 2010 +0200

    unit: simplify things a little by introducing API to add two dependencies in one step

diff --git a/src/automount.c b/src/automount.c
index b8d7ad2..0689ec7 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -125,10 +125,7 @@ int automount_add_one_mount_link(Automount *a, Mount *m) {
         if (path_equal(a->where, m->where))
                 return 0;
 
-        if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(a), true)) < 0)
-                return r;
-
-        if ((r = unit_add_dependency(UNIT(a), UNIT_REQUIRES, UNIT(m), true)) < 0)
+        if ((r = unit_add_two_dependencies(UNIT(a), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
                 return r;
 
         return 0;
diff --git a/src/mount.c b/src/mount.c
index db8551e..6b38741 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -262,11 +262,7 @@ static int mount_add_target_links(Mount *m) {
                 if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
                         return r;
 
-                if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(am), true)) < 0)
-                        return r;
-
-                return unit_add_dependency(UNIT(am), UNIT_BEFORE, tu, true);
-
+                return unit_add_two_dependencies(tu, UNIT_AFTER, UNIT_WANTS, UNIT(am), true);
         } else {
 
                 if (!noauto && handle)
diff --git a/src/path.c b/src/path.c
index 80dc3c4..56936fd 100644
--- a/src/path.c
+++ b/src/path.c
@@ -65,10 +65,7 @@ int path_add_one_mount_link(Path *p, Mount *m) {
                 if (!path_startswith(s->path, m->where))
                         continue;
 
-                if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(p), true)) < 0)
-                        return r;
-
-                if ((r = unit_add_dependency(UNIT(p), UNIT_REQUIRES, UNIT(m), true)) < 0)
+                if ((r = unit_add_two_dependencies(UNIT(p), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
                         return r;
         }
 
diff --git a/src/service.c b/src/service.c
index 10e9ccf..cbc9c95 100644
--- a/src/service.c
+++ b/src/service.c
@@ -543,10 +543,8 @@ static int service_load_sysv_path(Service *s, const char *path) {
 
                                         if (unit_name_to_type(m) == UNIT_SERVICE)
                                                 r = unit_add_name(u, m);
-                                        else {
-                                                if ((r = unit_add_dependency_by_name_inverse(u, UNIT_REQUIRES, m, NULL, true)) >= 0)
-                                                        r = unit_add_dependency_by_name(u, UNIT_BEFORE, m, NULL, true);
-                                        }
+                                        else
+                                                r = unit_add_two_dependencies_by_name_inverse(u, UNIT_AFTER, UNIT_REQUIRES, m, NULL, true);
 
                                         free(m);
 
@@ -2449,21 +2447,13 @@ static int service_enumerate(Manager *m) {
                                 service = unit_follow_merge(service);
 
                                 if (de->d_name[0] == 'S') {
-                                        Unit *runlevel_target;
-
-                                        if ((r = manager_load_unit(m, rcnd_table[i].target, NULL, &runlevel_target)) < 0)
-                                                goto finish;
-
-                                        if ((r = unit_add_dependency(runlevel_target, UNIT_WANTS, service, true)) < 0)
-                                                goto finish;
 
-                                        if ((r = unit_add_dependency(service, UNIT_BEFORE, runlevel_target, true)) < 0)
+                                        if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_WANTS, rcnd_table[i].target, NULL, true)) < 0)
                                                 goto finish;
 
                                 } else if (de->d_name[0] == 'K' &&
                                            (rcnd_table[i].type == RUNLEVEL_DOWN ||
                                             rcnd_table[i].type == RUNLEVEL_SYSINIT)) {
-                                        Unit *shutdown_target;
 
                                         /* We honour K links only for
                                          * halt/reboot. For the normal
@@ -2481,13 +2471,7 @@ static int service_enumerate(Manager *m) {
                                          * too to the shutdown
                                          * target.*/
 
-                                        if ((r = manager_load_unit(m, SPECIAL_SHUTDOWN_TARGET, NULL, &shutdown_target)) < 0)
-                                                goto finish;
-
-                                        if ((r = unit_add_dependency(service, UNIT_CONFLICTS, shutdown_target, true)) < 0)
-                                                goto finish;
-
-                                        if ((r = unit_add_dependency(service, UNIT_BEFORE, shutdown_target, true)) < 0)
+                                        if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0)
                                                 goto finish;
                                 }
                         }
diff --git a/src/socket.c b/src/socket.c
index 8edf0ce..91eea7d 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -204,10 +204,7 @@ int socket_add_one_mount_link(Socket *s, Mount *m) {
         if (!socket_needs_mount(s, m->where))
                 return 0;
 
-        if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(s), true)) < 0)
-                return r;
-
-        if ((r = unit_add_dependency(UNIT(s), UNIT_REQUIRES, UNIT(m), true)) < 0)
+        if ((r = unit_add_two_dependencies(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
                 return r;
 
         return 0;
diff --git a/src/swap.c b/src/swap.c
index 2e3e995..d093c2e 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -77,10 +77,7 @@ int swap_add_one_mount_link(Swap *s, Mount *m) {
         if (!path_startswith(s->what, m->where))
                 return 0;
 
-        if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(s), true)) < 0)
-                return r;
-
-        if ((r = unit_add_dependency(UNIT(s), UNIT_REQUIRES, UNIT(m), true)) < 0)
+        if ((r = unit_add_two_dependencies(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
                 return r;
 
         return 0;
diff --git a/src/unit.c b/src/unit.c
index 9fed5a0..8c495b4 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1324,6 +1324,20 @@ fail:
         return r;
 }
 
+int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference) {
+        int r;
+
+        assert(u);
+
+        if ((r = unit_add_dependency(u, d, other, add_reference)) < 0)
+                return r;
+
+        if ((r = unit_add_dependency(u, e, other, add_reference)) < 0)
+                return r;
+
+        return 0;
+}
+
 static const char *resolve_template(Unit *u, const char *name, const char*path, char **p) {
         char *s;
 
@@ -1378,6 +1392,27 @@ finish:
         return r;
 }
 
+int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
+        Unit *other;
+        int r;
+        char *s;
+
+        assert(u);
+        assert(name || path);
+
+        if (!(name = resolve_template(u, name, path, &s)))
+                return -ENOMEM;
+
+        if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+                goto finish;
+
+        r = unit_add_two_dependencies(u, d, e, other, add_reference);
+
+finish:
+        free(s);
+        return r;
+}
+
 int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
         Unit *other;
         int r;
@@ -1399,6 +1434,28 @@ finish:
         return r;
 }
 
+int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
+        Unit *other;
+        int r;
+        char *s;
+
+        assert(u);
+        assert(name || path);
+
+        if (!(name = resolve_template(u, name, path, &s)))
+                return -ENOMEM;
+
+        if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+                goto finish;
+
+        if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
+                goto finish;
+
+finish:
+        free(s);
+        return r;
+}
+
 int set_unit_path(const char *p) {
         char *cwd, *c;
         int r;
@@ -1907,10 +1964,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) {
         if (r < 0)
                 return r;
 
-        if ((r = unit_add_dependency(u, UNIT_AFTER, device, true)) < 0)
-                return r;
-
-        if ((r = unit_add_dependency(u, UNIT_REQUIRES, device, true)) < 0)
+        if ((r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, device, true)) < 0)
                 return r;
 
         if (wants)
diff --git a/src/unit.h b/src/unit.h
index aa80aad..d3dd5de 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -367,8 +367,13 @@ void unit_free(Unit *u);
 int unit_add_name(Unit *u, const char *name);
 
 int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference);
+int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference);
+
 int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
+int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
+
 int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
+int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
 
 int unit_add_exec_dependencies(Unit *u, ExecContext *c);
 


More information about the systemd-commits mailing list