Merge pull request #1408 from poettering/systemctl-and-more

Systemctl and more
This commit is contained in:
Daniel Mack 2015-09-29 22:10:40 +02:00
commit 2ea69f8d5e
113 changed files with 2293 additions and 2417 deletions

1
.gitignore vendored
View file

@ -96,7 +96,6 @@
/systemd-kmsg-syslogd
/systemd-localed
/systemd-logind
/systemd-machine-id-commit
/systemd-machine-id-setup
/systemd-machined
/systemd-modules-load

View file

@ -102,7 +102,6 @@ MANPAGES += \
man/systemd-inhibit.1 \
man/systemd-initctl.service.8 \
man/systemd-journald.service.8 \
man/systemd-machine-id-commit.1 \
man/systemd-machine-id-commit.service.8 \
man/systemd-machine-id-setup.1 \
man/systemd-notify.1 \
@ -2351,7 +2350,6 @@ EXTRA_DIST += \
man/systemd-localed.service.xml \
man/systemd-logind.service.xml \
man/systemd-machine-id-commit.service.xml \
man/systemd-machine-id-commit.xml \
man/systemd-machine-id-setup.xml \
man/systemd-machined.service.xml \
man/systemd-modules-load.service.xml \

View file

@ -397,7 +397,6 @@ rootlibexec_PROGRAMS = \
systemd-remount-fs \
systemd-reply-password \
systemd-fsck \
systemd-machine-id-commit \
systemd-ac-power \
systemd-sysctl \
systemd-sleep \
@ -2331,6 +2330,9 @@ systemd_machine_id_setup_SOURCES = \
systemd_machine_id_setup_LDADD = \
libshared.la
SYSINIT_TARGET_WANTS += \
systemd-machine-id-commit.service
# ------------------------------------------------------------------------------
systemd_sysctl_SOURCES = \
src/sysctl/sysctl.c
@ -2352,18 +2354,6 @@ systemd_fsck_SOURCES = \
systemd_fsck_LDADD = \
libshared.la
# ------------------------------------------------------------------------------
systemd_machine_id_commit_SOURCES = \
src/machine-id-commit/machine-id-commit.c \
src/core/machine-id-setup.c \
src/core/machine-id-setup.h
systemd_machine_id_commit_LDADD = \
libshared.la
SYSINIT_TARGET_WANTS += \
systemd-machine-id-commit.service
# ------------------------------------------------------------------------------
systemd_ac_power_SOURCES = \
src/ac-power/ac-power.c

View file

@ -79,8 +79,9 @@
<term><varname>systemd.unit=</varname></term>
<term><varname>rd.systemd.unit=</varname></term>
<term><varname>systemd.dump_core=</varname></term>
<term><varname>systemd.crash_shell=</varname></term>
<term><varname>systemd.crash_chvt=</varname></term>
<term><varname>systemd.crash_shell=</varname></term>
<term><varname>systemd.crash_reboot=</varname></term>
<term><varname>systemd.confirm_spawn=</varname></term>
<term><varname>systemd.show_status=</varname></term>
<term><varname>systemd.log_target=</varname></term>

View file

@ -63,7 +63,7 @@
<para>The machine ID is usually generated from a random source
during system installation and stays constant for all subsequent
boots. Optionally, for stateless systems, it is generated during
runtime at boot if it is found to be empty.</para>
runtime at early boot if it is found to be empty.</para>
<para>The machine ID does not change based on user configuration
or when hardware is replaced.</para>

View file

@ -1120,9 +1120,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<tgroup cols='3'>
<thead>
<row>
<entry>Printed string</entry>
<entry>Meaning</entry>
<entry>Return value</entry>
<entry>Name</entry>
<entry>Description</entry>
<entry>Exit Code</entry>
</row>
</thead>
<tbody>
@ -1137,7 +1137,7 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<row>
<entry><literal>linked</literal></entry>
<entry morerows='1'>Made available through a symlink to the unit file (permanently or just in <filename>/run</filename>).</entry>
<entry morerows='1'>1</entry>
<entry morerows='1'>&gt; 0</entry>
</row>
<row>
<entry><literal>linked-runtime</literal></entry>
@ -1145,7 +1145,7 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<row>
<entry><literal>masked</literal></entry>
<entry morerows='1'>Disabled entirely (permanently or just in <filename>/run</filename>).</entry>
<entry morerows='1'>1</entry>
<entry morerows='1'>&gt; 0</entry>
</row>
<row>
<entry><literal>masked-runtime</literal></entry>
@ -1163,7 +1163,7 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<row>
<entry><literal>disabled</literal></entry>
<entry>Unit file is not enabled.</entry>
<entry>1</entry>
<entry>&gt; 0</entry>
</row>
</tbody>
</tgroup>
@ -1474,22 +1474,25 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<listitem>
<para>Checks whether the system is operational. This
returns success when the system is fully up and running,
meaning not in startup, shutdown or maintenance
mode. Failure is returned otherwise. In addition, the
returns success (exit code 0) when the system is fully up
and running, specifically not in startup, shutdown or
maintenance mode, and with no failed services. Failure is
returned otherwise (exit code non-zero). In addition, the
current state is printed in a short string to standard
output, see table below. Use <option>--quiet</option> to
suppress this output.</para>
<table>
<title>Manager Operational States</title>
<tgroup cols='2'>
<colspec colname='name' />
<colspec colname='description' />
<title><command>is-system-running</command> output</title>
<tgroup cols='3'>
<colspec colname='name'/>
<colspec colname='description'/>
<colspec colname='exit-code'/>
<thead>
<row>
<entry>Name</entry>
<entry>Description</entry>
<entry>Exit Code</entry>
</row>
</thead>
<tbody>
@ -1499,32 +1502,53 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<filename>basic.target</filename> is reached
or the <varname>maintenance</varname> state entered.
</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>starting</varname></entry>
<entry><para>Late bootup, before the job queue
becomes idle for the first time, or one of the
rescue targets are reached.</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>running</varname></entry>
<entry><para>The system is fully
operational.</para></entry>
<entry>0</entry>
</row>
<row>
<entry><varname>degraded</varname></entry>
<entry><para>The system is operational but one or more
units failed.</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>maintenance</varname></entry>
<entry><para>The rescue or emergency target is
active.</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>stopping</varname></entry>
<entry><para>The manager is shutting
down.</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>offline</varname></entry>
<entry><para>The manager is not
running. Specifically, this is the operational
state if an incompatible program is running as
system manager (PID 1).</para></entry>
<entry>&gt; 0</entry>
</row>
<row>
<entry><varname>unknown</varname></entry>
<entry><para>The operational state could not be
determined, due to lack of resources or another
error cause.</para></entry>
<entry>&gt; 0</entry>
</row>
</tbody>
</tgroup>

View file

@ -42,55 +42,50 @@
<refnamediv>
<refname>systemd-machine-id-commit.service</refname>
<refpurpose>Commit transient machine-id to disk</refpurpose>
<refpurpose>Commit a transient machine-id to disk</refpurpose>
</refnamediv>
<refsynopsisdiv>
<para><filename>systemd-machine-id-commit.service</filename></para>
<para><filename>/usr/lib/systemd/systemd-machine-id-commit</filename></para>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><filename>systemd-machine-id-commit.service</filename> is a
service responsible for committing any transient
<filename>/etc/machine-id</filename> file to a writable file
<para><filename>systemd-machine-id-commit.service</filename> is an
early-boot service responsible for committing transient
<filename>/etc/machine-id</filename> files to a writable disk file
system. See
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information about this file.</para>
for more information about machine IDs.</para>
<para>This service is started shortly after
<filename>local-fs.target</filename> if
<filename>/etc/machine-id</filename> is an independent mount point
(probably a tmpfs one) and /etc is writable.
<command>systemd-machine-id-commit</command> will then write
current machine ID to disk and unmount the transient
<para>This service is started after
<filename>local-fs.target</filename> in case
<filename>/etc/machine-id</filename> is a mount point of its own
(usually from a memory file system such as
<literal>tmpfs</literal>) and /etc is writable. The service will
invoke <command>systemd-machine-id-setup --commit</command>, which
writes the current transient machine ID to disk and unmount the
<filename>/etc/machine-id</filename> file in a race-free manner to
ensure that file is always valid for other processes.</para>
ensure that file is always valid and accessible for other
processes. See
<citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>
for details.</para>
<para>Note that the traditional way to initialize the machine ID
in <filename>/etc/machine-id</filename> is to use
<command>systemd-machine-id-setup</command> by system installer
tools. You can also use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
to initialize the machine ID on mounted (but not booted) system
images. The main use case for that service is
<filename>/etc/machine-id</filename> being an empty file at boot
and initrd chaining to systemd giving it a read only file system
that will be turned read-write later during the boot
process.</para>
<para>There is no consequence if that service fails other than a
newer machine-id will be generated during next system boot.
</para>
<para>The main use case of this service are systems where
<filename>/etc/machine-id</filename> is read-only and initially
not initialized. In this case the system manager will generate a
transient machine ID file on a memory file system, and mount it
over <filename>/etc/machine-id</filename>, during the early boot
phase. This service is then invoked in a later boot phase, as soon
as <filename>/etc</filename> has been remounted writable and the
ID may thus be committed to disk to make it permanent.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-machine-id-commit</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>

View file

@ -1,123 +0,0 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!--
This file is part of systemd.
Copyright 2014 Didier Roche
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
-->
<refentry id="systemd-machine-id-commit"
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>systemd-machine-id-commit</title>
<productname>systemd</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Didier</firstname>
<surname>Roche</surname>
<email>didrocks@ubuntu.com</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>systemd-machine-id-commit</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>systemd-machine-id-commit</refname>
<refpurpose>Commit transient machine ID to /etc/machine-id</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>systemd-machine-id-commit</command>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><command>systemd-machine-id-commit</command> may be used to
write on disk any transient machine ID mounted as a temporary file
system in <filename>/etc/machine-id</filename> at boot time. See
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information about this file.</para>
<para>This tool will execute no operation if
<filename>/etc/machine-id</filename> doesn't contain any valid
machine ID, isn't mounted as an independent temporary file system,
or <filename>/etc</filename> is read-only. If those conditions are
met, it will then write current machine ID to disk and unmount the
transient <filename>/etc/machine-id</filename> file in a race-free
manner to ensure that this file is always valid for other
processes.</para>
<para>Note that the traditional way to initialize the machine ID
in <filename>/etc/machine-id</filename> is to use
<command>systemd-machine-id-setup</command> by system installer
tools. You can also use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
to initialize the machine ID on mounted (but not booted) system
images.</para>
</refsect1>
<refsect1>
<title>Options</title>
<para>The following options are understood:</para>
<variablelist>
<varlistentry>
<term><option>--root=<replaceable>root</replaceable></option></term>
<listitem><para>Takes a directory path
as an argument. All paths will be
prefixed with the given alternate
<replaceable>root</replaceable> path,
including config search paths.
</para></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
</refsect1>
<refsect1>
<title>Exit status</title>
<para>On success, 0 is returned, a non-zero failure code
otherwise.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>

View file

@ -1,4 +1,4 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
@ -35,6 +35,12 @@
<surname>Poettering</surname>
<email>lennart@poettering.net</email>
</author>
<author>
<contrib>Developer</contrib>
<firstname>Didier</firstname>
<surname>Roche</surname>
<email>didrocks@ubuntu.com</email>
</author>
</authorgroup>
</refentryinfo>
@ -59,30 +65,43 @@
<para><command>systemd-machine-id-setup</command> may be used by
system installer tools to initialize the machine ID stored in
<filename>/etc/machine-id</filename> at install time with a
randomly generated ID. See
<filename>/etc/machine-id</filename> at install time, with a
provisioned or randomly generated ID. See
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information about this file.</para>
<para>This tool will execute no operation if
<filename>/etc/machine-id</filename> is already
initialized.</para>
<para>If the tool is invoked without the <option>--commit</option>
switch <filename>/etc/machine-id</filename> is initialized with a
valid, new machined ID if it is missing or empty. The new machine
ID will be acquired in the following fashion:</para>
<para>If a valid D-Bus machine ID is already configured for the
system, the D-Bus machine ID is copied and used to initialize the
machine ID in <filename>/etc/machine-id</filename>.</para>
<orderedlist>
<listitem><para>If a valid D-Bus machine ID is already
configured for the system, the D-Bus machine ID is copied and
used to initialize the machine ID in
<filename>/etc/machine-id</filename>.</para></listitem>
<para>If run inside a KVM virtual machine and a UUID is passed via
the <option>-uuid</option> option, this UUID is used to initialize
the machine ID instead of a randomly generated one. The caller
must ensure that the UUID passed is sufficiently unique and is
different for every booted instanced of the VM.</para>
<listitem><para>If run inside a KVM virtual machine and a UUID
is was configured (via the <option>-uuid</option>
option), this UUID is used to initialize the machine ID. The
caller must ensure that the UUID passed is sufficiently unique
and is different for every booted instance of the
VM.</para></listitem>
<para>Similar, if run inside a Linux container environment and a
UUID is set for the container this is used to initialize the
machine ID. For details see the documentation of the <ulink
url="http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface">Container
Interface</ulink>.</para>
<listitem><para>Similar, if run inside a Linux container
environment and a UUID is configured for the container this is
used to initialize the machine ID. For details see the
documentation of the <ulink
url="http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface">Container
Interface</ulink>.</para></listitem>
<listitem><para>Otherwise a new ID is randomly
generated.</para></listitem>
</orderedlist>
<para>The <option>--commit</option> switch may be used to commit a
transient machined ID to disk, making it persistent. For details,
see below.</para>
<para>Use
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
@ -97,13 +116,41 @@
<para>The following options are understood:</para>
<variablelist>
<varlistentry>
<term><option>--root=<replaceable>root</replaceable></option></term>
<listitem><para>Takes a directory path as an argument. All
paths will be prefixed with the given alternate
<replaceable>root</replaceable> path, including config search
paths. </para></listitem>
<listitem><para>Takes a directory path as argument. All paths
operated will be prefixed with the given alternate
<replaceable>root</replaceable> path, including the path for
<filename>/etc/machine-id</filename> itself.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--commit</option></term>
<listitem><para>Commit a transient machine ID to disk. This
command may be used to convert a transient machine ID into a
persistent one. A transient machine ID file is one that was
bind mounted from a memory file system (usually
<literal>tmpfs</literal>) to
<filename>/etc/machine-id</filename> during the early phase of
the boot process. This may happen because
<filename>/etc</filename> is initially read-only and was
missing a valid machine ID file at that point.</para>
<para>This command will execute no operation if
<filename>/etc/machine-id</filename> is not mounted from a
memory file system, or if <filename>/etc</filename> is
read-only. The command will write the current transient
machine ID to disk and unmount the
<filename>/etc/machine-id</filename> mount point in a
race-free manner to ensure that this file is always valid and
accessible for other processes.</para>
<para>This command is primarily used by the
<citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
early-boot service.</para></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
@ -122,6 +169,7 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
<citerefentry project='dbus'><refentrytitle>dbus-uuidgen</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>

View file

@ -124,7 +124,12 @@
systemd, non-zero otherwise. If this option is passed, no
message is sent. This option is hence unrelated to the other
options. For details about the semantics of this option, see
<citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
<citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>. An
alternative way to check for this state is to call
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
with the <command>is-system-running</command> command. It will
return <literal>offline</literal> if the system was not booted
with systemd. </para></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
@ -156,12 +161,12 @@ mkfifo /tmp/waldo
systemd-notify --ready --status="Waiting for data..."
while : ; do
read a &lt; /tmp/waldo
systemd-notify --status="Processing $a"
read a &lt; /tmp/waldo
systemd-notify --status="Processing $a"
# Do something with $a ...
# Do something with $a ...
systemd-notify --status="Waiting for data..."
systemd-notify --status="Waiting for data..."
done</programlisting>
</example>
</refsect1>

