• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 25026908423

27 Apr 2026 07:14PM UTC coverage: 71.865% (-0.3%) from 72.175%
25026908423

push

github

daandemeyer
udev: don't assert on worker cap after killing a broken idle worker

manager_can_process_event() considers an event processable if either
there is room below children_max to spawn, or an idle worker exists.
When only the latter holds, event_run() picks the idle worker and
tries device_monitor_send(). If that send fails, event_run() SIGKILLs
the worker, marks it WORKER_KILLED and continues the loop. With no
other idle worker available, it falls through to worker_spawn(),
guarded by:

    assert(hashmap_size(manager->workers) < manager->config.children_max);

The just-killed worker is still in manager->workers until its SIGCHLD
is reaped by on_worker_exit(), so at the cap this assertion trips and
udevd aborts:

    Assertion 'hashmap_size(manager->workers) < manager->config.children_max'
    failed at src/udev/udev-manager.c:635, function event_run(). Aborting.

Instead of asserting, bail out when we are already at the worker
limit. The event remains in EVENT_QUEUED; once the killed worker's
SIGCHLD arrives and frees it from the hashmap, on_post() re-runs
event_queue_start() and the event is retried.

1 of 1 new or added line in 1 file covered. (100.0%)

7309 existing lines in 125 files now uncovered.

322519 of 448782 relevant lines covered (71.87%)

1173939.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.4
/src/shared/blockdev-list.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "sd-device.h"
4

5
#include "alloc-util.h"
6
#include "ansi-color.h"
7
#include "blockdev-list.h"
8
#include "blockdev-util.h"
9
#include "device-private.h"
10
#include "device-util.h"
11
#include "devnum-util.h"
12
#include "errno-util.h"
13
#include "string-util.h"
14
#include "strv.h"
15
#include "terminal-util.h"
16

17
void block_device_done(BlockDevice *d) {
×
UNCOV
18
        assert(d);
×
19

20
        d->node = mfree(d->node);
×
21
        d->symlinks = strv_free(d->symlinks);
×
22
        d->model = mfree(d->model);
×
23
        d->vendor = mfree(d->vendor);
×
24
        d->subsystem = mfree(d->subsystem);
×
UNCOV
25
 }
×
26

UNCOV
27
void block_device_array_free(BlockDevice *d, size_t n_devices) {
×
28

29
        FOREACH_ARRAY(i, d, n_devices)
×
UNCOV
30
                block_device_done(d);
×
31

32
        free(d);
×
UNCOV
33
}
×
34

35
static int blockdev_get_prop(sd_device *d, const char *prop1, const char *prop2, char **ret_value) {
×
UNCOV
36
        int r, ret = 0;
×
37

38
        assert(d);
×
39
        assert(prop1);
×
UNCOV
40
        assert(ret_value);
×
41

42
        FOREACH_STRING(prop, prop1, prop2) {
×
43
                const char *m = NULL;
×
44
                r = sd_device_get_property_value(d, prop, &m);
×
45
                if (r < 0 && r != -ENOENT)
×
46
                        RET_GATHER(ret, log_device_debug_errno(d, r, "Failed to acquire '%s' from device, ignoring: %m", prop));
×
47
                else if (!isempty(m))
×
UNCOV
48
                        return strdup_to(ret_value, m);
×
49
        }
50

UNCOV
51
        return ret < 0 ? ret : -ENOENT;
×
52
}
53

54
static int blockdev_get_subsystem(sd_device *d, char **ret_subsystem) {
×
UNCOV
55
        int r;
×
56

57
        assert(d);
×
UNCOV
58
        assert(ret_subsystem);
×
59

60
        /* We prefer the explicitly set block device subsystem property, because if it is set it's generally
61
         * the most useful. If it's not set we'll look for the subsystem of the first parent device that
62
         * isn't of subsystem 'block'. The former covers 'virtual' block devices such as loopback, device
63
         * mapper, zram, while the latter covers physical block devices such as USB or NVME. */
64

65
        r = blockdev_get_prop(d, "ID_BLOCK_SUBSYSTEM", /* prop2= */ NULL, ret_subsystem);
×
66
        if (r >= 0)
×
UNCOV
67
                return r;
×
68

69
        int ret = r != -ENOENT ? r : 0;
×
70
        sd_device *q = d;
×
71
        for (;;) {
×
72
                r = sd_device_get_parent(q, &q);
×
73
                if (r < 0) {
×
74
                        if (r != -ENOENT)
×
75
                                RET_GATHER(ret, log_device_debug_errno(q, r, "Failed to get parent device, ignoring: %m"));
×
UNCOV
76
                        break;
×
77
                }
78

79
                const char *s = NULL;
×
80
                r = sd_device_get_subsystem(q, &s);
×
81
                if (r < 0)
×
82
                        RET_GATHER(ret, log_device_debug_errno(q, r, "Failed to get subsystem of device, ignoring: %m"));
×
83
                else if (!isempty(s) && !streq(s, "block"))
×
UNCOV
84
                        return strdup_to(ret_subsystem, s);
×
85
        }
86

UNCOV
87
        return ret < 0 ? ret : -ENOENT;
×
88
}
89

