1
0
mirror of https://github.com/systemd/systemd synced 2026-04-04 06:04:51 +02:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Scott Lamb
4b499063ac fsck: no emergency.target on nofail mounts
Also describe failure behavior more precisely in the manpage.
Fixes #20237.
2021-11-10 11:58:12 +01:00
Anita Zhang
899acf5c2d core: replace slice dependencies as they get added
Defines a "UNIT_DEPENDENCY_SLICE_PROPERTY" UnitDependencyMask type that
is used when adding slices to the dependencies hashmap. This type is
used to remove slice dependencies when they get overridden by new ones.

Fixes #20182
2021-11-10 10:52:08 +01:00
Zbigniew Jędrzejewski-Szmek
4d544a0c87
Merge pull request #21287 from yuwata/man-network-condition
man: cleanups for [Match] section
2021-11-10 10:36:54 +01:00
Yu Watanabe
4883a5ec6c network: cake: fix copy-and-paste error
Follow-up for 35896db4895f68050c3edd2c58b913dcba4e0fd8.

Fixes CID#1465796.
2021-11-10 10:35:36 +01:00
Yu Watanabe
8c66ab20f6 man: use include directive for [Match] section 2021-11-10 10:59:21 +09:00
Yu Watanabe
33132db903 man: add missing Firmware= setting 2021-11-10 10:56:42 +09:00
12 changed files with 73 additions and 88 deletions

View File

@ -55,9 +55,18 @@
the filesystem should actually be checked based on the time since the filesystem should actually be checked based on the time since
last check, number of mounts, unclean unmount, etc.</para> last check, number of mounts, unclean unmount, etc.</para>
<para>If a file system check fails for a service without <para><filename>systemd-fsck-root.service</filename> will activate
<option>nofail</option>, emergency mode is activated, by isolating <filename>reboot.target</filename> if <filename>/sbin/fsck</filename>
to <filename>emergency.target</filename>.</para> returns the "System should reboot" condition, or
<filename>emergency.target</filename> if <filename>/sbin/fsck</filename>
returns the "Filesystem errors left uncorrected" condition.</para>
<para><filename>systemd-fsck@.service</filename> will fail if
<filename>/sbin/fsck</filename> returns with either "System should reboot"
or "Filesystem errors left uncorrected" conditions. For filesystems
listed in <filename>/etc/fstab</filename> without <literal>nofail</literal>
or <literal>noauto</literal> options, <literal>local-fs.target</literal>
will then activate <filename>emergency.target</filename>.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>

View File

@ -3,7 +3,8 @@
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="systemd.netdev" conditional='ENABLE_NETWORKD'> <refentry id="systemd.netdev" conditional='ENABLE_NETWORKD'
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo> <refentryinfo>
<title>systemd.network</title> <title>systemd.network</title>
@ -197,78 +198,16 @@
<refsect1> <refsect1>
<title>[Match] Section Options</title> <title>[Match] Section Options</title>
<para>A virtual network device is only created if the <para>A virtual network device is only created if the [Match] section matches the current
[Match] section matches the current environment, or if the section is empty. The following keys are accepted:</para>
environment, or if the section is empty. The following keys are
accepted:</para>
<variablelist class='network-directives'> <variablelist class='network-directives'>
<varlistentry> <xi:include href="systemd.link.xml" xpointer="host" />
<term><varname>Host=</varname></term> <xi:include href="systemd.link.xml" xpointer="virtualization" />
<listitem> <xi:include href="systemd.link.xml" xpointer="kernel-command-line" />
<para>Matches against the hostname or machine ID of the host. See <xi:include href="systemd.link.xml" xpointer="kernel-version" />
<literal>ConditionHost=</literal> in <xi:include href="systemd.link.xml" xpointer="architecture" />
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> <xi:include href="systemd.link.xml" xpointer="firmware" />
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Virtualization=</varname></term>
<listitem>
<para>Checks whether the system is executed in a virtualized environment and optionally test
whether it is a specific implementation. See <literal>ConditionVirtualization=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>KernelCommandLine=</varname></term>
<listitem>
<para>Checks whether a specific kernel command line option is set. See
<literal>ConditionKernelCommandLine=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>KernelVersion=</varname></term>
<listitem>
<para>Checks whether the kernel version (as reported by <command>uname -r</command>) matches a
certain expression. See <literal>ConditionKernelVersion=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Architecture=</varname></term>
<listitem>
<para>Checks whether the system is running on a specific architecture. See
<literal>ConditionArchitecture=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Firmware=</varname></term>
<listitem>
<para>Checks whether the system is running on a machine with the specified firmware. See
<literal>ConditionFirmware=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -132,6 +132,7 @@
<xi:include href="systemd.link.xml" xpointer="kernel-command-line" /> <xi:include href="systemd.link.xml" xpointer="kernel-command-line" />
<xi:include href="systemd.link.xml" xpointer="kernel-version" /> <xi:include href="systemd.link.xml" xpointer="kernel-version" />
<xi:include href="systemd.link.xml" xpointer="architecture" /> <xi:include href="systemd.link.xml" xpointer="architecture" />
<xi:include href="systemd.link.xml" xpointer="firmware" />
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -2273,7 +2273,7 @@ static int bus_unit_set_transient_property(
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit name '%s' is not a slice", s); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit name '%s' is not a slice", s);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE); r = unit_set_slice(u, slice);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -3793,7 +3793,7 @@ int config_parse_unit_slice(
return 0; return 0;
} }
r = unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE); r = unit_set_slice(u, slice);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id);
return 0; return 0;