View file

@ -90,9 +90,10 @@
<term><varname>LogColor=</varname></term>
<term><varname>LogLocation=</varname></term>
<term><varname>DumpCore=yes</varname></term>
<term><varname>CrashChangeVT=no</varname></term>
<term><varname>CrashShell=no</varname></term>
<term><varname>CrashReboot=no</varname></term>
<term><varname>ShowStatus=yes</varname></term>
<term><varname>CrashChVT=1</varname></term>
<term><varname>DefaultStandardOutput=journal</varname></term>
<term><varname>DefaultStandardError=inherit</varname></term>

View file

@ -84,22 +84,27 @@
<varlistentry>
<term><varname>WorkingDirectory=</varname></term>
<listitem><para>Takes an absolute directory path. Sets the
working directory for executed processes. If not set, defaults
to the root directory when systemd is running as a system
instance and the respective user's home directory if run as
user.</para></listitem>
<listitem><para>Takes an absolute directory path, or the
special value <literal>~</literal>. Sets the working directory
for executed processes. If set to <literal>~</literal> the
home directory of the user specified in
<varname>User=</varname> is used. If not set, defaults to the
root directory when systemd is running as a system instance
and the respective user's home directory if run as user. If
the setting is prefixed with the <literal>-</literal>
character, a missing working directory is not considered
fatal.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>RootDirectory=</varname></term>
<listitem><para>Takes an absolute directory path. Sets the
root directory for executed processes, with the
<citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
root directory for executed processes, with the <citerefentry
project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
system call. If this is used, it must be ensured that the
process and all its auxiliary files are available in the
<function>chroot()</function> jail.</para></listitem>
process binary and all its auxiliary files are available in
the <function>chroot()</function> jail.</para></listitem>
</varlistentry>
<varlistentry>

View file

@ -1,4 +1,4 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
@ -131,17 +131,48 @@
<varlistentry>
<term><option>--dump-core</option></term>
<listitem><para>Dump core on crash. This switch has no effect
when run as user instance.</para></listitem>
<listitem><para>Enable core dumping on crash. This switch has
no effect when running as user instance. This setting may also
be enabled during boot on the kernel command line via the
<varname>systemd.dump_core=</varname> option, see
below.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--crash-vt=</option><replaceable>VT</replaceable></term>
<listitem><para>Switch to a specific virtual console (VT) on
crash. Takes a positive integer in the range 1..63, or a
boolean argument. If an integer is passed, selects which VT to
switch to. If <constant>yes</constant>, the VT kernel messages
are written to is selected. If <constant>no</constant>, no VT
switch is attempted. This switch has no effect when running as
user instance. This setting may also be enabled during boot,
on the kernel command line via the
<varname>systemd.crash_vt=</varname> option, see
below.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--crash-shell</option></term>
<listitem><para>Run shell on
crash. This switch has no effect when
run as user
instance.</para></listitem>
<listitem><para>Run a shell on crash. This switch has no
effect when running as user instance. This setting may also be
enabled during boot, on the kernel command line via the
<varname>systemd.crash_shell=</varname> option, see
below.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--crash-reboot</option></term>
<listitem><para>Automatically reboot the system on crash. This
switch has no effect when running as user instance. This
setting may also be enabled during boot, on the kernel command
line via the <varname>systemd.crash_reboot=</varname> option,
see below.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--confirm-spawn</option></term>
@ -854,50 +885,67 @@
<term><varname>systemd.dump_core=</varname></term>
<listitem><para>Takes a boolean argument. If
<option>true</option>, systemd dumps core when it crashes.
Otherwise, no core dump is created. Defaults to
<option>true</option>.</para></listitem>
<option>yes</option>, the systemd manager (PID 1) dumps core
when it crashes. Otherwise, no core dump is created. Defaults
to <option>yes</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.crash_chvt=</varname></term>
<listitem><para>Takes a positive integer, or a boolean
argument. If a positive integer (in the range 1..63) is
specified the system manager (PID 1) will activate the specified
virtual terminal (VT) when it crashes. Defaults to
<constant>no</constant>, meaning that no such switch is
attempted. If set to <constant>yes</constant> the VT the
kernel messages are written to is selected.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.crash_shell=</varname></term>
<listitem><para>Takes a boolean argument. If
<option>true</option>, systemd spawns a shell when it crashes.
Otherwise, no shell is spawned. Defaults to
<option>false</option>, for security reasons, as the shell is
not protected by any password
<option>yes</option>, the system manager (PID 1) spawns a
shell when it crashes, after a 10s delay. Otherwise, no shell
is spawned. Defaults to <option>no</option>, for security
reasons, as the shell is not protected by password
authentication.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.crash_chvt=</varname></term>
<term><varname>systemd.crash_reboot=</varname></term>
<listitem><para>Takes an integer argument. If positive systemd
activates the specified virtual terminal when it crashes.
Defaults to <constant>-1</constant>.</para></listitem>
<listitem><para>Takes a boolean argument. If
<option>yes</option>, the system manager (PID 1) will reboot
the machine automatically when it crashes, after a 10s delay.
Otherwise, the system will hang indefinitely. Defaults to
<option>no</option>, in order to avoid a reboot loop. If
combined with <varname>systemd.crash_shell=</varname>, it is
first attempted to invoke a shell, and if this is not
successful the system is rebooted.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.confirm_spawn=</varname></term>
<listitem><para>Takes a boolean argument. If
<option>true</option>, asks for confirmation when spawning
processes. Defaults to
<option>false</option>.</para></listitem>
<option>yes</option>, the system manager (PID 1) asks for
confirmation when spawning processes. Defaults to
<option>no</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.show_status=</varname></term>
<listitem><para>Takes a boolean argument or the constant
<constant>auto</constant>. If <option>true</option>, shows
terse service status updates on the console during bootup.
<constant>auto</constant> behaves like <option>false</option>
until a service fails or there is a significant delay in boot.
Defaults to <option>true</option>, unless
<option>quiet</option> is passed as kernel command line option
in which case it defaults to
<constant>auto</constant>. If <option>yes</option>, the
systemd manager (PID 1) shows terse service status updates on
the console during bootup. <constant>auto</constant> behaves
like <option>false</option> until a service fails or there is
a significant delay in boot. Defaults to
<option>yes</option>, unless <option>quiet</option> is passed
as kernel command line option in which case it defaults to
<constant>auto</constant>.</para></listitem>
</varlistentry>

View file

@ -19,21 +19,20 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <getopt.h>
#include <sys/epoll.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <getopt.h>
#include <unistd.h>
#include "systemd/sd-daemon.h"
#include "socket-util.h"
#include "build.h"
#include "log.h"
#include "strv.h"
#include "macro.h"
#include "signal-util.h"
#include "socket-util.h"
#include "strv.h"
static char** arg_listen = NULL;
static bool arg_accept = false;
@ -314,9 +313,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0 /* done */;
return version();
case 'l': {
int r = strv_extend(&arg_listen, optarg);

View file

@ -20,25 +20,25 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "log.h"
#include "build.h"
#include "util.h"
#include "strxcpyx.h"
#include "strv.h"
#include "unit-name.h"
#include "special.h"
#include "hashmap.h"
#include "pager.h"
#include "analyze-verify.h"
#include "bus-error.h"
#include "bus-util.h"
#include "hashmap.h"
#include "log.h"
#include "pager.h"
#include "special.h"
#include "strv.h"
#include "strxcpyx.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
#define SCALE_X (0.1 / 1000.0) /* pixels per us */
#define SCALE_Y (20.0)
@ -1339,9 +1339,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_USER:
arg_user = true;
@ -1434,7 +1432,7 @@ int main(int argc, char *argv[]) {
else {
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus);
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -295,14 +295,20 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
return r;
}
void mac_selinux_free(char *label) {
char* mac_selinux_free(char *label) {
#ifdef HAVE_SELINUX
if (!label)
return NULL;
if (!mac_selinux_use())
return;
return NULL;
freecon((security_context_t) label);
#endif
return NULL;
}
int mac_selinux_create_file_prepare(const char *path, mode_t mode) {

View file

@ -24,6 +24,8 @@
#include <sys/socket.h>
#include <stdbool.h>
#include "macro.h"
bool mac_selinux_use(void);
void mac_selinux_retest(void);
@ -36,7 +38,7 @@ int mac_selinux_apply(const char *path, const char *label);
int mac_selinux_get_create_label_from_exe(const char *exe, char **label);
int mac_selinux_get_our_label(char **label);
int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *exec_label, char **label);
void mac_selinux_free(char *label);
char* mac_selinux_free(char *label);
int mac_selinux_create_file_prepare(const char *path, mode_t mode);
void mac_selinux_create_file_clear(void);
@ -45,3 +47,5 @@ int mac_selinux_create_socket_prepare(const char *label);
void mac_selinux_create_socket_clear(void);
int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, mac_selinux_free);

View file

@ -720,3 +720,28 @@ bool strv_fnmatch(char* const* patterns, const char *s, int flags) {
return false;
}
char ***strv_free_free(char ***l) {
char ***i;
if (!l)
return NULL;
for (i = l; *i; i++)
strv_free(*i);
free(l);
return NULL;
}
char **strv_skip(char **l, size_t n) {
while (n > 0) {
if (strv_isempty(l))
return l;
l++, n--;
}
return l;
}

View file

@ -154,3 +154,7 @@ static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, i
return strv_isempty(patterns) ||
strv_fnmatch(patterns, s, flags);
}
char ***strv_free_free(char ***l);
char **strv_skip(char **l, size_t n);

View file

