Skip to content

Commit 03abeb0

Browse files
authored
Merge pull request #12267 from keszybz/udev-settle-warning
Udev settle warning
2 parents 01234e1 + 1662732 commit 03abeb0

File tree

5 files changed

+121
-2
lines changed

5 files changed

+121
-2
lines changed

man/rules/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ manpages = [
775775
'systemd-tmpfiles-setup.service'],
776776
''],
777777
['systemd-tty-ask-password-agent', '1', [], ''],
778+
['systemd-udev-settle.service', '8', [], ''],
778779
['systemd-udevd.service',
779780
'8',
780781
['systemd-udevd',

man/systemd-udev-settle.service.xml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version='1.0'?>
2+
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3+
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4+
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
5+
6+
<refentry id="systemd-udev-settle.service"
7+
xmlns:xi="http://www.w3.org/2001/XInclude">
8+
9+
<refentryinfo>
10+
<title>systemd-udev-settle.service</title>
11+
<productname>systemd</productname>
12+
</refentryinfo>
13+
14+
<refmeta>
15+
<refentrytitle>systemd-udev-settle.service</refentrytitle>
16+
<manvolnum>8</manvolnum>
17+
</refmeta>
18+
19+
<refnamediv>
20+
<refname>systemd-udev-settle.service</refname>
21+
<refpurpose>Wait for all pending udev events to be handled</refpurpose>
22+
</refnamediv>
23+
24+
<refsynopsisdiv>
25+
<para><filename>systemd-udev-settle.service</filename></para>
26+
</refsynopsisdiv>
27+
28+
<refsect1><title>Description</title>
29+
<para>This service calls <command>udevadm settle</command> to wait until all events that have been queued
30+
by <citerefentry><refentrytitle>udev</refentrytitle><manvolnum>7</manvolnum></citerefentry> have been
31+
processed. It is a crude way to wait until "all" hardware has been discovered. Services may pull in this
32+
service and order themselves after it to wait for the udev queue to be empty.</para>
33+
34+
<para><emphasis>Using this service is not recommended.</emphasis> There can be no guarantee that hardware
35+
is fully discovered at any specific time, because the kernel does hardware detection asynchronously, and
36+
certain busses and devices take a very long time to become ready, and also additional hardware may be
37+
plugged in at any time. Instead, services should subscribe to udev events and react to any new hardware as
38+
it is discovered. Services that, based on configuration, expect certain devices to appear, may warn or
39+
report failure after a timeout. This timeout should be tailored to the hardware type. Waiting for
40+
<filename>systemd-udev-settle.service</filename> usually slows boot significantly, because it means waiting
41+
for all unrelated events too.</para>
42+
</refsect1>
43+
44+
<refsect1>
45+
<title>See Also</title>
46+
<para>
47+
<citerefentry><refentrytitle>udev</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
48+
<citerefentry><refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum></citerefentry>
49+
</para>
50+
</refsect1>
51+
</refentry>

man/udevadm.xml

+4
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@
362362

363363
<xi:include href="standard-options.xml" xpointer="help" />
364364
</variablelist>
365+
366+
<para>See
367+
<citerefentry><refentrytitle>systemd-udev-settle.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
368+
for more information.</para>
365369
</refsect2>
366370

367371
<refsect2><title>udevadm control <replaceable>option</replaceable></title>

src/udev/udevadm-settle.c

+64-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
#include <string.h>
1414
#include <unistd.h>
1515

16+
#include "sd-bus.h"
17+
#include "sd-login.h"
18+
1619
#include "libudev-util.h"
20+
#include "string-util.h"
21+
#include "strv.h"
1722
#include "time-util.h"
18-
#include "udevadm.h"
1923
#include "udev-ctrl.h"
24+
#include "udevadm.h"
25+
#include "unit-def.h"
2026
#include "util.h"
2127
#include "virt.h"
2228

@@ -79,6 +85,61 @@ static int parse_argv(int argc, char *argv[]) {
7985
return 1;
8086
}
8187

88+
static int emit_deprecation_warning(void) {
89+
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
90+
_cleanup_free_ char *unit = NULL, *unit_path = NULL;
91+
_cleanup_strv_free_ char **a = NULL, **b = NULL;
92+
int r;
93+
94+
r = sd_pid_get_unit(0, &unit);
95+
if (r < 0 || !streq(unit, "systemd-udev-settle.service"))
96+
return 0;
97+
98+
log_notice("systemd-udev-settle.service is deprecated.");
99+
100+
r = sd_bus_open_system(&bus);
101+
if (r < 0)
102+
return log_debug_errno(r, "Failed to open system bus, skipping dependency queries: %m");
103+
104+
unit_path = unit_dbus_path_from_name("systemd-udev-settle.service");
105+
if (!unit_path)
106+
return -ENOMEM;
107+
108+
(void) sd_bus_get_property_strv(
109+
bus,
110+
"org.freedesktop.systemd1",
111+
unit_path,
112+
"org.freedesktop.systemd1.Unit",
113+
"WantedBy",
114+
NULL,
115+
&a);
116+
117+
(void) sd_bus_get_property_strv(
118+
bus,
119+
"org.freedesktop.systemd1",
120+
unit_path,
121+
"org.freedesktop.systemd1.Unit",
122+
"RequiredBy",
123+
NULL,
124+
&b);
125+
126+
r = strv_extend_strv(&a, b, true);
127+
if (r < 0)
128+
return r;
129+
130+
if (!strv_isempty(a)) {
131+
_cleanup_free_ char *t = NULL;
132+
133+
t = strv_join(a, ", ");
134+
if (!t)
135+
return -ENOMEM;
136+
137+
log_notice("Hint: please fix %s not to pull it in.", t);
138+
}
139+
140+
return 0;
141+
}
142+
82143
int settle_main(int argc, char *argv[], void *userdata) {
83144
_cleanup_(udev_queue_unrefp) struct udev_queue *queue = NULL;
84145
struct pollfd pfd;
@@ -128,6 +189,8 @@ int settle_main(int argc, char *argv[], void *userdata) {
128189
.fd = r,
129190
};
130191

192+
(void) emit_deprecation_warning();
193+
131194
for (;;) {
132195
if (arg_exists && access(arg_exists, F_OK) >= 0)
133196
return 0;

units/systemd-udev-settle.service.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
[Unit]
1515
Description=udev Wait for Complete Device Initialization
16-
Documentation=man:udev(7) man:systemd-udevd.service(8)
16+
Documentation=man:systemd-udev-settle.service(8)
1717
DefaultDependencies=no
1818
Wants=systemd-udevd.service
1919
After=systemd-udev-trigger.service

0 commit comments

Comments
 (0)