View File

@ -593,6 +593,7 @@ static void print_unit_dependency_mask(FILE *f, const char *kind, UnitDependency
{ UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT, "mountinfo-implicit" }, { UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT, "mountinfo-implicit" },
{ UNIT_DEPENDENCY_MOUNTINFO_DEFAULT, "mountinfo-default" }, { UNIT_DEPENDENCY_MOUNTINFO_DEFAULT, "mountinfo-default" },
{ UNIT_DEPENDENCY_PROC_SWAP, "proc-swap" }, { UNIT_DEPENDENCY_PROC_SWAP, "proc-swap" },
{ UNIT_DEPENDENCY_SLICE_PROPERTY, "slice-property" },
}; };
assert(f); assert(f);

View File

@ -3285,7 +3285,7 @@ reset:
return r; return r;
} }
int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask) { int unit_set_slice(Unit *u, Unit *slice) {
int r; int r;
assert(u); assert(u);
@ -3318,7 +3318,11 @@ int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask) {
if (UNIT_GET_SLICE(u) && u->cgroup_realized) if (UNIT_GET_SLICE(u) && u->cgroup_realized)
return -EBUSY; return -EBUSY;
r = unit_add_dependency(u, UNIT_IN_SLICE, slice, true, mask); /* Remove any slices assigned prior; we should only have one UNIT_IN_SLICE dependency */
if (UNIT_GET_SLICE(u))
unit_remove_dependencies(u, UNIT_DEPENDENCY_SLICE_PROPERTY);
r = unit_add_dependency(u, UNIT_IN_SLICE, slice, true, UNIT_DEPENDENCY_SLICE_PROPERTY);
if (r < 0) if (r < 0)
return r; return r;
@ -3374,7 +3378,7 @@ int unit_set_default_slice(Unit *u) {
if (r < 0) if (r < 0)
return r; return r;
return unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE); return unit_set_slice(u, slice);
} }
const char *unit_slice_name(Unit *u) { const char *unit_slice_name(Unit *u) {

View File

@ -89,7 +89,10 @@ typedef enum UnitDependencyMask {
/* A dependency created because of data read from /proc/swaps and no other configuration source */ /* A dependency created because of data read from /proc/swaps and no other configuration source */
UNIT_DEPENDENCY_PROC_SWAP = 1 << 7, UNIT_DEPENDENCY_PROC_SWAP = 1 << 7,
_UNIT_DEPENDENCY_MASK_FULL = (1 << 8) - 1, /* A dependency for units in slices assigned by directly setting Slice= */
UNIT_DEPENDENCY_SLICE_PROPERTY = 1 << 8,
_UNIT_DEPENDENCY_MASK_FULL = (1 << 9) - 1,
} UnitDependencyMask; } UnitDependencyMask;
/* The Unit's dependencies[] hashmaps use this structure as value. It has the same size as a void pointer, and thus can /* The Unit's dependencies[] hashmaps use this structure as value. It has the same size as a void pointer, and thus can
@ -782,7 +785,7 @@ Unit *unit_follow_merge(Unit *u) _pure_;
int unit_load_fragment_and_dropin(Unit *u, bool fragment_required); int unit_load_fragment_and_dropin(Unit *u, bool fragment_required);
int unit_load(Unit *unit); int unit_load(Unit *unit);
int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask); int unit_set_slice(Unit *u, Unit *slice);
int unit_set_default_slice(Unit *u); int unit_set_default_slice(Unit *u);
const char *unit_description(Unit *u) _pure_; const char *unit_description(Unit *u) _pure_;

View File

@ -52,7 +52,7 @@ static void start_target(const char *target, const char *mode) {
return; return;
} }
log_info("Running request %s/start/replace", target); log_info("Running request %s/start/%s", target, mode);
/* Start these units only if we can replace base.target with it */ /* Start these units only if we can replace base.target with it */
r = sd_bus_call_method(bus, r = sd_bus_call_method(bus,
@ -412,10 +412,7 @@ static int run(int argc, char *argv[]) {
/* System should be rebooted. */ /* System should be rebooted. */
start_target(SPECIAL_REBOOT_TARGET, "replace-irreversibly"); start_target(SPECIAL_REBOOT_TARGET, "replace-irreversibly");
return -EINVAL; return -EINVAL;
} else if (exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED)) } else if (!(exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED)))
/* Some other problem */
start_target(SPECIAL_EMERGENCY_TARGET, "replace");
else
log_warning("Ignoring error."); log_warning("Ignoring error.");
} }