@ -48,7 +48,7 @@ int chvt(int vt) {
if (fd < 0)
return -errno;
if (vt < 0) {
if (vt <= 0) {
int tiocl[2] = {
TIOCL_GETKMSGREDIRECT,
0

View file

@ -72,6 +72,7 @@
* otherwise conflicts with sys/mount.h. Yay, Linux is great! */
#include <linux/fs.h>
#include "build.h"
#include "def.h"
#include "device-nodes.h"
#include "env-util.h"
@ -6201,15 +6202,6 @@ int ptsname_malloc(int fd, char **ret) {
int openpt_in_namespace(pid_t pid, int flags) {
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
} control = {};
struct msghdr mh = {
.msg_control = &control,
.msg_controllen = sizeof(control),
};
struct cmsghdr *cmsg;
siginfo_t si;
pid_t child;
int r;
@ -6243,15 +6235,7 @@ int openpt_in_namespace(pid_t pid, int flags) {
if (unlockpt(master) < 0)
_exit(EXIT_FAILURE);
cmsg = CMSG_FIRSTHDR(&mh);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cmsg), &master, sizeof(int));
mh.msg_controllen = cmsg->cmsg_len;
if (sendmsg(pair[1], &mh, MSG_NOSIGNAL) < 0)
if (send_one_fd(pair[1], master, 0) < 0)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);
@ -6265,26 +6249,7 @@ int openpt_in_namespace(pid_t pid, int flags) {
if (si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS)
return -EIO;
if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
return -errno;
CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
int *fds;
unsigned n_fds;
fds = (int*) CMSG_DATA(cmsg);
n_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
if (n_fds != 1) {
close_many(fds, n_fds);
return -EIO;
}
return fds[0];
}
return -EIO;
return receive_one_fd(pair[0], 0);
}
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) {
@ -6884,7 +6849,7 @@ int fgetxattr_malloc(int fd, const char *name, char **value) {
}
}
int send_one_fd(int transport_fd, int fd) {
int send_one_fd(int transport_fd, int fd, int flags) {
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
@ -6894,7 +6859,6 @@ int send_one_fd(int transport_fd, int fd) {
.msg_controllen = sizeof(control),
};
struct cmsghdr *cmsg;
ssize_t k;
assert(transport_fd >= 0);
assert(fd >= 0);
@ -6906,14 +6870,13 @@ int send_one_fd(int transport_fd, int fd) {
memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
mh.msg_controllen = CMSG_SPACE(sizeof(int));
k = sendmsg(transport_fd, &mh, MSG_NOSIGNAL);
if (k < 0)
if (sendmsg(transport_fd, &mh, MSG_NOSIGNAL | flags) < 0)
return -errno;
return 0;
}
int receive_one_fd(int transport_fd) {
int receive_one_fd(int transport_fd, int flags) {
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
@ -6922,33 +6885,45 @@ int receive_one_fd(int transport_fd) {
.msg_control = &control,
.msg_controllen = sizeof(control),
};
struct cmsghdr *cmsg;
ssize_t k;
struct cmsghdr *cmsg, *found = NULL;
assert(transport_fd >= 0);
/*
* Receive a single FD via @transport_fd. We don't care for the
* transport-type, but the caller must assure that no other CMSG types
* than SCM_RIGHTS is enabled. We also retrieve a single FD at most, so
* for packet-based transports, the caller must ensure to send only a
* single FD per packet.
* This is best used in combination with send_one_fd().
* Receive a single FD via @transport_fd. We don't care for
* the transport-type. We retrieve a single FD at most, so for
* packet-based transports, the caller must ensure to send
* only a single FD per packet. This is best used in
* combination with send_one_fd().
*/
k = recvmsg(transport_fd, &mh, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC);
if (k < 0)
if (recvmsg(transport_fd, &mh, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC | flags) < 0)
return -errno;
cmsg = CMSG_FIRSTHDR(&mh);
if (!cmsg || CMSG_NXTHDR(&mh, cmsg) ||
cmsg->cmsg_level != SOL_SOCKET ||
cmsg->cmsg_type != SCM_RIGHTS ||
cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
*(const int *)CMSG_DATA(cmsg) < 0) {
CMSG_FOREACH(cmsg, &mh) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
assert(!found);
found = cmsg;
break;
}
}
if (!found) {
cmsg_close_all(&mh);
return -EIO;
}
return *(const int *)CMSG_DATA(cmsg);
return *(int*) CMSG_DATA(found);
}
void nop_signal_handler(int sig) {
/* nothing here */
}
int version(void) {
puts(PACKAGE_STRING "\n"
SYSTEMD_FEATURES);
return 0;
}

View file

@ -942,5 +942,9 @@ int reset_uid_gid(void);
int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink);
int fgetxattr_malloc(int fd, const char *name, char **value);
int send_one_fd(int transport_fd, int fd);
int receive_one_fd(int transport_fd);
int send_one_fd(int transport_fd, int fd, int flags);
int receive_one_fd(int transport_fd, int flags);
void nop_signal_handler(int sig);
int version(void);

View file

@ -19,20 +19,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "conf-files.h"
#include "fileio.h"
#include "log.h"
#include "strv.h"
#include "util.h"
#include "conf-files.h"
#include "fileio.h"
#include "build.h"
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("binfmt");
@ -143,9 +142,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case '?':
return -EINVAL;

View file

@ -20,28 +20,27 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <dirent.h>
#include <ctype.h>
#include <limits.h>
#include <ftw.h>
#include <stdbool.h>
#include <blkid/blkid.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <ftw.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <unistd.h>
#include "efivars.h"
#include "build.h"
#include "util.h"
#include "rm-rf.h"
#include "blkid-util.h"
#include "efivars.h"
#include "rm-rf.h"
#include "util.h"
static int verify_esp(const char *p, uint32_t *part, uint64_t *pstart, uint64_t *psize, sd_id128_t *uuid) {
struct statfs sfs;
@ -967,8 +966,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
printf(VERSION "\n");
return 0;
return version();
case ARG_PATH:
arg_path = optarg;

View file

@ -22,26 +22,26 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/prctl.h>
#include <stddef.h>
#include <getopt.h>
#include <pthread.h>
#include <stddef.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include "log.h"
#include "util.h"
#include "sd-daemon.h"
#include "bus-internal.h"
#include "build.h"
#include "strv.h"
#include "def.h"
#include "capability.h"
#include "bus-xml-policy.h"
#include "proxy.h"
#include "capability.h"
#include "def.h"
#include "formats-util.h"
#include "log.h"
#include "proxy.h"
#include "strv.h"
#include "util.h"
static char *arg_address = NULL;
static char **arg_configuration = NULL;
@ -215,9 +215,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_ADDRESS:
r = free_and_strdup(&arg_address, optarg);

View file

@ -21,23 +21,23 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include <getopt.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
#include "util.h"
#include "sd-daemon.h"
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "build.h"
#include "strv.h"
#include "def.h"
#include "proxy.h"
#include "formats-util.h"
#include "log.h"
#include "proxy.h"
#include "strv.h"
#include "util.h"
static char *arg_address = NULL;
static char *arg_command_line_buffer = NULL;
@ -86,9 +86,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_ADDRESS: {
char *a;

View file

@ -19,25 +19,25 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "sd-bus.h"
#include "bus-error.h"
#include "bus-util.h"
#include "cgroup-show.h"
#include "cgroup-util.h"
#include "log.h"
#include "path-util.h"
#include "util.h"
#include "pager.h"
#include "build.h"
#include "output-mode.h"
#include "fileio.h"
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "log.h"
#include "output-mode.h"
#include "pager.h"
#include "path-util.h"
#include "unit-name.h"
#include "util.h"
static bool arg_no_pager = false;
static bool arg_kernel_threads = false;
@ -89,9 +89,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;
@ -147,7 +145,7 @@ static int get_cgroup_root(char **ret) {
if (!path)
return log_oom();
r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
return log_error_errno(r, "Failed to create bus connection: %m");

View file

@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
* this to avoid an activation loop when we start dbus when we
* are called when the dbus service is shut down. */
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0) {
/* If we couldn't connect we assume this was triggered
* while systemd got restarted/transitioned from

View file

@ -19,27 +19,27 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <alloca.h>
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "path-util.h"
#include "terminal-util.h"
#include "process-util.h"
#include "util.h"
#include "hashmap.h"
#include "cgroup-util.h"
#include "build.h"
#include "fileio.h"
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "fileio.h"
#include "hashmap.h"
#include "path-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
typedef struct Group {
char *path;
@ -696,9 +696,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_CPU_TYPE:
if (optarg) {
@ -863,7 +861,7 @@ static int get_cgroup_root(char **ret) {
if (!path)
return log_oom();
r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
return log_error_errno(r, "Failed to create bus connection: %m");

View file

@ -595,6 +595,33 @@ static int property_get_address_families(
return sd_bus_message_close_container(reply);
}
static int property_get_working_directory(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
const char *wd;
assert(bus);
assert(reply);
assert(c);
if (c->working_directory_home)
wd = "~";
else
wd = c->working_directory;
if (c->working_directory_missing_ok)
wd = strjoina("!", wd);
return sd_bus_message_append(reply, "s", wd);
}
const sd_bus_vtable bus_exec_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
@ -616,7 +643,7 @@ const sd_bus_vtable bus_exec_vtable[] = {
SD_BUS_PROPERTY("LimitNICE", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LimitRTPRIO", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LimitRTTIME", "t", property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("WorkingDirectory", "s", NULL, offsetof(ExecContext, working_directory), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
@ -847,8 +874,7 @@ int bus_exec_context_set_transient_property(
return 1;
} else if (STR_IN_SET(name,
"TTYPath", "WorkingDirectory", "RootDirectory")) {
} else if (STR_IN_SET(name, "TTYPath", "RootDirectory")) {
const char *s;
r = sd_bus_message_read(message, "s", &s);
@ -859,28 +885,55 @@ int bus_exec_context_set_transient_property(
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s takes an absolute path", name);
if (mode != UNIT_CHECK) {
char *t;
t = strdup(s);
if (!t)
return -ENOMEM;
if (streq(name, "TTYPath")) {
free(c->tty_path);
c->tty_path = t;
} else if (streq(name, "WorkingDirectory")) {
free(c->working_directory);
c->working_directory = t;
} else if (streq(name, "RootDirectory")) {
free(c->root_directory);
c->root_directory = t;
if (streq(name, "TTYPath"))
r = free_and_strdup(&c->tty_path, s);
else {
assert(streq(name, "RootDirectory"));
r = free_and_strdup(&c->root_directory, s);
}
if (r < 0)
return r;
unit_write_drop_in_private_format(u, mode, name, "%s=%s\n", name, s);
}
return 1;
} else if (streq(name, "WorkingDirectory")) {
const char *s;
bool missing_ok;
r = sd_bus_message_read(message, "s", &s);
if (r < 0)
return r;
if (s[0] == '-') {
missing_ok = true;
s++;
} else
missing_ok = false;
if (!streq(s, "~") && !path_is_absolute(s))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
if (mode != UNIT_CHECK) {
if (streq(s, "~")) {
c->working_directory = mfree(c->working_directory);
c->working_directory_home = true;
} else {
r = free_and_strdup(&c->working_directory, s);
if (r < 0)
return r;
c->working_directory_home = false;
}
c->working_directory_missing_ok = missing_ok;
unit_write_drop_in_private_format(u, mode, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
}
return 1;
} else if (streq(name, "StandardInput")) {
const char *s;
ExecInput p;

View file

@ -1325,7 +1325,7 @@ static int exec_child(
_cleanup_strv_free_ char **our_env = NULL, **pam_env = NULL, **final_env = NULL, **final_argv = NULL;
_cleanup_free_ char *mac_selinux_context_net = NULL;
const char *username = NULL, *home = NULL, *shell = NULL;
const char *username = NULL, *home = NULL, *shell = NULL, *wd;
unsigned n_dont_close = 0;
int dont_close[n_fds + 4];
uid_t uid = UID_INVALID;
@ -1698,6 +1698,13 @@ static int exec_child(
}
}
if (context->working_directory_home)
wd = home;
else if (context->working_directory)
wd = context->working_directory;
else
wd = "/";
if (params->apply_chroot) {
if (!needs_mount_namespace && context->root_directory)
if (chroot(context->root_directory) < 0) {
@ -1705,21 +1712,15 @@ static int exec_child(
return -errno;
}
if (chdir(context->working_directory ?: "/") < 0 &&
if (chdir(wd) < 0 &&
!context->working_directory_missing_ok) {
*exit_status = EXIT_CHDIR;
return -errno;
}
} else {
_cleanup_free_ char *d = NULL;
if (asprintf(&d, "%s/%s",
context->root_directory ?: "",
context->working_directory ?: "") < 0) {
*exit_status = EXIT_MEMORY;
return -ENOMEM;
}
const char *d;
d = strjoina(strempty(context->root_directory), "/", strempty(wd));
if (chdir(d) < 0 &&
!context->working_directory_missing_ok) {
*exit_status = EXIT_CHDIR;

View file

@ -103,6 +103,7 @@ struct ExecContext {
struct rlimit *rlimit[_RLIMIT_MAX];
char *working_directory, *root_directory;
bool working_directory_missing_ok;
bool working_directory_home;
mode_t umask;
int oom_score_adjust;

View file

@ -17,7 +17,7 @@ struct ConfigPerfItem;
%%
m4_dnl Define the context options only once
m4_define(`EXEC_CONTEXT_CONFIG_ITEMS',
`$1.WorkingDirectory, config_parse_unit_path_printf, 0, offsetof($1, exec_context.working_directory)
`$1.WorkingDirectory, config_parse_working_directory, 0, offsetof($1, exec_context)
$1.RootDirectory, config_parse_unit_path_printf, 0, offsetof($1, exec_context.root_directory)
$1.User, config_parse_unit_string_printf, 0, offsetof($1, exec_context.user)
$1.Group, config_parse_unit_string_printf, 0, offsetof($1, exec_context.group)

View file

@ -20,44 +20,42 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <linux/oom.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sched.h>
#include <linux/fs.h>
#include <sys/stat.h>
#include <linux/oom.h>
#include <sched.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/stat.h>
#ifdef HAVE_SECCOMP
#include <seccomp.h>
#endif
#include "unit.h"
#include "strv.h"
#include "conf-parser.h"
#include "load-fragment.h"
#include "log.h"
#include "ioprio.h"
#include "securebits.h"
#include "missing.h"
#include "unit-name.h"
#include "unit-printf.h"
#include "utf8.h"
#include "path-util.h"
#include "env-util.h"
#include "cgroup.h"
#include "bus-util.h"
#include "bus-error.h"
#include "errno-list.h"
#include "af-list.h"
#include "cap-list.h"
#include "signal-util.h"
#include "bus-error.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "cap-list.h"
#include "cgroup.h"
#include "conf-parser.h"
#include "env-util.h"
#include "errno-list.h"
#include "ioprio.h"
#include "log.h"
#include "missing.h"
#include "path-util.h"
#ifdef HAVE_SECCOMP
#include "seccomp-util.h"
#endif
#include "securebits.h"
#include "signal-util.h"
#include "strv.h"
#include "unit-name.h"
#include "unit-printf.h"
#include "unit.h"
#include "utf8.h"
#include "load-fragment.h"
int config_parse_warn_compat(
const char *unit,
@ -195,16 +193,17 @@ int config_parse_unit_strv_printf(const char *unit,
k ? k : rvalue, data, userdata);
}
int config_parse_unit_path_printf(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
int config_parse_unit_path_printf(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_free_ char *k = NULL;
Unit *u = userdata;
@ -1846,6 +1845,70 @@ int config_parse_bus_endpoint_policy(
return bus_endpoint_add_policy(c->bus_endpoint, name, access);
}
int config_parse_working_directory(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
ExecContext *c = data;
Unit *u = userdata;
bool missing_ok;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(c);
assert(u);
if (rvalue[0] == '-') {
missing_ok = true;
rvalue++;
} else
missing_ok = false;
if (streq(rvalue, "~")) {
c->working_directory_home = true;
c->working_directory = mfree(c->working_directory);
} else {
_cleanup_free_ char *k = NULL;
r = unit_full_printf(u, rvalue, &k);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in working directory path '%s', ignoring: %m", rvalue);
return 0;
}
path_kill_slashes(k);
if (!utf8_is_valid(k)) {
log_invalid_utf8(unit, LOG_ERR, filename, line, 0, rvalue);
return 0;
}
if (!path_is_absolute(k)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Working directory path '%s' is not absolute, ignoring.", rvalue);
return 0;
}
free(c->working_directory);
c->working_directory = k;
k = NULL;
c->working_directory_home = false;
}
c->working_directory_missing_ok = missing_ok;
return 0;
}
int config_parse_unit_env_file(const char *unit,
const char *filename,
unsigned line,

View file

@ -106,6 +106,7 @@ int config_parse_protect_home(const char* unit, const char *filename, unsigned l
int config_parse_protect_system(const char* unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_bus_name(const char* unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_exec_utmp_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_working_directory(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
/* gperf prototypes */
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, unsigned length);

View file

@ -19,63 +19,63 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/prctl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#ifdef HAVE_VALGRIND_VALGRIND_H
#include <valgrind/valgrind.h>
#endif
#include <sys/prctl.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef HAVE_SECCOMP
#include <seccomp.h>
#endif
#ifdef HAVE_VALGRIND_VALGRIND_H
#include <valgrind/valgrind.h>
#endif
#include "sd-daemon.h"
#include "sd-bus.h"
#include "log.h"
#include "fdset.h"
#include "special.h"
#include "conf-parser.h"
#include "missing.h"
#include "pager.h"
#include "build.h"
#include "strv.h"
#include "def.h"
#include "virt.h"
#include "architecture.h"
#include "watchdog.h"
#include "switch-root.h"
#include "capability.h"
#include "killall.h"
#include "env-util.h"
#include "clock-util.h"
#include "fileio.h"
#include "build.h"
#include "bus-error.h"
#include "bus-util.h"
#include "selinux-util.h"
#include "formats-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "manager.h"
#include "capability.h"
#include "clock-util.h"
#include "conf-parser.h"
#include "dbus-manager.h"
#include "load-fragment.h"
#include "mount-setup.h"
#include "loopback-setup.h"
#include "def.h"
#include "env-util.h"
#include "fdset.h"
#include "fileio.h"
#include "formats-util.h"
#include "hostname-setup.h"
#include "machine-id-setup.h"
#include "selinux-setup.h"
#include "ima-setup.h"
#include "smack-setup.h"
#include "killall.h"
#include "kmod-setup.h"
#include "load-fragment.h"
#include "log.h"
#include "loopback-setup.h"
#include "machine-id-setup.h"
#include "manager.h"
#include "missing.h"
#include "mount-setup.h"
#include "pager.h"
#include "process-util.h"
#include "selinux-setup.h"
#include "selinux-util.h"
#include "signal-util.h"
#include "smack-setup.h"
#include "special.h"
#include "strv.h"
#include "switch-root.h"
#include "terminal-util.h"
#include "virt.h"
#include "watchdog.h"
static enum {
ACTION_RUN,
@ -88,8 +88,9 @@ static enum {
static char *arg_default_unit = NULL;
static ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
static bool arg_dump_core = true;
static bool arg_crash_shell = false;
static int arg_crash_chvt = -1;
static bool arg_crash_shell = false;
static bool arg_crash_reboot = false;
static bool arg_confirm_spawn = false;
static ShowStatus arg_show_status = _SHOW_STATUS_UNSET;
static bool arg_switched_root = false;
@ -116,8 +117,6 @@ static bool arg_default_blockio_accounting = false;
static bool arg_default_memory_accounting = false;
static bool arg_default_tasks_accounting = false;
static void nop_handler(int sig) {}
static void pager_open_if_enabled(void) {
if (arg_no_pager <= 0)
@ -126,49 +125,65 @@ static void pager_open_if_enabled(void) {
pager_open(false);
}
noreturn static void freeze_or_reboot(void) {
if (arg_crash_reboot) {
log_notice("Rebooting in 10s...");
(void) sleep(10);
log_notice("Rebooting now...");
(void) reboot(RB_AUTOBOOT);
log_emergency_errno(errno, "Failed to reboot: %m");
}
log_emergency("Freezing execution.");
freeze();
}
noreturn static void crash(int sig) {
if (getpid() != 1)
/* Pass this on immediately, if this is not PID 1 */
raise(sig);
(void) raise(sig);
else if (!arg_dump_core)
log_emergency("Caught <%s>, not dumping core.", signal_to_string(sig));
else {
struct sigaction sa = {
.sa_handler = nop_handler,
.sa_handler = nop_signal_handler,
.sa_flags = SA_NOCLDSTOP|SA_RESTART,
};
pid_t pid;
/* We want to wait for the core process, hence let's enable SIGCHLD */
sigaction(SIGCHLD, &sa, NULL);
(void) sigaction(SIGCHLD, &sa, NULL);
pid = raw_clone(SIGCHLD, NULL);
if (pid < 0)
log_emergency_errno(errno, "Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
else if (pid == 0) {
struct rlimit rl = {};
struct rlimit rl = {
.rlim_cur = RLIM_INFINITY,
.rlim_max = RLIM_INFINITY,
};
/* Enable default signal handler for core dump */
zero(sa);
sa.sa_handler = SIG_DFL;
sigaction(sig, &sa, NULL);
sa = (struct sigaction) {
.sa_handler = SIG_DFL,
};
(void) sigaction(sig, &sa, NULL);
/* Don't limit the core dump size */
rl.rlim_cur = RLIM_INFINITY;
rl.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &rl);
(void) setrlimit(RLIMIT_CORE, &rl);
/* Just to be sure... */
(void) chdir("/");
/* Raise the signal again */
pid = raw_getpid();
kill(pid, sig); /* raise() would kill the parent */
(void) kill(pid, sig); /* raise() would kill the parent */
assert_not_reached("We shouldn't be here...");
_exit(1);
_exit(EXIT_FAILURE);
} else {
siginfo_t status;
int r;
@ -190,8 +205,8 @@ noreturn static void crash(int sig) {
}
}
if (arg_crash_chvt)
chvt(arg_crash_chvt);
if (arg_crash_chvt >= 0)
(void) chvt(arg_crash_chvt);
if (arg_crash_shell) {
struct sigaction sa = {
@ -200,27 +215,30 @@ noreturn static void crash(int sig) {
};
pid_t pid;
log_info("Executing crash shell in 10s...");
sleep(10);
log_notice("Executing crash shell in 10s...");
(void) sleep(10);
/* Let the kernel reap children for us */
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
(void) sigaction(SIGCHLD, &sa, NULL);
pid = raw_clone(SIGCHLD, NULL);
if (pid < 0)
log_emergency_errno(errno, "Failed to fork off crash shell: %m");
else if (pid == 0) {
make_console_stdio();
execle("/bin/sh", "/bin/sh", NULL, environ);
(void) setsid();
(void) make_console_stdio();
(void) execle("/bin/sh", "/bin/sh", NULL, environ);
log_emergency_errno(errno, "execle() failed: %m");
_exit(1);
} else
log_info("Successfully spawned crash shell as PID "PID_FMT".", pid);
freeze_or_reboot();
_exit(EXIT_FAILURE);
} else {
log_info("Spawned crash shell as PID "PID_FMT".", pid);
freeze();
}
}
log_emergency("Freezing execution.");
freeze();
freeze_or_reboot();
}
static void install_crash_handler(void) {
@ -254,17 +272,20 @@ static int console_setup(void) {
return 0;
}
static int set_default_unit(const char *u) {
char *c;
static int parse_crash_chvt(const char *value) {
int b;
assert(u);
if (safe_atoi(value, &arg_crash_chvt) >= 0)
return 0;
c = strdup(u);
if (!c)
return -ENOMEM;
b = parse_boolean(value);
if (b < 0)
return b;
free(arg_default_unit);
arg_default_unit = c;
if (b > 0)
arg_crash_chvt = 0; /* switch to where kmsg goes */
else
arg_crash_chvt = -1; /* turn off switching */
return 0;
}
@ -292,12 +313,12 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
if (streq(key, "systemd.unit") && value) {
if (!in_initrd())
return set_default_unit(value);
return free_and_strdup(&arg_default_unit, value);
} else if (streq(key, "rd.systemd.unit") && value) {
if (in_initrd())
return set_default_unit(value);
return free_and_strdup(&arg_default_unit, value);
} else if (streq(key, "systemd.dump_core") && value) {
@ -307,6 +328,11 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
else
arg_dump_core = r;
} else if (streq(key, "systemd.crash_chvt") && value) {
if (parse_crash_chvt(value) < 0)
log_warning("Failed to parse crash chvt switch %s. Ignoring.", value);
} else if (streq(key, "systemd.crash_shell") && value) {
r = parse_boolean(value);
@ -315,12 +341,13 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
else
arg_crash_shell = r;
} else if (streq(key, "systemd.crash_chvt") && value) {
} else if (streq(key, "systemd.crash_reboot") && value) {
if (safe_atoi(value, &r) < 0)
log_warning("Failed to parse crash chvt switch %s. Ignoring.", value);
r = parse_boolean(value);
if (r < 0)
log_warning("Failed to parse crash reboot switch %s. Ignoring.", value);
else
arg_crash_chvt = r;
arg_crash_reboot = r;
} else if (streq(key, "systemd.confirm_spawn") && value) {
@ -384,7 +411,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
/* SysV compatibility */
for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
if (streq(key, rlmap[i]))
return set_default_unit(rlmap[i+1]);
return free_and_strdup(&arg_default_unit, rlmap[i+1]);
}
return 0;
@ -410,9 +437,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
\
r = func(rvalue); \
if (r < 0) \
log_syntax(unit, LOG_ERR, filename, line, -r, \
"Invalid " descr "'%s': %s", \
rvalue, strerror(-r)); \
log_syntax(unit, LOG_ERR, filename, line, r, \
"Invalid " descr "'%s': %m", \
rvalue); \
\
return 0; \
}
@ -478,21 +505,32 @@ static int config_parse_show_status(
return 0;
}
static void strv_free_free(char ***l) {
char ***i;
static int config_parse_crash_chvt(
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
if (!l)
return;
int r;
for (i = l; *i; i++)
strv_free(*i);
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
free(l);
}
r = parse_crash_chvt(rvalue);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue);
return 0;
}
static void free_join_controllers(void) {
strv_free_free(arg_join_controllers);
arg_join_controllers = NULL;
return 0;
}
static int config_parse_join_controllers(const char *unit,
@ -513,7 +551,7 @@ static int config_parse_join_controllers(const char *unit,
assert(lvalue);
assert(rvalue);
free_join_controllers();
arg_join_controllers = strv_free_free(arg_join_controllers);
for (;;) {
_cleanup_free_ char *word = NULL;
@ -530,7 +568,7 @@ static int config_parse_join_controllers(const char *unit,
l = strv_split(word, ",");
if (!l)
log_oom();
return log_oom();
strv_uniq(l);
if (strv_length(l) <= 1) {
@ -605,9 +643,11 @@ static int parse_config_file(void) {
{ "Manager", "LogColor", config_parse_color, 0, NULL },
{ "Manager", "LogLocation", config_parse_location, 0, NULL },
{ "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
{ "Manager", "CrashChVT", /* legacy */ config_parse_crash_chvt, 0, NULL },
{ "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, NULL },
{ "Manager", "CrashShell", config_parse_bool, 0, &arg_crash_shell },
{ "Manager", "CrashReboot", config_parse_bool, 0, &arg_crash_reboot },
{ "Manager", "ShowStatus", config_parse_show_status, 0, &arg_show_status },
{ "Manager", "CrashChVT", config_parse_int, 0, &arg_crash_chvt },
{ "Manager", "CPUAffinity", config_parse_cpu_affinity2, 0, NULL },
{ "Manager", "JoinControllers", config_parse_join_controllers, 0, &arg_join_controllers },
{ "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog },
@ -695,7 +735,9 @@ static int parse_argv(int argc, char *argv[]) {
ARG_VERSION,
ARG_DUMP_CONFIGURATION_ITEMS,
ARG_DUMP_CORE,
ARG_CRASH_CHVT,
ARG_CRASH_SHELL,
ARG_CRASH_REBOOT,
ARG_CONFIRM_SPAWN,
ARG_SHOW_STATUS,
ARG_DESERIALIZE,
@ -718,7 +760,9 @@ static int parse_argv(int argc, char *argv[]) {
{ "version", no_argument, NULL, ARG_VERSION },
{ "dump-configuration-items", no_argument, NULL, ARG_DUMP_CONFIGURATION_ITEMS },
{ "dump-core", optional_argument, NULL, ARG_DUMP_CORE },
{ "crash-chvt", required_argument, NULL, ARG_CRASH_CHVT },
{ "crash-shell", optional_argument, NULL, ARG_CRASH_SHELL },
{ "crash-reboot", optional_argument, NULL, ARG_CRASH_REBOOT },
{ "confirm-spawn", optional_argument, NULL, ARG_CONFIRM_SPAWN },
{ "show-status", optional_argument, NULL, ARG_SHOW_STATUS },
{ "deserialize", required_argument, NULL, ARG_DESERIALIZE },
@ -803,7 +847,7 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_UNIT:
r = set_default_unit(optarg);
r = free_and_strdup(&arg_default_unit, optarg);
if (r < 0)
return log_error_errno(r, "Failed to set default unit %s: %m", optarg);
@ -836,21 +880,42 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_DUMP_CORE:
r = optarg ? parse_boolean(optarg) : 1;
if (r < 0) {
log_error("Failed to parse dump core boolean %s.", optarg);
return r;
if (!optarg)
arg_dump_core = true;
else {
r = parse_boolean(optarg);
if (r < 0)
return log_error_errno(r, "Failed to parse dump core boolean: %s", optarg);
arg_dump_core = r;
}
arg_dump_core = r;
break;
case ARG_CRASH_CHVT:
r = parse_crash_chvt(optarg);
if (r < 0)
return log_error_errno(r, "Failed to parse crash virtual terminal index: %s", optarg);
break;
case ARG_CRASH_SHELL:
r = optarg ? parse_boolean(optarg) : 1;
if (r < 0) {
log_error("Failed to parse crash shell boolean %s.", optarg);
return r;
if (!optarg)
arg_crash_shell = true;
else {
r = parse_boolean(optarg);
if (r < 0)
return log_error_errno(r, "Failed to parse crash shell boolean: %s", optarg);
arg_crash_shell = r;
}
break;
case ARG_CRASH_REBOOT:
if (!optarg)
arg_crash_reboot = true;
else {
r = parse_boolean(optarg);
if (r < 0)
return log_error_errno(r, "Failed to parse crash shell boolean: %s", optarg);
arg_crash_reboot = r;
}
arg_crash_shell = r;
break;
case ARG_CONFIRM_SPAWN:
@ -880,17 +945,16 @@ static int parse_argv(int argc, char *argv[]) {
r = safe_atoi(optarg, &fd);
if (r < 0 || fd < 0) {
log_error("Failed to parse deserialize option %s.", optarg);
return r < 0 ? r : -EINVAL;
return -EINVAL;
}
fd_cloexec(fd, true);
(void) fd_cloexec(fd, true);
f = fdopen(fd, "r");
if (!f)
return log_error_errno(errno, "Failed to open serialization fd: %m");
safe_fclose(arg_serialization);
arg_serialization = f;
break;
@ -950,14 +1014,16 @@ static int help(void) {
" --unit=UNIT Set default unit\n"
" --system Run a system instance, even if PID != 1\n"
" --user Run a user instance\n"
" --dump-core[=0|1] Dump core on crash\n"
" --crash-shell[=0|1] Run shell on crash\n"
" --confirm-spawn[=0|1] Ask for confirmation when spawning processes\n"
" --show-status[=0|1] Show status updates on the console during bootup\n"
" --dump-core[=BOOL] Dump core on crash\n"
" --crash-vt=NR Change to specified VT on crash\n"
" --crash-reboot[=BOOL] Reboot on crash\n"
" --crash-shell[=BOOL] Run shell on crash\n"
" --confirm-spawn[=BOOL] Ask for confirmation when spawning processes\n"
" --show-status[=BOOL] Show status updates on the console during bootup\n"
" --log-target=TARGET Set log target (console, journal, kmsg, journal-or-kmsg, null)\n"
" --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
" --log-color[=0|1] Highlight important log messages\n"
" --log-location[=0|1] Include code location in log messages\n"
" --log-color[=BOOL] Highlight important log messages\n"
" --log-location[=BOOL] Include code location in log messages\n"
" --default-standard-output= Set default standard output for services\n"
" --default-standard-error= Set default standard error output for services\n",
program_invocation_short_name);
@ -965,16 +1031,9 @@ static int help(void) {
return 0;
}
static int version(void) {
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
}
static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) {
FILE *f = NULL;
FDSet *fds = NULL;
_cleanup_fdset_free_ FDSet *fds = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(m);
@ -982,56 +1041,39 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
assert(_fds);
r = manager_open_serialization(m, &f);
if (r < 0) {
log_error_errno(r, "Failed to create serialization file: %m");
goto fail;
}
if (r < 0)
return log_error_errno(r, "Failed to create serialization file: %m");
/* Make sure nothing is really destructed when we shut down */
m->n_reloading ++;
bus_manager_send_reloading(m, true);
fds = fdset_new();
if (!fds) {
r = -ENOMEM;
log_error_errno(r, "Failed to allocate fd set: %m");
goto fail;
}
if (!fds)
return log_oom();
r = manager_serialize(m, f, fds, switching_root);
if (r < 0) {
log_error_errno(r, "Failed to serialize state: %m");
goto fail;
}
if (r < 0)
return log_error_errno(r, "Failed to serialize state: %m");
if (fseeko(f, 0, SEEK_SET) < 0) {
log_error_errno(errno, "Failed to rewind serialization fd: %m");
goto fail;
}
if (fseeko(f, 0, SEEK_SET) == (off_t) -1)
return log_error_errno(errno, "Failed to rewind serialization fd: %m");
r = fd_cloexec(fileno(f), false);
if (r < 0) {
log_error_errno(r, "Failed to disable O_CLOEXEC for serialization: %m");
goto fail;
}
if (r < 0)
return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization: %m");
r = fdset_cloexec(fds, false);
if (r < 0) {
log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m");
goto fail;
}
if (r < 0)
return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m");
*_f = f;
*_fds = fds;
f = NULL;
fds = NULL;
return 0;
fail:
fdset_free(fds);
safe_fclose(f);
return r;
}
static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
@ -1090,7 +1132,7 @@ static void test_mtab(void) {
log_error("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. "
"This is not supported anymore. "
"Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
freeze();
freeze_or_reboot();
}
static void test_usr(void) {
@ -1116,15 +1158,19 @@ static int initialize_join_controllers(void) {
return -ENOMEM;
arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL);
if (!arg_join_controllers[0])
goto oom;
arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL);
if (!arg_join_controllers[1])
goto oom;
arg_join_controllers[2] = NULL;
if (!arg_join_controllers[0] || !arg_join_controllers[1]) {
free_join_controllers();
return -ENOMEM;
}
return 0;
oom:
arg_join_controllers = strv_free_free(arg_join_controllers);
return -ENOMEM;
}
static int enforce_syscall_archs(Set *archs) {
@ -1222,7 +1268,6 @@ int main(int argc, char *argv[]) {
char *switch_root_dir = NULL, *switch_root_init = NULL;
struct rlimit saved_rlimit_nofile = RLIMIT_MAKE_CONST(0);
const char *error_message = NULL;
uint8_t shutdown_exit_code = 0;
#ifdef HAVE_SYSV_COMPAT
if (getpid() != 1 && strstr(program_invocation_short_name, "init")) {
@ -1369,7 +1414,7 @@ int main(int argc, char *argv[]) {
}
/* Initialize default unit */
r = set_default_unit(SPECIAL_DEFAULT_TARGET);
r = free_and_strdup(&arg_default_unit, SPECIAL_DEFAULT_TARGET);
if (r < 0) {
log_emergency_errno(r, "Failed to set default unit %s: %m", SPECIAL_DEFAULT_TARGET);
error_message = "Failed to set default unit";
@ -1646,8 +1691,7 @@ int main(int argc, char *argv[]) {
/* This will close all file descriptors that were opened, but
* not claimed by any unit. */
fdset_free(fds);
fds = NULL;
fds = fdset_free(fds);
arg_serialization = safe_fclose(arg_serialization);
@ -1775,8 +1819,9 @@ int main(int argc, char *argv[]) {
goto finish;
case MANAGER_EXIT:
retval = m->return_value;
if (m->running_as == MANAGER_USER) {
retval = EXIT_SUCCESS;
log_debug("Exit.");
goto finish;
}
@ -1809,21 +1854,17 @@ int main(int argc, char *argv[]) {
finish:
pager_close();
if (m) {
if (m)
arg_shutdown_watchdog = m->shutdown_watchdog;
shutdown_exit_code = m->return_value;
}
m = manager_free(m);
for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++)
arg_default_rlimit[j] = mfree(arg_default_rlimit[j]);
arg_default_unit = mfree(arg_default_unit);
free_join_controllers();
arg_join_controllers = strv_free_free(arg_join_controllers);
arg_default_environment = strv_free(arg_default_environment);
arg_syscall_archs = set_free(arg_syscall_archs);
mac_selinux_finish();
@ -1841,7 +1882,7 @@ finish:
* that the new systemd can pass the kernel default to
* its child processes */
if (saved_rlimit_nofile.rlim_cur > 0)
setrlimit(RLIMIT_NOFILE, &saved_rlimit_nofile);
(void) setrlimit(RLIMIT_NOFILE, &saved_rlimit_nofile);
if (switch_root_dir) {
/* Kill all remaining processes from the
@ -1883,10 +1924,10 @@ finish:
/* do not pass along the environment we inherit from the kernel or initrd */
if (switch_root_dir)
clearenv();
(void) clearenv();
assert(i <= args_size);
execv(args[0], (char* const*) args);
(void) execv(args[0], (char* const*) args);
}
/* Try the fallback, if there is any, without any
@ -1896,14 +1937,10 @@ finish:
* but let's hope that doesn't matter.) */
arg_serialization = safe_fclose(arg_serialization);
if (fds) {
fdset_free(fds);
fds = NULL;
}
fds = fdset_free(fds);
/* Reopen the console */
make_console_stdio();
(void) make_console_stdio();
for (j = 1, i = 1; j < (unsigned) argc; j++)
args[i++] = argv[j];
@ -1917,30 +1954,26 @@ finish:
if (switch_root_init) {
args[0] = switch_root_init;
execv(args[0], (char* const*) args);
(void) execv(args[0], (char* const*) args);
log_warning_errno(errno, "Failed to execute configured init, trying fallback: %m");
}
args[0] = "/sbin/init";
execv(args[0], (char* const*) args);
(void) execv(args[0], (char* const*) args);
if (errno == ENOENT) {
log_warning("No /sbin/init, trying fallback");
args[0] = "/bin/sh";
args[1] = NULL;
execv(args[0], (char* const*) args);
(void) execv(args[0], (char* const*) args);
log_error_errno(errno, "Failed to execute /bin/sh, giving up: %m");
} else
log_warning_errno(errno, "Failed to execute /sbin/init, giving up: %m");
}
arg_serialization = safe_fclose(arg_serialization);
if (fds) {
fdset_free(fds);
fds = NULL;
}
fds = fdset_free(fds);
#ifdef HAVE_VALGRIND_VALGRIND_H
/* If we are PID 1 and running under valgrind, then let's exit
@ -1969,6 +2002,7 @@ finish:
xsprintf(log_level, "%d", log_get_max_level());
switch (log_get_target()) {
case LOG_TARGET_KMSG:
case LOG_TARGET_JOURNAL_OR_KMSG:
case LOG_TARGET_SYSLOG_OR_KMSG:
@ -1994,7 +2028,7 @@ finish:
if (streq(shutdown_verb, "exit")) {
command_line[pos++] = "--exit-code";
command_line[pos++] = exit_code;
xsprintf(exit_code, "%d", shutdown_exit_code);
xsprintf(exit_code, "%d", retval);
}
assert(pos < ELEMENTSOF(command_line));
@ -2010,7 +2044,7 @@ finish:
/* Tell the binary how often to ping, ignore failure */
if (asprintf(&e, "WATCHDOG_USEC="USEC_FMT, arg_shutdown_watchdog) > 0)
strv_push(&env_block, e);
(void) strv_push(&env_block, e);
} else
watchdog_close(true);
@ -2030,7 +2064,7 @@ finish:
manager_status_printf(NULL, STATUS_TYPE_EMERGENCY,
ANSI_HIGHLIGHT_RED "!!!!!!" ANSI_NORMAL,
"%s, freezing.", error_message);
freeze();
freeze_or_reboot();
}
return retval;

View file

@ -19,19 +19,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <signal.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/timerfd.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/inotify.h>
#include <sys/epoll.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/timerfd.h>
#ifdef HAVE_AUDIT
#include <libaudit.h>
@ -40,40 +40,40 @@
#include "sd-daemon.h"
#include "sd-messages.h"
#include "hashmap.h"
#include "macro.h"
#include "strv.h"
#include "log.h"
#include "util.h"
#include "mkdir.h"
#include "ratelimit.h"
#include "locale-setup.h"
#include "unit-name.h"
#include "missing.h"
#include "rm-rf.h"
#include "path-lookup.h"
#include "special.h"
#include "exit-status.h"
#include "virt.h"
#include "watchdog.h"
#include "path-util.h"
#include "audit-fd.h"
#include "boot-timestamps.h"
#include "env-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-kernel.h"
#include "time-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "dbus.h"
#include "dbus-unit.h"
#include "bus-util.h"
#include "dbus-job.h"
#include "dbus-manager.h"
#include "manager.h"
#include "dbus-unit.h"
#include "dbus.h"
#include "env-util.h"
#include "exit-status.h"
#include "hashmap.h"
#include "locale-setup.h"
#include "log.h"
#include "macro.h"
#include "missing.h"
#include "mkdir.h"
#include "path-lookup.h"
#include "path-util.h"
#include "process-util.h"
#include "ratelimit.h"
#include "rm-rf.h"
#include "signal-util.h"
#include "special.h"
#include "strv.h"
#include "terminal-util.h"
#include "time-util.h"
#include "transaction.h"
#include "unit-name.h"
#include "util.h"
#include "virt.h"
#include "watchdog.h"
#include "manager.h"
/* Initial delay and the interval for printing status messages about running jobs */
#define JOBS_IN_PROGRESS_WAIT_USEC (5*USEC_PER_SEC)

View file

@ -27,8 +27,8 @@
#include "sd-bus.h"
#include "sd-event.h"
#include "fdset.h"
#include "cgroup-util.h"
#include "fdset.h"
#include "hashmap.h"
#include "list.h"
#include "ratelimit.h"
@ -69,11 +69,11 @@ typedef enum StatusType {
STATUS_TYPE_EMERGENCY,
} StatusType;
#include "execute.h"
#include "job.h"
#include "path-lookup.h"
#include "execute.h"
#include "unit-name.h"
#include "show-status.h"
#include "unit-name.h"
struct Manager {
/* Note that the set of units we know of is allowed to be

View file

@ -643,16 +643,7 @@ int setup_tmp_dirs(const char *id, char **tmp_dir, char **var_tmp_dir) {
int setup_netns(int netns_storage_socket[2]) {
_cleanup_close_ int netns = -1;
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
} control = {};
struct msghdr mh = {
.msg_control = &control,
.msg_controllen = sizeof(control),
};
struct cmsghdr *cmsg;
int r;
int r, q;
assert(netns_storage_socket);
assert(netns_storage_socket[0] >= 0);
@ -669,12 +660,8 @@ int setup_netns(int netns_storage_socket[2]) {
if (lockf(netns_storage_socket[0], F_LOCK, 0) < 0)
return -errno;
if (recvmsg(netns_storage_socket[0], &mh, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) < 0) {
if (errno != EAGAIN) {
r = -errno;
goto fail;
}
netns = receive_one_fd(netns_storage_socket[0], MSG_DONTWAIT);
if (netns == -EAGAIN) {
/* Nothing stored yet, so let's create a new namespace */
if (unshare(CLONE_NEWNET) < 0) {
@ -691,15 +678,13 @@ int setup_netns(int netns_storage_socket[2]) {
}
r = 1;
} else if (netns < 0) {
r = netns;
goto fail;
} else {
/* Yay, found something, so let's join the namespace */
CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
assert(cmsg->cmsg_len == CMSG_LEN(sizeof(int)));
netns = *(int*) CMSG_DATA(cmsg);
}
if (setns(netns, CLONE_NEWNET) < 0) {
r = -errno;
goto fail;
@ -708,21 +693,14 @@ int setup_netns(int netns_storage_socket[2]) {
r = 0;
}
cmsg = CMSG_FIRSTHDR(&mh);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cmsg), &netns, sizeof(int));
mh.msg_controllen = cmsg->cmsg_len;
if (sendmsg(netns_storage_socket[1], &mh, MSG_DONTWAIT|MSG_NOSIGNAL) < 0) {
r = -errno;
q = send_one_fd(netns_storage_socket[1], netns, MSG_DONTWAIT);
if (q < 0) {
r = q;
goto fail;
}
fail:
lockf(netns_storage_socket[0], F_ULOCK, 0);
return r;
}

View file

@ -78,14 +78,14 @@ int mac_selinux_setup(bool *loaded_policy) {
before_load = now(CLOCK_MONOTONIC);
r = selinux_init_load_policy(&enforce);
if (r == 0) {
_cleanup_(mac_selinux_freep) char *label = NULL;
char timespan[FORMAT_TIMESPAN_MAX];
char *label;
mac_selinux_retest();
/* Transition to the new context */
r = mac_selinux_get_create_label_from_exe(SYSTEMD_BINARY_PATH, &label);
if (r < 0 || label == NULL) {
if (r < 0 || !label) {
log_open();
log_error("Failed to compute init label, ignoring.");
} else {
@ -94,8 +94,6 @@ int mac_selinux_setup(bool *loaded_policy) {
log_open();
if (r < 0)
log_error("Failed to transition into init label '%s', ignoring.", label);
mac_selinux_free(label);
}
after_load = now(CLOCK_MONOTONIC);

View file

@ -430,6 +430,5 @@ int main(int argc, char *argv[]) {
error:
log_emergency_errno(r, "Critical error while doing system shutdown: %m");
freeze();
}

View file

@ -19,38 +19,39 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/stat.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <signal.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <mqueue.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <sys/epoll.h>
#include <sys/stat.h>
#include <unistd.h>
#include "sd-event.h"
#include "bus-error.h"
#include "bus-util.h"
#include "copy.h"
#include "dbus-socket.h"
#include "def.h"
#include "exit-status.h"
#include "formats-util.h"
#include "label.h"
#include "log.h"
#include "strv.h"
#include "missing.h"
#include "mkdir.h"
#include "path-util.h"
#include "selinux-util.h"
#include "signal-util.h"
#include "smack-util.h"
#include "socket.h"
#include "special.h"
#include "strv.h"
#include "unit-name.h"
#include "unit-printf.h"
#include "missing.h"
#include "special.h"
#include "label.h"
#include "exit-status.h"
#include "def.h"
#include "smack-util.h"
#include "bus-util.h"
#include "bus-error.h"
#include "selinux-util.h"
#include "dbus-socket.h"
#include "unit.h"
#include "formats-util.h"
#include "signal-util.h"
#include "socket.h"
#include "copy.h"
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = UNIT_INACTIVE,
@ -955,50 +956,48 @@ static void socket_apply_fifo_options(Socket *s, int fd) {
if (s->pipe_size > 0)
if (fcntl(fd, F_SETPIPE_SZ, s->pipe_size) < 0)
log_unit_warning_errno(UNIT(s), errno, "F_SETPIPE_SZ: %m");
log_unit_warning_errno(UNIT(s), errno, "Setting pipe size failed, ignoring: %m");
if (s->smack) {
r = mac_smack_apply_fd(fd, SMACK_ATTR_ACCESS, s->smack);
if (r < 0)
log_unit_error_errno(UNIT(s), r, "mac_smack_apply_fd: %m");
log_unit_error_errno(UNIT(s), r, "SMACK relabelling failed, ignoring: %m");
}
}
static int fifo_address_create(
const char *path,
mode_t directory_mode,
mode_t socket_mode,
int *_fd) {
mode_t socket_mode) {
int fd = -1, r = 0;
struct stat st;
_cleanup_close_ int fd = -1;
mode_t old_mask;
struct stat st;
int r;
assert(path);
assert(_fd);
mkdir_parents_label(path, directory_mode);
r = mac_selinux_create_file_prepare(path, S_IFIFO);
if (r < 0)
goto fail;
return r;
/* Enforce the right access mode for the fifo */
old_mask = umask(~ socket_mode);
/* Include the original umask in our mask */
umask(~socket_mode | old_mask);
(void) umask(~socket_mode | old_mask);
r = mkfifo(path, socket_mode);
umask(old_mask);
(void) umask(old_mask);
if (r < 0 && errno != EEXIST) {
r = -errno;
goto fail;
}
fd = open(path,
O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW);
fd = open(path, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW);
if (fd < 0) {
r = -errno;
goto fail;
@ -1015,13 +1014,14 @@ static int fifo_address_create(
(st.st_mode & 0777) != (socket_mode & ~old_mask) ||
st.st_uid != getuid() ||
st.st_gid != getgid()) {
r = -EEXIST;
goto fail;
}
*_fd = fd;
return 0;
r = fd;
fd = -1;
return r;
fail:
mac_selinux_create_file_clear();
@ -1030,51 +1030,36 @@ fail:
return r;
}
static int special_address_create(
const char *path,
int *_fd) {
int fd = -1, r = 0;
static int special_address_create(const char *path) {
_cleanup_close_ int fd = -1;
struct stat st;
int r;
assert(path);
assert(_fd);
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW);
if (fd < 0) {
r = -errno;
goto fail;
}
if (fd < 0)
return -errno;
if (fstat(fd, &st) < 0) {
r = -errno;
goto fail;
}
if (fstat(fd, &st) < 0)
return -errno;
/* Check whether this is a /proc, /sys or /dev file or char device */
if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
r = -EEXIST;
goto fail;
}
if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode))
return -EEXIST;
*_fd = fd;
return 0;
fail:
safe_close(fd);
r = fd;
fd = -1;
return r;
}
static int ffs_address_create(
const char *path,
int *_fd) {
static int usbffs_address_create(const char *path) {
_cleanup_close_ int fd = -1;
struct stat st;
int r;
assert(path);
assert(_fd);
fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW);
if (fd < 0)
@ -1087,32 +1072,32 @@ static int ffs_address_create(
if (!S_ISREG(st.st_mode))
return -EEXIST;
*_fd = fd;
r = fd;
fd = -1;
return 0;
return r;
}
static int mq_address_create(
const char *path,
mode_t mq_mode,
long maxmsg,
long msgsize,
int *_fd) {
long msgsize) {
int fd = -1, r = 0;
_cleanup_close_ int fd = -1;
struct stat st;
mode_t old_mask;
struct mq_attr _attr, *attr = NULL;
int r;
assert(path);
assert(_fd);
if (maxmsg > 0 && msgsize > 0) {
zero(_attr);
_attr.mq_flags = O_NONBLOCK;
_attr.mq_maxmsg = maxmsg;
_attr.mq_msgsize = msgsize;
_attr = (struct mq_attr) {
.mq_flags = O_NONBLOCK,
.mq_maxmsg = maxmsg,
.mq_msgsize = msgsize,
};
attr = &_attr;
}
@ -1120,33 +1105,24 @@ static int mq_address_create(
old_mask = umask(~ mq_mode);
/* Include the original umask in our mask */
umask(~mq_mode | old_mask);
(void) umask(~mq_mode | old_mask);
fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr);
umask(old_mask);
(void) umask(old_mask);
if (fd < 0) {
r = -errno;
goto fail;
}
if (fd < 0)
return -errno;
if (fstat(fd, &st) < 0) {
r = -errno;
goto fail;
}
if (fstat(fd, &st) < 0)
return -errno;
if ((st.st_mode & 0777) != (mq_mode & ~old_mask) ||
st.st_uid != getuid() ||
st.st_gid != getgid()) {
st.st_gid != getgid())
return -EEXIST;
r = -EEXIST;
goto fail;
}
r = fd;
fd = -1;
*_fd = fd;
return 0;
fail:
safe_close(fd);
return r;
}
@ -1166,8 +1142,7 @@ static int socket_symlink(Socket *s) {
return 0;
}
static int ffs_write_descs(int fd, Unit *u) {
Service *s = SERVICE(u);
static int usbffs_write_descs(int fd, Service *s) {
int r;
if (!s->usb_function_descriptors || !s->usb_function_strings)
@ -1175,27 +1150,25 @@ static int ffs_write_descs(int fd, Unit *u) {
r = copy_file_fd(s->usb_function_descriptors, fd, false);
if (r < 0)
return 0;
return r;
r = copy_file_fd(s->usb_function_strings, fd, false);
return r;
return copy_file_fd(s->usb_function_strings, fd, false);
}
static int select_ep(const struct dirent *d) {
static int usbffs_select_ep(const struct dirent *d) {
return d->d_name[0] != '.' && !streq(d->d_name, "ep0");
}
static int ffs_dispatch_eps(SocketPort *p) {
static int usbffs_dispatch_eps(SocketPort *p) {
_cleanup_free_ struct dirent **ent = NULL;
int r, i, n, k;
_cleanup_free_ char *path = NULL;
int r, i, n, k;
r = path_get_parent(p->path, &path);
if (r < 0)
return r;
r = scandir(path, &ent, select_ep, alphasort);
r = scandir(path, &ent, usbffs_select_ep, alphasort);
if (r < 0)
return -errno;
@ -1216,10 +1189,12 @@ static int ffs_dispatch_eps(SocketPort *p) {
path_kill_slashes(ep);
r = ffs_address_create(ep, &p->auxiliary_fds[k]);
r = usbffs_address_create(ep);
if (r < 0)
goto fail;
p->auxiliary_fds[k] = r;
++k;
free(ent[i]);
}
@ -1227,9 +1202,7 @@ static int ffs_dispatch_eps(SocketPort *p) {
return r;
fail:
while (k)
safe_close(p->auxiliary_fds[--k]);
close_many(p->auxiliary_fds, k);
p->auxiliary_fds = mfree(p->auxiliary_fds);
p->n_auxiliary_fds = 0;
@ -1237,10 +1210,10 @@ fail:
}
static int socket_open_fds(Socket *s) {
_cleanup_(mac_selinux_freep) char *label = NULL;
bool know_label = false;
SocketPort *p;
int r;
char *label = NULL;
bool know_label = false;
assert(s);
@ -1249,7 +1222,9 @@ static int socket_open_fds(Socket *s) {
if (p->fd >= 0)
continue;
if (p->type == SOCKET_SOCKET) {
switch (p->type) {
case SOCKET_SOCKET:
if (!know_label) {
/* Figure out label, if we don't it know
@ -1300,64 +1275,72 @@ static int socket_open_fds(Socket *s) {
p->fd = r;
socket_apply_socket_options(s, p->fd);
socket_symlink(s);
break;
} else if (p->type == SOCKET_SPECIAL) {
case SOCKET_SPECIAL:
r = special_address_create(
p->path,
&p->fd);
if (r < 0)
p->fd = special_address_create(p->path);
if (p->fd < 0) {
r = p->fd;
goto rollback;
}
break;
} else if (p->type == SOCKET_FIFO) {
case SOCKET_FIFO:
r = fifo_address_create(
p->fd = fifo_address_create(
p->path,
s->directory_mode,
s->socket_mode,
&p->fd);
if (r < 0)
s->socket_mode);
if (p->fd < 0) {
r = p->fd;
goto rollback;
}
socket_apply_fifo_options(s, p->fd);
socket_symlink(s);
break;
} else if (p->type == SOCKET_MQUEUE) {
case SOCKET_MQUEUE:
r = mq_address_create(
p->fd = mq_address_create(
p->path,
s->socket_mode,
s->mq_maxmsg,
s->mq_msgsize,
&p->fd);
if (r < 0)
s->mq_msgsize);
if (p->fd < 0) {
r = p->fd;
goto rollback;
} else if (p->type == SOCKET_USB_FUNCTION) {
}
break;
r = ffs_address_create(
p->path,
&p->fd);
case SOCKET_USB_FUNCTION:
p->fd = usbffs_address_create(p->path);
if (p->fd < 0) {
r = p->fd;
goto rollback;
}
r = usbffs_write_descs(p->fd, SERVICE(UNIT_DEREF(s->service)));
if (r < 0)
goto rollback;
r = ffs_write_descs(p->fd, s->service.unit);
r = usbffs_dispatch_eps(p);
if (r < 0)
goto rollback;
r = ffs_dispatch_eps(p);
if (r < 0)
goto rollback;
} else
break;
default:
assert_not_reached("Unknown port type");
}
}
mac_selinux_free(label);
return 0;
rollback:
socket_close_fds(s);
mac_selinux_free(label);
return r;
}

View file

@ -17,9 +17,10 @@
#LogColor=yes
#LogLocation=no
#DumpCore=yes
#CrashShell=no
#ShowStatus=yes
#CrashChVT=1
#CrashChangeVT=no
#CrashShell=no
#CrashReboot=no
#CPUAffinity=1 2
#JoinControllers=cpu,cpuacct net_cls,net_prio
#RuntimeWatchdogSec=0

View file

@ -1129,12 +1129,12 @@ static int unit_add_slice_dependencies(Unit *u) {
return 0;
if (UNIT_ISSET(u->slice))
return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_WANTS, UNIT_DEREF(u->slice), true);
return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, UNIT_DEREF(u->slice), true);
if (streq(u->id, SPECIAL_ROOT_SLICE))
if (unit_has_name(u, SPECIAL_ROOT_SLICE))
return 0;
return unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, SPECIAL_ROOT_SLICE, NULL, true);
return unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, SPECIAL_ROOT_SLICE, NULL, true);
}
static int unit_add_mount_dependencies(Unit *u) {

View file

@ -21,21 +21,20 @@
***/
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <sys/prctl.h>
#include <unistd.h>
#include "hashmap.h"
#include "util.h"
#include "path-util.h"
#include "log.h"
#include "pager.h"
#include "build.h"
#include "strv.h"
#include "path-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
static const char prefixes[] =
"/etc\0"
@ -544,9 +543,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;

View file

@ -19,14 +19,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdlib.h>
#include "util.h"
#include "virt.h"
#include "build.h"
static bool arg_quiet = false;
static enum {
@ -75,9 +74,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'q':
arg_quiet = true;
@ -99,8 +96,7 @@ static int parse_argv(int argc, char *argv[]) {
}
if (optind < argc) {
log_error("%s takes no arguments.",
program_invocation_short_name);
log_error("%s takes no arguments.", program_invocation_short_name);
return -EINVAL;
}
@ -108,7 +104,7 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
int retval = EXIT_SUCCESS, r;
int r;
/* This is mostly intended to be used for scripts which want
* to detect whether we are being run in a virtualized
@ -126,7 +122,7 @@ int main(int argc, char *argv[]) {
case ONLY_VM:
r = detect_vm();
if (r < 0) {
log_error_errno(r, "Failed to check for vm: %m");
log_error_errno(r, "Failed to check for VM: %m");
return EXIT_FAILURE;
}
@ -155,7 +151,5 @@ int main(int argc, char *argv[]) {
if (!arg_quiet)
puts(virtualization_to_string(r));
retval = r != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
return retval;
return r != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
}

View file

@ -19,14 +19,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "log.h"
#include "unit-name.h"
#include "build.h"
#include "strv.h"
#include "unit-name.h"
static enum {
ACTION_ESCAPE,
@ -83,9 +82,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_SUFFIX:

View file

@ -19,24 +19,22 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <shadow.h>
#include <unistd.h>
#include "strv.h"
#include "fileio.h"
#include "ask-password-api.h"
#include "copy.h"
#include "build.h"
#include "fileio.h"
#include "hostname-util.h"
#include "locale-util.h"
#include "mkdir.h"
#include "time-util.h"
#include "path-util.h"
#include "random-util.h"
#include "locale-util.h"
#include "ask-password-api.h"
#include "strv.h"
#include "terminal-util.h"
#include "hostname-util.h"
#include "time-util.h"
static char *arg_root = NULL;
static char *arg_locale = NULL; /* $LANG */
@ -704,9 +702,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_ROOT:
free(arg_root);

View file

@ -67,7 +67,7 @@ static void start_target(const char *target) {
assert(target);
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0) {
log_error_errno(r, "Failed to get D-Bus connection: %m");
return;

View file

@ -19,21 +19,21 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <locale.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "sd-bus.h"
#include "sd-id128.h"
#include "hostname-util.h"
#include "bus-util.h"
#include "bus-error.h"
#include "util.h"
#include "spawn-polkit-agent.h"
#include "build.h"
#include "architecture.h"
#include "bus-error.h"
#include "bus-util.h"
#include "hostname-util.h"
#include "spawn-polkit-agent.h"
#include "util.h"
static bool arg_ask_password = true;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
@ -387,9 +387,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'H':
arg_transport = BUS_TRANSPORT_REMOTE;
@ -519,7 +517,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -17,21 +17,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <ctype.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "strbuf.h"
#include "conf-files.h"
#include "strv.h"
#include "mkdir.h"
#include "verbs.h"
#include "build.h"
#include "hwdb-internal.h"
#include "hwdb-util.h"
#include "mkdir.h"
#include "strbuf.h"
#include "strv.h"
#include "util.h"
#include "verbs.h"
/*
* Generic udev properties, key/value database based on modalias strings.
@ -688,9 +686,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_USR:
arg_hwdb_bin_dir = UDEVLIBEXECDIR;

View file

@ -22,15 +22,15 @@
#include <getopt.h>
#include "sd-event.h"
#include "event-util.h"
#include "signal-util.h"
#include "hostname-util.h"
#include "verbs.h"
#include "build.h"
#include "machine-image.h"
#include "import-util.h"
#include "export-tar.h"
#include "export-raw.h"
#include "export-tar.h"
#include "hostname-util.h"
#include "import-util.h"
#include "machine-image.h"
#include "signal-util.h"
#include "verbs.h"
static ImportCompressType arg_compress = IMPORT_COMPRESS_UNKNOWN;
@ -260,9 +260,7 @@ static int parse_argv(int argc, char *argv[]) {
return help(0, NULL, NULL);
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_FORMAT:
if (streq(optarg, "uncompressed"))

View file

@ -22,15 +22,15 @@
#include <getopt.h>
#include "sd-event.h"
#include "event-util.h"
#include "verbs.h"
#include "build.h"
#include "signal-util.h"
#include "hostname-util.h"
#include "machine-image.h"
#include "import-util.h"
#include "import-tar.h"
#include "import-raw.h"
#include "import-tar.h"
#include "import-util.h"
#include "machine-image.h"
#include "signal-util.h"
#include "verbs.h"
static bool arg_force = false;
static bool arg_read_only = false;
@ -280,9 +280,7 @@ static int parse_argv(int argc, char *argv[]) {
return help(0, NULL, NULL);
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_FORCE:
arg_force = true;

View file

@ -600,11 +600,11 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void
cmsg_close_all(&msghdr);
CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS && cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred)))
CMSG_FOREACH(cmsg, &msghdr)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred)))
ucred = (struct ucred*) CMSG_DATA(cmsg);
}
if (msghdr.msg_flags & MSG_TRUNC) {
log_warning("Got overly long notification datagram, ignoring.");

View file

@ -22,16 +22,16 @@
#include <getopt.h>
#include "sd-event.h"
#include "event-util.h"
#include "verbs.h"
#include "build.h"
#include "signal-util.h"
#include "hostname-util.h"
#include "machine-image.h"
#include "import-util.h"
#include "pull-tar.h"
#include "pull-raw.h"
#include "machine-image.h"
#include "pull-dkr.h"
#include "pull-raw.h"
#include "pull-tar.h"
#include "signal-util.h"
#include "verbs.h"
static bool arg_force = false;
static const char *arg_image_root = "/var/lib/machines";
@ -381,9 +381,7 @@ static int parse_argv(int argc, char *argv[]) {
return help(0, NULL, NULL);
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_FORCE:
arg_force = true;

View file

@ -318,7 +318,7 @@ static int server_init(Server *s, unsigned n_sockets) {
s->n_fifos ++;
}
r = bus_open_system_systemd(&s->bus);
r = bus_connect_system_systemd(&s->bus);
if (r < 0) {
log_error_errno(r, "Failed to get D-Bus connection: %m");
r = -EIO;

View file

@ -24,9 +24,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <microhttpd.h>
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif
@ -34,15 +32,15 @@
#include "sd-journal.h"
#include "sd-daemon.h"
#include "sd-bus.h"
#include "log.h"
#include "util.h"
#include "bus-util.h"
#include "fileio.h"
#include "hostname-util.h"
#include "log.h"
#include "logs-show.h"
#include "microhttpd-util.h"
#include "build.h"
#include "fileio.h"
#include "sigbus.h"
#include "hostname-util.h"
#include "util.h"
static char *arg_key_pem = NULL;
static char *arg_cert_pem = NULL;
@ -909,9 +907,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_KEY:
if (arg_key_pem) {

View file

@ -21,31 +21,30 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <getopt.h>
#include "sd-daemon.h"
#include "signal-util.h"
#include "journal-file.h"
#include "journald-native.h"
#include "socket-util.h"
#include "build.h"
#include "macro.h"
#include "strv.h"
#include "fileio.h"
#include "conf-parser.h"
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif
#include "journal-remote.h"
#include "sd-daemon.h"
#include "conf-parser.h"
#include "fileio.h"
#include "journal-file.h"
#include "journald-native.h"
#include "macro.h"
#include "signal-util.h"
#include "socket-util.h"
#include "strv.h"
#include "journal-remote-write.h"
#include "journal-remote.h"
#define REMOTE_JOURNAL_PATH "/var/log/journal/remote"
@ -1259,9 +1258,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0 /* done */;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0 /* done */;
return version();
case ARG_URL:
if (arg_url) {

View file

@ -19,22 +19,22 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <curl/curl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include "sd-daemon.h"
#include "log.h"
#include "util.h"
#include "build.h"
#include "fileio.h"
#include "mkdir.h"
#include "conf-parser.h"
#include "sigbus.h"
#include "fileio.h"
#include "formats-util.h"
#include "log.h"
#include "mkdir.h"
#include "sigbus.h"
#include "signal-util.h"
#include "util.h"
#include "journal-upload.h"
#define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
@ -619,9 +619,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0 /* done */;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0 /* done */;
return version();
case 'u':
if (arg_url) {

View file

@ -19,17 +19,16 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "systemd/sd-journal.h"
#include "sd-journal.h"
#include "util.h"
#include "build.h"
static char *arg_identifier = NULL;
static int arg_priority = LOG_INFO;
@ -76,9 +75,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 't':
free(arg_identifier);
@ -95,7 +92,7 @@ static int parse_argv(int argc, char *argv[]) {
arg_priority = log_level_from_string(optarg);
if (arg_priority < 0) {
log_error("Failed to parse priority value.");
return arg_priority;
return -EINVAL;
}
break;
@ -103,10 +100,9 @@ static int parse_argv(int argc, char *argv[]) {
int k;
k = parse_boolean(optarg);
if (k < 0) {
log_error("Failed to parse level prefix value.");
return k;
}
if (k < 0)
return log_error_errno(k, "Failed to parse level prefix value.");
arg_level_prefix = k;
break;
}
@ -122,7 +118,8 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
int r, fd = -1, saved_stderr = -1;
_cleanup_close_ int fd = -1, saved_stderr = -1;
int r;
log_parse_environment();
log_open();
@ -133,8 +130,7 @@ int main(int argc, char *argv[]) {
fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix);
if (fd < 0) {
log_error_errno(fd, "Failed to create stream fd: %m");
r = fd;
r = log_error_errno(fd, "Failed to create stream fd: %m");
goto finish;
}
@ -148,25 +144,20 @@ int main(int argc, char *argv[]) {
if (fd >= 3)
safe_close(fd);
fd = -1;
if (argc <= optind)
execl("/bin/cat", "/bin/cat", NULL);
(void) execl("/bin/cat", "/bin/cat", NULL);
else
execvp(argv[optind], argv + optind);
(void) execvp(argv[optind], argv + optind);
r = -errno;
/* Let's try to restore a working stderr, so we can print the error message */
if (saved_stderr >= 0)
dup3(saved_stderr, STDERR_FILENO, 0);
(void) dup3(saved_stderr, STDERR_FILENO, 0);
log_error_errno(r, "Failed to execute process: %m");
finish:
safe_close(fd);
safe_close(saved_stderr);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

View file

@ -19,27 +19,27 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <getopt.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <unistd.h>
#include "sd-journal.h"
#include "build.h"
#include "set.h"
#include "util.h"
#include "log.h"
#include "path-util.h"
#include "pager.h"
#include "macro.h"
#include "journal-internal.h"
#include "compress.h"
#include "sigbus.h"
#include "journal-internal.h"
#include "log.h"
#include "macro.h"
#include "pager.h"
#include "path-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "set.h"
#include "sigbus.h"
#include "signal-util.h"
#include "terminal-util.h"
#include "util.h"
static enum {
ACTION_NONE,
@ -175,9 +175,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
case ARG_VERSION:
arg_action = ACTION_NONE;
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;

View file

@ -212,11 +212,6 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path),
};
ssize_t k;
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int))];
} control;
struct cmsghdr *cmsg;
bool have_syslog_identifier = false;
bool seal = true;
@ -335,26 +330,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
return r;
}
mh.msg_iov = NULL;
mh.msg_iovlen = 0;
zero(control);
mh.msg_control = &control;
mh.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&mh);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cmsg), &buffer_fd, sizeof(int));
mh.msg_controllen = cmsg->cmsg_len;
k = sendmsg(fd, &mh, MSG_NOSIGNAL);
if (k < 0)
return -errno;
return 0;
return send_one_fd(fd, buffer_fd, 0);
}
static int fill_iovec_perror_and_send(const char *message, int skip, struct iovec iov[]) {

View file

@ -19,48 +19,47 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <locale.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <signal.h>
#include <poll.h>
#include <sys/stat.h>
#include <sys/inotify.h>
#include <linux/fs.h>
#include <locale.h>
#include <poll.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/inotify.h>
#include <sys/stat.h>
#include <unistd.h>
#include "sd-journal.h"
#include "sd-bus.h"
#include "log.h"
#include "logs-show.h"
#include "util.h"
#include "sd-journal.h"
#include "acl-util.h"
#include "path-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "catalog.h"
#include "fileio.h"
#include "build.h"
#include "pager.h"
#include "strv.h"
#include "set.h"
#include "sigbus.h"
#include "journal-internal.h"
#include "fsprg.h"
#include "hostname-util.h"
#include "journal-def.h"
#include "journal-verify.h"
#include "journal-internal.h"
#include "journal-qrcode.h"
#include "journal-vacuum.h"
#include "fsprg.h"
#include "unit-name.h"
#include "catalog.h"
#include "journal-verify.h"
#include "log.h"
#include "logs-show.h"
#include "mkdir.h"
#include "bus-util.h"
#include "bus-error.h"
#include "pager.h"
#include "path-util.h"
#include "set.h"
#include "sigbus.h"
#include "strv.h"
#include "terminal-util.h"
#include "hostname-util.h"
#include "unit-name.h"
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
@ -350,9 +349,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;
@ -1725,7 +1722,7 @@ static int flush_to_var(void) {
/* OK, let's actually do the full logic, send SIGUSR1 to the
* daemon and set up inotify to wait for the flushed file to appear */
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0)
return log_error_errno(r, "Failed to get D-Bus connection: %m");

View file

@ -217,15 +217,8 @@ int bus_container_connect_kernel(sd_bus *b) {
_exit(EXIT_FAILURE);
}
cmsg = CMSG_FIRSTHDR(&mh);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
mh.msg_controllen = cmsg->cmsg_len;
if (sendmsg(pair[1], &mh, MSG_NOSIGNAL) < 0)
r = send_one_fd(pair[1], fd, 0);
if (r < 0)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);

View file

@ -21,22 +21,21 @@
#include <getopt.h>
#include "strv.h"
#include "util.h"
#include "sd-bus.h"
#include "bus-dump.h"
#include "bus-internal.h"
#include "bus-signature.h"
#include "bus-type.h"
#include "bus-util.h"
#include "busctl-introspect.h"
#include "log.h"
#include "build.h"
#include "pager.h"
#include "path-util.h"
#include "set.h"
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "bus-dump.h"
#include "bus-signature.h"
#include "bus-type.h"
#include "busctl-introspect.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
static bool arg_no_pager = false;
static bool arg_legend = true;
@ -1786,9 +1785,7 @@ static int parse_argv(int argc, char *argv[]) {
return help();
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;

View file

@ -498,16 +498,11 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
}
_public_ int sd_booted(void) {
struct stat st;
/* We test whether the runtime unit file directory has been
* created. This takes place in mount-setup.c, so is
* guaranteed to happen very early during boot. */
if (lstat("/run/systemd/system/", &st) < 0)
return 0;
return !!S_ISDIR(st.st_mode);
return laccess("/run/systemd/system/", F_OK) >= 0;
}
_public_ int sd_watchdog_enabled(int unset_environment, uint64_t *usec) {

View file

@ -19,6 +19,7 @@
#pragma once
#include "sparse-endian.h"
#include "util.h"
#define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' }

View file

@ -20,26 +20,26 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <locale.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <string.h>
#include <ftw.h>
#include <getopt.h>
#include <locale.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "util.h"
#include "spawn-polkit-agent.h"
#include "build.h"
#include "strv.h"
#include "pager.h"
#include "set.h"
#include "bus-util.h"
#include "def.h"
#include "virt.h"
#include "fileio.h"
#include "locale-util.h"
#include "pager.h"
#include "set.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
#include "util.h"
#include "virt.h"
static bool arg_no_pager = false;
static bool arg_ask_password = true;
@ -546,9 +546,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_CONVERT:
arg_convert = false;
@ -678,7 +676,7 @@ int main(int argc, char*argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -19,21 +19,21 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "util.h"
#include "build.h"
#include "strv.h"
#include "bus-util.h"
#include "formats-util.h"
#include "process-util.h"
#include "signal-util.h"
#include "strv.h"
#include "util.h"
static const char* arg_what = "idle:sleep:shutdown";
static const char* arg_who = NULL;
@ -179,9 +179,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_WHAT:
arg_what = optarg;

View file

@ -19,31 +19,31 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include <locale.h>
#include <string.h>
#include <unistd.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "log.h"
#include "util.h"
#include "macro.h"
#include "pager.h"
#include "build.h"
#include "strv.h"
#include "unit-name.h"
#include "sysfs-show.h"
#include "logs-show.h"
#include "bus-util.h"
#include "cgroup-show.h"
#include "cgroup-util.h"
#include "spawn-polkit-agent.h"
#include "verbs.h"
#include "log.h"
#include "logs-show.h"
#include "macro.h"
#include "pager.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
#include "sysfs-show.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
#include "verbs.h"
static char **arg_property = NULL;
static bool arg_all = false;
@ -1416,9 +1416,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'p': {
r = strv_extend(&arg_property, optarg);
@ -1544,7 +1542,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -1 +0,0 @@
../Makefile

View file

@ -1,107 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Didier Roche
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <errno.h>
#include "machine-id-setup.h"
#include "log.h"
#include "build.h"
static const char *arg_root = NULL;
static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Commit a transient /etc/machine-id on disk if writable.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --root=ROOT Filesystem root\n",
program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_ROOT,
};
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "root", required_argument, NULL, ARG_ROOT },
{}
};
int c;
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0)
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
case ARG_ROOT:
arg_root = optarg;
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
if (optind < argc) {
log_error("Extraneous arguments");
return -EINVAL;
}
return 1;
}
int main(int argc, char *argv[]) {
int r;
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
if (r <= 0)
goto finish;
r = machine_id_commit(arg_root);
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

View file

@ -19,24 +19,26 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "machine-id-setup.h"
#include "log.h"
#include "build.h"
#include "machine-id-setup.h"
#include "util.h"
static const char *arg_root = "";
static const char *arg_root = NULL;
static bool arg_commit = false;
static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Initialize /etc/machine-id from a random source.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --root=ROOT Filesystem root\n",
program_invocation_short_name);
" --root=ROOT Filesystem root\n"
" --commit Commit transient ID\n"
, program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@ -44,12 +46,14 @@ static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_ROOT,
ARG_COMMIT,
};
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "root", required_argument, NULL, ARG_ROOT },
{ "commit", no_argument, NULL, ARG_COMMIT },
{}
};
@ -67,14 +71,16 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_ROOT:
arg_root = optarg;
break;
case ARG_COMMIT:
arg_commit = true;
break;
case '?':
return -EINVAL;
@ -100,5 +106,11 @@ int main(int argc, char *argv[]) {
if (r <= 0)
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
return machine_id_setup(arg_root) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
if (arg_commit)
r = machine_id_commit(arg_root);
else
r = machine_id_setup(arg_root);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

View file

@ -735,7 +735,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
description = strjoina("Shell for User ", isempty(user) ? "root" : user);
r = sd_bus_message_append(tm,
"(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)",
"(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)(sv)",
"Description", "s", description,
"StandardInput", "s", "tty",
"StandardOutput", "s", "tty",
@ -748,7 +748,8 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
"TTYReset", "b", true,
"UtmpIdentifier", "s", utmp_id,
"UtmpMode", "s", "user",
"PAMName", "s", "login");
"PAMName", "s", "login",
"WorkingDirectory", "s", "-~");
if (r < 0)
return r;

View file

@ -19,44 +19,44 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <getopt.h>
#include <locale.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <unistd.h>
#include "sd-bus.h"
#include "log.h"
#include "util.h"
#include "macro.h"
#include "pager.h"
#include "spawn-polkit-agent.h"
#include "bus-util.h"
#include "bus-error.h"
#include "build.h"
#include "strv.h"
#include "unit-name.h"
#include "bus-util.h"
#include "cgroup-show.h"
#include "logs-show.h"
#include "cgroup-util.h"
#include "ptyfwd.h"
#include "event-util.h"
#include "path-util.h"
#include "mkdir.h"
#include "copy.h"
#include "verbs.h"
#include "import-util.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "env-util.h"
#include "event-util.h"
#include "hostname-util.h"
#include "import-util.h"
#include "log.h"
#include "logs-show.h"
#include "macro.h"
#include "mkdir.h"
#include "pager.h"
#include "path-util.h"
#include "process-util.h"
#include "ptyfwd.h"
#include "signal-util.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
#include "terminal-util.h"
#include "unit-name.h"
#include "util.h"
#include "verbs.h"
static char **arg_property = NULL;
static bool arg_all = false;
@ -2554,9 +2554,7 @@ static int parse_argv(int argc, char *argv[]) {
return help(0, NULL, NULL);
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'p':
r = strv_extend(&arg_property, optarg);
@ -2747,7 +2745,7 @@ int main(int argc, char*argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -20,17 +20,16 @@
***/
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <limits.h>
#include <getopt.h>
#include <libkmod.h>
#include "log.h"
#include "util.h"
#include "strv.h"
#include "conf-files.h"
#include "build.h"
#include "log.h"
#include "strv.h"
#include "util.h"
static char **arg_proc_cmdline_modules = NULL;
@ -199,9 +198,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case '?':
return -EINVAL;

View file

@ -19,29 +19,28 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include <getopt.h>
#include <net/if.h>
#include <stdbool.h>
#include "sd-network.h"
#include "sd-netlink.h"
#include "sd-hwdb.h"
#include "sd-device.h"
#include "sd-hwdb.h"
#include "sd-netlink.h"
#include "sd-network.h"
#include "strv.h"
#include "build.h"
#include "util.h"
#include "pager.h"
#include "lldp.h"
#include "netlink-util.h"
#include "device-util.h"
#include "hwdb-util.h"
#include "arphrd-list.h"
#include "local-addresses.h"
#include "socket-util.h"
#include "device-util.h"
#include "ether-addr-util.h"
#include "verbs.h"
#include "hwdb-util.h"
#include "lldp.h"
#include "local-addresses.h"
#include "netlink-util.h"
#include "pager.h"
#include "socket-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
#include "verbs.h"
static bool arg_no_pager = false;
static bool arg_legend = true;
@ -1063,9 +1062,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_NO_PAGER:
arg_no_pager = true;

View file

@ -21,10 +21,10 @@
#include <getopt.h>
#include "sd-daemon.h"
#include "strv.h"
#include "build.h"
#include "signal-util.h"
#include "networkd-wait-online.h"
#include "signal-util.h"
#include "strv.h"
static bool arg_quiet = false;
static usec_t arg_timeout = 120 * USEC_PER_SEC;
@ -79,9 +79,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'i':
if (strv_extend(&arg_interfaces, optarg) < 0)

View file

@ -27,7 +27,6 @@
#include "sd-daemon.h"
#include "build.h"
#include "env-util.h"
#include "formats-util.h"
#include "log.h"
@ -85,9 +84,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_READY:
arg_ready = true;

View file

@ -194,7 +194,7 @@ int expose_port_send_rtnl(int send_fd) {
/* Store away the fd in the socket, so that it stays open as
* long as we run the child */
r = send_one_fd(send_fd, fd);
r = send_one_fd(send_fd, fd, 0);
if (r < 0)
return log_error_errno(r, "Failed to send netlink fd: %m");
@ -214,7 +214,7 @@ int expose_port_watch_rtnl(
assert(recv_fd >= 0);
assert(ret);
fd = receive_one_fd(recv_fd);
fd = receive_one_fd(recv_fd, 0);
if (fd < 0)
return log_error_errno(fd, "Failed to recv netlink fd: %m");

View file

@ -50,7 +50,6 @@
#include "base-filesystem.h"
#include "blkid-util.h"
#include "btrfs-util.h"
#include "build.h"
#include "cap-list.h"
#include "capability.h"
#include "cgroup-util.h"
@ -414,9 +413,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'D':
r = set_sanitized_path(&arg_directory, optarg);
@ -1291,7 +1288,7 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
/* Store away the fd in the socket, so that it stays open as
* long as we run the child */
r = send_one_fd(kmsg_socket, fd);
r = send_one_fd(kmsg_socket, fd, 0);
safe_close(fd);
if (r < 0)
@ -2282,8 +2279,6 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
return r;
}
static void nop_handler(int sig) {}
static int on_orderly_shutdown(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
pid_t pid;
@ -3241,7 +3236,7 @@ int main(int argc, char *argv[]) {
ContainerStatus container_status;
_cleanup_(barrier_destroy) Barrier barrier = BARRIER_NULL;
static const struct sigaction sa = {
.sa_handler = nop_handler,
.sa_handler = nop_signal_handler,
.sa_flags = SA_NOCLDSTOP,
};
int ifi = 0;
@ -3338,8 +3333,7 @@ int main(int argc, char *argv[]) {
barrier_set_role(&barrier, BARRIER_PARENT);
fdset_free(fds);
fds = NULL;
fds = fdset_free(fds);
kmsg_socket_pair[1] = safe_close(kmsg_socket_pair[1]);
rtnl_socket_pair[1] = safe_close(rtnl_socket_pair[1]);

View file

@ -19,16 +19,16 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <getopt.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "sd-path.h"
#include "build.h"
#include "log.h"
#include "macro.h"
#include "util.h"
#include "log.h"
static const char *arg_suffix = NULL;
@ -155,9 +155,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_SUFFIX:
arg_suffix = optarg;

View file

@ -23,14 +23,13 @@
#include <getopt.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "in-addr-util.h"
#include "af-list.h"
#include "build.h"
#include "resolved-dns-packet.h"
#include "af-list.h"
#include "bus-error.h"
#include "bus-util.h"
#include "in-addr-util.h"
#include "resolved-def.h"
#include "resolved-dns-packet.h"
#define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
@ -507,9 +506,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0; /* done */;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0 /* done */;
return version();
case '4':
arg_family = AF_INET;

View file

@ -19,24 +19,24 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <getopt.h>
#include <stdio.h>
#include "sd-bus.h"
#include "sd-event.h"
#include "bus-util.h"
#include "event-util.h"
#include "strv.h"
#include "build.h"
#include "unit-name.h"
#include "env-util.h"
#include "path-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "calendarspec.h"
#include "ptyfwd.h"
#include "env-util.h"
#include "event-util.h"
#include "formats-util.h"
#include "path-util.h"
#include "ptyfwd.h"
#include "signal-util.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
#include "unit-name.h"
static bool arg_ask_password = true;
static bool arg_scope = false;
@ -199,9 +199,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_USER:
arg_user = true;
@ -1176,7 +1174,7 @@ int main(int argc, char* argv[]) {
arg_description = description;
}
r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus);
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -21,6 +21,9 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include "time-util.h"
int ask_password_tty(const char *message, usec_t until, bool echo, const char *flag_file, char **_passphrase);

View file

@ -574,14 +574,14 @@ int bus_check_peercred(sd_bus *c) {
return 1;
}
int bus_open_system_systemd(sd_bus **_bus) {
int bus_connect_system_systemd(sd_bus **_bus) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
int r;
assert(_bus);
if (geteuid() != 0)
return sd_bus_open_system(_bus);
return sd_bus_default_system(_bus);
/* If we are root and kdbus is not available, then let's talk
* directly to the system instance, instead of going via the
@ -616,7 +616,7 @@ int bus_open_system_systemd(sd_bus **_bus) {
r = sd_bus_start(bus);
if (r < 0)
return sd_bus_open_system(_bus);
return sd_bus_default_system(_bus);
r = bus_check_peercred(bus);
if (r < 0)
@ -628,7 +628,7 @@ int bus_open_system_systemd(sd_bus **_bus) {
return 0;
}
int bus_open_user_systemd(sd_bus **_bus) {
int bus_connect_user_systemd(sd_bus **_bus) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *ee = NULL;
const char *e;
@ -658,7 +658,7 @@ int bus_open_user_systemd(sd_bus **_bus) {
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e)
return sd_bus_open_user(_bus);
return sd_bus_default_user(_bus);
ee = bus_address_escape(e);
if (!ee)
@ -674,7 +674,7 @@ int bus_open_user_systemd(sd_bus **_bus) {
r = sd_bus_start(bus);
if (r < 0)
return sd_bus_open_user(_bus);
return sd_bus_default_user(_bus);
r = bus_check_peercred(bus);
if (r < 0)
@ -1209,7 +1209,7 @@ int bus_map_all_properties(
return bus_message_map_all_properties(m, map, userdata);
}
int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int r;
assert(transport >= 0);
@ -1244,7 +1244,7 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b
return r;
}
int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int r;
assert(transport >= 0);
@ -1258,9 +1258,9 @@ int bus_open_transport_systemd(BusTransport transport, const char *host, bool us
case BUS_TRANSPORT_LOCAL:
if (user)
r = bus_open_user_systemd(bus);
r = bus_connect_user_systemd(bus);
else
r = bus_open_system_systemd(bus);
r = bus_connect_system_systemd(bus);
break;

View file

@ -65,11 +65,11 @@ int bus_test_polkit(sd_bus_message *call, int capability, const char *action, co
int bus_verify_polkit_async(sd_bus_message *call, int capability, const char *action, const char **details, bool interactive, uid_t good_user, Hashmap **registry, sd_bus_error *error);
void bus_verify_polkit_async_registry_free(Hashmap *registry);
int bus_open_system_systemd(sd_bus **_bus);
int bus_open_user_systemd(sd_bus **_bus);
int bus_connect_system_systemd(sd_bus **_bus);
int bus_connect_user_systemd(sd_bus **_bus);
int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_print_property(const char *name, sd_bus_message *property, bool all);
int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);

View file

@ -48,24 +48,27 @@ noreturn static void pager_fallback(void) {
}
int pager_open(bool jump_to_end) {
int fd[2];
_cleanup_close_pair_ int fd[2] = { -1, -1 };
const char *pager;
pid_t parent_pid;
int r;
if (pager_pid > 0)
return 1;
if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
if (!*pager || streq(pager, "cat"))
return 0;
if (!on_tty())
return 0;
pager = getenv("SYSTEMD_PAGER");
if (!pager)
pager = getenv("PAGER");
/* If the pager is explicitly turned off, honour it */
if (pager && (pager[0] == 0 || streq(pager, "cat")))
return 0;
/* Determine and cache number of columns before we spawn the
* pager so that we get the value from the actual tty */
columns();
(void) columns();
if (pipe(fd) < 0)
return log_error_errno(errno, "Failed to create pager pipe: %m");
@ -73,11 +76,8 @@ int pager_open(bool jump_to_end) {
parent_pid = getpid();
pager_pid = fork();
if (pager_pid < 0) {
r = log_error_errno(errno, "Failed to fork pager: %m");
safe_close_pair(fd);
return r;
}
if (pager_pid < 0)
return log_error_errno(errno, "Failed to fork pager: %m");
/* In the child start the pager */
if (pager_pid == 0) {
@ -86,7 +86,7 @@ int pager_open(bool jump_to_end) {
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
dup2(fd[0], STDIN_FILENO);
(void) dup2(fd[0], STDIN_FILENO);
safe_close_pair(fd);
/* Initialize a good set of less options */
@ -141,7 +141,6 @@ int pager_open(bool jump_to_end) {
if (dup2(fd[1], STDERR_FILENO) < 0)
return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
safe_close_pair(fd);
return 1;
}

View file

@ -19,18 +19,17 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fileio.h"
#include "log.h"
#include "util.h"
#include "fileio.h"
#include "build.h"
#include "sysctl-util.h"
char *sysctl_normalize(char *s) {

View file

@ -20,18 +20,18 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include "sd-messages.h"
#include "log.h"
#include "util.h"
#include "strv.h"
#include "fileio.h"
#include "build.h"
#include "sleep-config.h"
#include "def.h"
#include "fileio.h"
#include "log.h"
#include "sleep-config.h"
#include "strv.h"
#include "util.h"
static char* arg_verb = NULL;
@ -165,9 +165,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0; /* done */
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0 /* done */;
return version();
case '?':
return -EINVAL;

View file

@ -20,12 +20,12 @@
***/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
@ -33,12 +33,12 @@
#include "sd-daemon.h"
#include "sd-event.h"
#include "sd-resolve.h"
#include "log.h"
#include "path-util.h"
#include "set.h"
#include "socket-util.h"
#include "util.h"
#include "build.h"
#include "set.h"
#include "path-util.h"
#define BUFFER_SIZE (256 * 1024)
#define CONNECTIONS_MAX 256
@ -603,9 +603,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case '?':
return -EINVAL;

View file

@ -19,23 +19,22 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
#include "strv.h"
#include "util.h"
#include "hashmap.h"
#include "path-util.h"
#include "conf-files.h"
#include "fileio.h"
#include "build.h"
#include "hashmap.h"
#include "log.h"
#include "path-util.h"
#include "strv.h"
#include "sysctl-util.h"
#include "util.h"
static char **arg_prefixes = NULL;
@ -195,9 +194,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_PREFIX: {
char *p;

File diff suppressed because it is too large Load diff

View file

@ -19,26 +19,25 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <pwd.h>
#include <grp.h>
#include <shadow.h>
#include <gshadow.h>
#include <getopt.h>
#include <grp.h>
#include <gshadow.h>
#include <pwd.h>
#include <shadow.h>
#include <utmp.h>
#include "util.h"
#include "hashmap.h"
#include "specifier.h"
#include "path-util.h"
#include "build.h"
#include "strv.h"
#include "conf-files.h"
#include "copy.h"
#include "utf8.h"
#include "fileio-label.h"
#include "uid-range.h"
#include "selinux-util.h"
#include "formats-util.h"
#include "hashmap.h"
#include "path-util.h"
#include "selinux-util.h"
#include "specifier.h"
#include "strv.h"
#include "uid-range.h"
#include "utf8.h"
#include "util.h"
typedef enum ItemType {
ADD_USER = 'u',
@ -1767,9 +1766,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_ROOT:
free(arg_root);

View file

@ -569,6 +569,28 @@ static void test_strv_shell_escape(void) {
assert_se(streq_ptr(v[3], NULL));
}
static void test_strv_skip_one(char **a, size_t n, char **b) {
a = strv_skip(a, n);
assert_se(strv_equal(a, b));
}
static void test_strv_skip(void) {
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 0, STRV_MAKE("foo", "bar", "baz"));
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 1, STRV_MAKE("bar", "baz"));
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 2, STRV_MAKE("baz"));
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 3, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 4, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE("foo", "bar", "baz"), 55, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE("quux"), 0, STRV_MAKE("quux"));
test_strv_skip_one(STRV_MAKE("quux"), 1, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE("quux"), 55, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE(NULL), 0, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE(NULL), 1, STRV_MAKE(NULL));
test_strv_skip_one(STRV_MAKE(NULL), 55, STRV_MAKE(NULL));
}
int main(int argc, char *argv[]) {
test_specifier_printf();
test_strv_foreach();
@ -627,6 +649,7 @@ int main(int argc, char *argv[]) {
test_strv_is_uniq();
test_strv_reverse();
test_strv_shell_escape();
test_strv_skip();
return 0;
}

View file

@ -20,20 +20,20 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <locale.h>
#include <stdbool.h>
#include <stdlib.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "util.h"
#include "spawn-polkit-agent.h"
#include "build.h"
#include "strv.h"
#include "bus-util.h"
#include "pager.h"
#include "spawn-polkit-agent.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
static bool arg_no_pager = false;
static bool arg_ask_password = true;
@ -374,9 +374,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case 'H':
arg_transport = BUS_TRANSPORT_REMOTE;
@ -502,7 +500,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View file

@ -20,43 +20,42 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <getopt.h>
#include <glob.h>
#include <limits.h>
#include <linux/fs.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <getopt.h>
#include <stdbool.h>
#include <time.h>
#include <glob.h>
#include <fnmatch.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/xattr.h>
#include <linux/fs.h>
#include <time.h>
#include <unistd.h>
#include "acl-util.h"
#include "btrfs-util.h"
#include "capability.h"
#include "conf-files.h"
#include "copy.h"
#include "formats-util.h"
#include "label.h"
#include "log.h"
#include "util.h"
#include "macro.h"
#include "missing.h"
#include "mkdir.h"
#include "path-util.h"
#include "strv.h"
#include "label.h"
#include "set.h"
#include "conf-files.h"
#include "capability.h"
#include "specifier.h"
#include "build.h"
#include "copy.h"
#include "rm-rf.h"
#include "selinux-util.h"
#include "btrfs-util.h"
#include "acl-util.h"
#include "formats-util.h"
#include "set.h"
#include "specifier.h"
#include "strv.h"
#include "util.h"
/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
* them in the file system. This is intended to be used to create
@ -2090,9 +2089,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_CREATE:
arg_create = true;

View file

@ -19,32 +19,31 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <poll.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <sys/inotify.h>
#include <sys/signalfd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stddef.h>
#include <poll.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/signalfd.h>
#include <fcntl.h>
#include "util.h"
#include "ask-password-api.h"
#include "conf-parser.h"
#include "def.h"
#include "mkdir.h"
#include "path-util.h"
#include "conf-parser.h"
#include "utmp-wtmp.h"
#include "socket-util.h"
#include "ask-password-api.h"
#include "strv.h"
#include "build.h"
#include "def.h"
#include "process-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "socket-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
#include "utmp-wtmp.h"
static enum {
ACTION_LIST,
@ -571,9 +570,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
return version();
case ARG_LIST:
arg_action = ACTION_LIST;
@ -628,15 +625,14 @@ int main(int argc, char *argv[]) {
goto finish;
if (arg_console) {
setsid();
release_terminal();
(void) setsid();
(void) release_terminal();
}
if (IN_SET(arg_action, ACTION_WATCH, ACTION_WALL))
r = watch_passwords();
else
r = show_passwords();
if (r < 0)
log_error_errno(r, "Error: %m");

View file

@ -62,7 +62,7 @@ static usec_t get_startup_time(Context *c) {
&error,
't', &t);
if (r < 0) {
log_error("Failed to get timestamp: %s", bus_error_message(&error, -r));
log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r));
return 0;
}
@ -105,10 +105,8 @@ static int get_current_runlevel(Context *c) {
"ActiveState",
&error,
&state);
if (r < 0) {
log_warning("Failed to get state: %s", bus_error_message(&error, -r));
return r;
}
if (r < 0)
return log_warning_errno(r, "Failed to get state: %s", bus_error_message(&error, r));
if (streq(state, "active") || streq(state, "reloading"))
return table[i].runlevel;
@ -130,8 +128,7 @@ static int on_reboot(Context *c) {
if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) {
r = log_error_errno(errno,
"Failed to send audit message: %m");
r = log_error_errno(errno, "Failed to send audit message: %m");
}
#endif
@ -160,8 +157,7 @@ static int on_shutdown(Context *c) {
if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) {
r = log_error_errno(errno,
"Failed to send audit message: %m");
r = log_error_errno(errno, "Failed to send audit message: %m");
}
#endif
@ -211,8 +207,7 @@ static int on_runlevel(Context *c) {
return log_oom();
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM)
r = log_error_errno(errno,
"Failed to send audit message: %m");
r = log_error_errno(errno, "Failed to send audit message: %m");
}
#endif
@ -256,7 +251,7 @@ int main(int argc, char *argv[]) {
if (c.audit_fd < 0 && errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
log_error_errno(errno, "Failed to connect to audit log: %m");
#endif
r = bus_open_system_systemd(&c.bus);
r = bus_connect_system_systemd(&c.bus);
if (r < 0) {
log_error_errno(r, "Failed to get D-Bus connection: %m");
r = -EIO;
@ -284,6 +279,6 @@ finish:
audit_close(c.audit_fd);
#endif
sd_bus_unref(c.bus);
sd_bus_flush_close_unref(c.bus);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

View file

@ -14,7 +14,7 @@ Documentation=http://www.freedesktop.org/wiki/Software/systemd/hostnamed
ExecStart=@rootlibexecdir@/systemd-hostnamed
BusName=org.freedesktop.hostname1
CapabilityBoundingSet=CAP_SYS_ADMIN
WatchdogSec=1min
WatchdogSec=3min
PrivateTmp=yes
PrivateDevices=yes
PrivateNetwork=yes

Some files were not shown because too many files have changed in this diff Show more