90
int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *ret_n_devices) {
6✔
91
        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
6✔
92
        int r;
6✔
93

94
        assert(!!ret_devices == !!ret_n_devices);
6✔
95

96
        /* If ret_devices/ret_n_devices are passed, returns a list of matching block devices, otherwise
97
         * prints the list to stdout */
98

99
        BlockDevice *l = NULL;
6✔
100
        size_t n = 0;
6✔
101
        CLEANUP_ARRAY(l, n, block_device_array_free);
6✔
102

103
        dev_t root_devno = 0, whole_root_devno = 0;
6✔
104
        if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT)) {
6✔
105
                r = blockdev_get_root(LOG_DEBUG, &root_devno);
2✔
106
                if (r < 0)
2✔
107
                        log_debug_errno(r, "Failed to get block device of root device, ignoring: %m");
×
108
                else if (r > 0) {
2✔
109
                        r = block_get_whole_disk(root_devno, &whole_root_devno);
2✔
110
                        if (r < 0)
2✔
111
                                log_debug_errno(r, "Failed to get whole block device of root device, ignoring: %m");
×
112
                }
113

114
                /* It's fine if root_devno/whole_root_devno are zero here as devnum_set_and_equal() will
115
                 * happily take that into account – it is in fact its primary raison d'etre. */
116
        }
117

118
        if (sd_device_enumerator_new(&e) < 0)
6✔
UNCOV
119
                return log_oom();
×
120

121
        r = sd_device_enumerator_add_match_subsystem(e, "block", /* match= */ true);
6✔
122
        if (r < 0)
6✔
UNCOV
123
                return log_error_errno(r, "Failed to add subsystem match: %m");
×
124

125
        if (FLAGS_SET(flags, BLOCKDEV_LIST_REQUIRE_LUKS)) {
6✔
126
                r = sd_device_enumerator_add_match_property(e, "ID_FS_TYPE", "crypto_LUKS");
1✔
127
                if (r < 0)
1✔
128
                        return log_error_errno(r, "Failed to add match for LUKS block devices: %m");
×
129
        }
130

131
        FOREACH_DEVICE(e, dev) {
32✔
132
                const char *node;
26✔
133

134
                r = sd_device_get_devname(dev, &node);
26✔
135
                if (r < 0) {
26✔
UNCOV
136
                        log_device_warning_errno(dev, r, "Failed to get device node of discovered block device, ignoring: %m");
×
137
                        continue;
19✔
138
                }
139

140
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT) && root_devno != 0) {
26✔
141
                        dev_t devno;
11✔
142

143
                        r = sd_device_get_devnum(dev, &devno);
11✔
144
                        if (r < 0) {
11✔
UNCOV
145
                                log_device_warning_errno(dev, r, "Failed to get major/minor of discovered block device, ignoring: %m");
×
146
                                continue;
4✔
147
                        }
148

149
                        if (devnum_set_and_equal(devno, root_devno) ||
11✔
150
                            devnum_set_and_equal(devno, whole_root_devno))
9✔
151
                                continue;
4✔
152
                }
153

154
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ZRAM)) {
22✔
155
                        r = device_sysname_startswith(dev, "zram");
21✔
156
                        if (r < 0) {
21✔
UNCOV
157
                                log_device_warning_errno(dev, r, "Failed to check device name of discovered block device '%s', ignoring: %m", node);
×
158
                                continue;
×
159
                        }
160
                        if (r > 0)
21✔
UNCOV
161
                                continue;
×
162
                }
163

164
                if (FLAGS_SET(flags, BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING)) {
22✔
165
                        r = blockdev_partscan_enabled(dev);
17✔
166
                        if (r < 0) {
17✔
UNCOV
167
                                log_device_warning_errno(dev, r, "Unable to determine whether '%s' supports partition scanning, skipping device: %m", node);
×
UNCOV
168
                                continue;
×
169
                        }
170
                        if (r == 0) {
17✔
171
                                log_device_debug(dev, "Device '%s' does not support partition scanning, skipping.", node);
15✔
172
                                continue;
15✔
173
                        }
174
                }