View File

@ -113,7 +113,7 @@ static int cake_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req)
} }
if (c->split_gso >= 0) { if (c->split_gso >= 0) {
r = sd_netlink_message_append_u32(req, TCA_CAKE_SPLIT_GSO, c->wash); r = sd_netlink_message_append_u32(req, TCA_CAKE_SPLIT_GSO, c->split_gso);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Could not append TCA_CAKE_SPLIT_GSO attribute: %m"); return log_link_error_errno(link, r, "Could not append TCA_CAKE_SPLIT_GSO attribute: %m");
} }

View File

@ -8,6 +8,7 @@
#include "manager-dump.h" #include "manager-dump.h"
#include "rm-rf.h" #include "rm-rf.h"
#include "service.h" #include "service.h"
#include "slice.h"
#include "special.h" #include "special.h"
#include "strv.h" #include "strv.h"
#include "tests.h" #include "tests.h"
@ -75,7 +76,8 @@ int main(int argc, char *argv[]) {
_cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
_cleanup_(manager_freep) Manager *m = NULL; _cleanup_(manager_freep) Manager *m = NULL;
Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL,
*h = NULL, *i = NULL, *a_conj = NULL, *unit_with_multiple_dashes = NULL, *stub = NULL; *h = NULL, *i = NULL, *a_conj = NULL, *unit_with_multiple_dashes = NULL, *stub = NULL,
*tomato = NULL, *sauce = NULL, *fruit = NULL, *zupa = NULL;
Job *j; Job *j;
int r; int r;
@ -260,5 +262,32 @@ int main(int argc, char *argv[]) {
verify_dependency_atoms(); verify_dependency_atoms();
/* Test adding multiple Slice= dependencies; only the last should remain */
assert_se(unit_new_for_name(m, sizeof(Service), "tomato.service", &tomato) >= 0);
assert_se(unit_new_for_name(m, sizeof(Slice), "sauce.slice", &sauce) >= 0);
assert_se(unit_new_for_name(m, sizeof(Slice), "fruit.slice", &fruit) >= 0);
assert_se(unit_new_for_name(m, sizeof(Slice), "zupa.slice", &zupa) >= 0);
unit_set_slice(tomato, sauce);
unit_set_slice(tomato, fruit);
unit_set_slice(tomato, zupa);
assert_se(UNIT_GET_SLICE(tomato) == zupa);
assert_se(!unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, sauce));
assert_se(!unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, fruit));
assert_se(unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, zupa));
assert_se(!unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, sauce));
assert_se(!unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, fruit));
assert_se(unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, zupa));
assert_se(!unit_has_dependency(sauce, UNIT_ATOM_SLICE_OF, tomato));
assert_se(!unit_has_dependency(fruit, UNIT_ATOM_SLICE_OF, tomato));
assert_se(unit_has_dependency(zupa, UNIT_ATOM_SLICE_OF, tomato));
assert_se(!unit_has_dependency(sauce, UNIT_ATOM_REFERENCED_BY, tomato));
assert_se(!unit_has_dependency(fruit, UNIT_ATOM_REFERENCED_BY, tomato));
assert_se(unit_has_dependency(zupa, UNIT_ATOM_REFERENCED_BY, tomato));
return 0; return 0;
} }

View File

@ -14,6 +14,8 @@ DefaultDependencies=no
Conflicts=shutdown.target Conflicts=shutdown.target
Before=local-fs.target shutdown.target Before=local-fs.target shutdown.target
ConditionPathIsReadWrite=!/ ConditionPathIsReadWrite=!/
OnFailure=emergency.target
OnFailureJobMode=replace-irreversibly
[Service] [Service]
Type=oneshot Type=oneshot