175

176
                uint64_t size = UINT64_MAX;
7✔
177
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_EMPTY) || ret_devices) {
7✔
178
                        r = device_get_sysattr_u64(dev, "size", &size);
×
UNCOV
179
                        if (r < 0)
×
UNCOV
180
                                log_device_debug_errno(dev, r, "Failed to acquire size of device '%s', ignoring: %m", node);
×
181
                        else
182
                                /* the 'size' sysattr is always in multiples of 512, even on 4K sector block devices! */
UNCOV
183
                                assert_se(MUL_ASSIGN_SAFE(&size, 512)); /* Overflow check for coverity */
×
184

UNCOV
185
                        if (size == 0 && FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_EMPTY)) {
×
186
                                log_device_debug(dev, "Device '%s' has a zero size, assuming drive without a medium, skipping.", node);
×
UNCOV
187
                                continue;
×
188
                        }
189
                }
190

UNCOV
191
                _cleanup_strv_free_ char **list = NULL;
×
192
                if (FLAGS_SET(flags, BLOCKDEV_LIST_SHOW_SYMLINKS)) {
7✔
193
                        FOREACH_DEVICE_DEVLINK(dev, sl)
67✔
194
                                if (strv_extend(&list, sl) < 0)
60✔
195
                                        return log_oom();
×
196

197
                        strv_sort(list);
7✔
198
                }
199

200
                _cleanup_free_ char *model = NULL, *vendor = NULL, *subsystem = NULL;
7✔
201
                int ro = -1;
7✔
202
                if (FLAGS_SET(flags, BLOCKDEV_LIST_METADATA)) {
7✔
UNCOV
203
                        (void) blockdev_get_prop(dev, "ID_MODEL_FROM_DATABASE", "ID_MODEL", &model);
×
204
                        (void) blockdev_get_prop(dev, "ID_VENDOR_FROM_DATABASE", "ID_VENDOR", &vendor);
×
205
                        (void) blockdev_get_subsystem(dev, &subsystem);
×
206

207
                        r = device_get_sysattr_bool(dev, "ro");
×
208
                        if (r < 0)
×
209
                                log_device_debug_errno(dev, r, "Failed to acquire read-only flag of device '%s', ignoring: %m", node);
×
210
                        else
211
                                ro = r;
212
                }
213

214
                if (ret_devices) {
7✔
UNCOV
215
                        uint64_t diskseq = UINT64_MAX;
×
216
                        r = sd_device_get_diskseq(dev, &diskseq);
×
217
                        if (r < 0)
×
218
                                log_device_debug_errno(dev, r, "Failed to acquire diskseq of device '%s', ignoring: %m", node);
×
219

UNCOV
220
                        if (!GREEDY_REALLOC(l, n+1))
×
UNCOV
221
                                return log_oom();
×
222

UNCOV
223
                        _cleanup_free_ char *m = strdup(node);
×
UNCOV
224
                        if (!m)
×
UNCOV
225
                                return log_oom();
×
226

UNCOV
227
                        l[n++] = (BlockDevice) {
×
UNCOV
228
                                .node = TAKE_PTR(m),
×
UNCOV
229
                                .symlinks = TAKE_PTR(list),
×
230
                                .diskseq = diskseq,
231
                                .size = size,
UNCOV
232
                                .model = TAKE_PTR(model),
×
UNCOV
233
                                .vendor = TAKE_PTR(vendor),
×
UNCOV
234
                                .subsystem = TAKE_PTR(subsystem),
×
235
                                .read_only = ro,
236
                        };
237

238
                } else {
239
                        printf("%s\n", node);
7✔
240

241
                        if (FLAGS_SET(flags, BLOCKDEV_LIST_SHOW_SYMLINKS))
7✔
242
                                STRV_FOREACH(i, list)
67✔
243
                                        printf("%s%s%s%s\n", on_tty() ? "    " : "", ansi_grey(), *i, ansi_normal());
180✔
244
                }
245
        }
246

247
        if (ret_devices)
6✔
248
                *ret_devices = TAKE_PTR(l);
2✔
249
        if (ret_n_devices)
6✔
250
                *ret_n_devices = n;
2✔
251

252
        return 0;
253
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc