Skip to content

Commit 608aa60

Browse files
authored
Merge pull request #28365 from DaanDeMeyer/udevadm-query
Various fixes and improvements
2 parents 39939e7 + a9e536a commit 608aa60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+284
-466
lines changed

src/backlight/backlight.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ static int help(void) {
4747

4848
static int has_multiple_graphics_cards(void) {
4949
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
50-
sd_device *dev;
5150
bool found = false;
5251
int r;
5352

@@ -173,7 +172,7 @@ static int same_device(sd_device *a, sd_device *b) {
173172
static int validate_device(sd_device *device) {
174173
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *enumerate = NULL;
175174
const char *v, *sysname, *subsystem;
176-
sd_device *parent, *other;
175+
sd_device *parent;
177176
int r;
178177

179178
assert(device);

src/basic/terminal-util.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
/* Underlined */
5151
#define ANSI_GREY_UNDERLINE "\x1B[0;4;38;5;245m"
52+
#define ANSI_BRIGHT_BLACK_UNDERLINE "\x1B[0;4;90m"
5253
#define ANSI_HIGHLIGHT_RED_UNDERLINE "\x1B[0;1;4;31m"
5354
#define ANSI_HIGHLIGHT_GREEN_UNDERLINE "\x1B[0;1;4;32m"
5455
#define ANSI_HIGHLIGHT_YELLOW_UNDERLINE "\x1B[0;1;4;38;5;185m"
@@ -62,8 +63,10 @@
6263
#define ANSI_HIGHLIGHT_UNDERLINE "\x1B[0;1;4m"
6364

6465
/* Fallback colors: 256 -> 16 */
65-
#define ANSI_HIGHLIGHT_GREY_FALLBACK "\x1B[0;1;90m"
66-
#define ANSI_HIGHLIGHT_YELLOW_FALLBACK "\x1B[0;1;33m"
66+
#define ANSI_HIGHLIGHT_GREY_FALLBACK "\x1B[0;1;90m"
67+
#define ANSI_HIGHLIGHT_GREY_FALLBACK_UNDERLINE "\x1B[0;1;4;90m"
68+
#define ANSI_HIGHLIGHT_YELLOW_FALLBACK "\x1B[0;1;33m"
69+
#define ANSI_HIGHLIGHT_YELLOW_FALLBACK_UNDERLINE "\x1B[0;1;4;33m"
6770

6871
/* Reset/clear ANSI styles */
6972
#define ANSI_NORMAL "\x1B[0m"
@@ -177,9 +180,13 @@ static inline bool colors_enabled(void) {
177180
} \
178181
}
179182

183+
static inline const char *ansi_underline(void) {
184+
return underline_enabled() ? ANSI_UNDERLINE : ANSI_NORMAL;
185+
}
186+
180187
#define DEFINE_ANSI_FUNC_UNDERLINE(name, NAME) \
181188
static inline const char *ansi_##name(void) { \
182-
return underline_enabled() ? ANSI_##NAME ANSI_UNDERLINE : \
189+
return underline_enabled() ? ANSI_##NAME##_UNDERLINE : \
183190
colors_enabled() ? ANSI_##NAME : ""; \
184191
}
185192

@@ -188,8 +195,8 @@ static inline bool colors_enabled(void) {
188195
static inline const char *ansi_##name(void) { \
189196
switch (get_color_mode()) { \
190197
case COLOR_OFF: return ""; \
191-
case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK ANSI_UNDERLINE : ANSI_##FALLBACK; \
192-
default : return underline_enabled() ? ANSI_##NAME ANSI_UNDERLINE: ANSI_##NAME; \
198+
case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK##_UNDERLINE : ANSI_##FALLBACK; \
199+
default : return underline_enabled() ? ANSI_##NAME##_UNDERLINE: ANSI_##NAME; \
193200
} \
194201
}
195202

@@ -229,7 +236,6 @@ static inline const char* _ansi_highlight_yellow(void) {
229236
return colors_enabled() ? _ANSI_HIGHLIGHT_YELLOW : "";
230237
}
231238

232-
DEFINE_ANSI_FUNC_UNDERLINE(underline, NORMAL);
233239
DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT);
234240
DEFINE_ANSI_FUNC_UNDERLINE_256(grey_underline, GREY, BRIGHT_BLACK);
235241
DEFINE_ANSI_FUNC_UNDERLINE(highlight_red_underline, HIGHLIGHT_RED);

src/busctl/busctl.c

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,34 +1679,26 @@ static int json_transform_array_or_struct(sd_bus_message *m, JsonVariant **ret)
16791679
assert(m);
16801680
assert(ret);
16811681

1682+
CLEANUP_ARRAY(elements, n_elements, json_variant_unref_many);
1683+
16821684
for (;;) {
16831685
r = sd_bus_message_at_end(m, false);
1684-
if (r < 0) {
1685-
bus_log_parse_error(r);
1686-
goto finish;
1687-
}
1686+
if (r < 0)
1687+
return bus_log_parse_error(r);
16881688
if (r > 0)
16891689
break;
16901690

1691-
if (!GREEDY_REALLOC(elements, n_elements + 1)) {
1692-
r = log_oom();
1693-
goto finish;
1694-
}
1691+
if (!GREEDY_REALLOC(elements, n_elements + 1))
1692+
return log_oom();
16951693

16961694
r = json_transform_one(m, elements + n_elements);
16971695
if (r < 0)
1698-
goto finish;
1696+
return r;
16991697

17001698
n_elements++;
17011699
}
17021700

1703-
r = json_variant_new_array(ret, elements, n_elements);
1704-
1705-
finish:
1706-
json_variant_unref_many(elements, n_elements);
1707-
free(elements);
1708-
1709-
return r;
1701+
return json_variant_new_array(ret, elements, n_elements);
17101702
}
17111703

17121704
static int json_transform_variant(sd_bus_message *m, const char *contents, JsonVariant **ret) {
@@ -1737,15 +1729,15 @@ static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {
17371729
assert(m);
17381730
assert(ret);
17391731

1732+
CLEANUP_ARRAY(elements, n_elements, json_variant_unref_many);
1733+
17401734
for (;;) {
17411735
const char *contents;
17421736
char type;
17431737

17441738
r = sd_bus_message_at_end(m, false);
1745-
if (r < 0) {
1746-
bus_log_parse_error(r);
1747-
goto finish;
1748-
}
1739+
if (r < 0)
1740+
return bus_log_parse_error(r);
17491741
if (r > 0)
17501742
break;
17511743

@@ -1755,43 +1747,31 @@ static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {
17551747

17561748
assert(type == 'e');
17571749

1758-
if (!GREEDY_REALLOC(elements, n_elements + 2)) {
1759-
r = log_oom();
1760-
goto finish;
1761-
}
1750+
if (!GREEDY_REALLOC(elements, n_elements + 2))
1751+
return log_oom();
17621752

17631753
r = sd_bus_message_enter_container(m, type, contents);
1764-
if (r < 0) {
1765-
bus_log_parse_error(r);
1766-
goto finish;
1767-
}
1754+
if (r < 0)
1755+
return bus_log_parse_error(r);
17681756

17691757
r = json_transform_one(m, elements + n_elements);
17701758
if (r < 0)
1771-
goto finish;
1759+
return r;
17721760

17731761
n_elements++;
17741762

17751763
r = json_transform_one(m, elements + n_elements);
17761764
if (r < 0)
1777-
goto finish;
1765+
return r;
17781766

17791767
n_elements++;
17801768

17811769
r = sd_bus_message_exit_container(m);
1782-
if (r < 0) {
1783-
bus_log_parse_error(r);
1784-
goto finish;
1785-
}
1770+
if (r < 0)
1771+
return bus_log_parse_error(r);
17861772
}
17871773

1788-
r = json_variant_new_object(ret, elements, n_elements);
1789-
1790-
finish:
1791-
json_variant_unref_many(elements, n_elements);
1792-
free(elements);
1793-
1794-
return r;
1774+
return json_variant_new_object(ret, elements, n_elements);
17951775
}
17961776

17971777
static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {

src/core/device.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ static int device_setup_devlink_unit_one(Manager *m, const char *devlink, Set **
800800

801801
static int device_setup_extra_units(Manager *m, sd_device *dev, Set **ready_units, Set **not_ready_units) {
802802
_cleanup_strv_free_ char **aliases = NULL;
803-
const char *devlink, *syspath, *devname = NULL;
803+
const char *syspath, *devname = NULL;
804804
Device *l;
805805
int r;
806806

@@ -1017,7 +1017,6 @@ static void device_shutdown(Manager *m) {
10171017

10181018
static void device_enumerate(Manager *m) {
10191019
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
1020-
sd_device *dev;
10211020
int r;
10221021

10231022
assert(m);

src/core/swap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int swap_setup_unit(
491491

492492
static void swap_process_new(Manager *m, const char *device, int prio, bool set_flags) {
493493
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
494-
const char *dn, *devlink;
494+
const char *dn;
495495
struct stat st, st_link;
496496
int r;
497497

@@ -1405,7 +1405,7 @@ static void swap_enumerate(Manager *m) {
14051405

14061406
int swap_process_device_new(Manager *m, sd_device *dev) {
14071407
_cleanup_free_ char *e = NULL;
1408-
const char *dn, *devlink;
1408+
const char *dn;
14091409
Unit *u;
14101410
int r;
14111411

src/dissect/dissect.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,6 @@ static int action_detach(const char *path) {
16991699

17001700
} else if (S_ISREG(st.st_mode)) {
17011701
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
1702-
sd_device *d;
17031702

17041703
/* If a regular file is specified, search for a loopback block device that is backed by it */
17051704

src/home/homed-manager.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,6 @@ static int manager_watch_devices(Manager *m) {
13371337

13381338
static int manager_enumerate_devices(Manager *m) {
13391339
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
1340-
sd_device *d;
13411340
int r;
13421341

13431342
assert(m);

src/journal/journald-kmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
237237
}
238238

239239
j = 0;
240-
FOREACH_DEVICE_DEVLINK(d, g) {
240+
FOREACH_DEVICE_DEVLINK(d, link) {
241241

242242
if (j >= N_IOVEC_UDEV_FIELDS)
243243
break;
244244

245-
b = strjoin("_UDEV_DEVLINK=", g);
245+
b = strjoin("_UDEV_DEVLINK=", link);
246246
if (b) {
247247
iovec[n++] = IOVEC_MAKE_STRING(b);
248248
z++;

src/libsystemd/sd-device/device-enumerator.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,14 @@ static bool match_property(sd_device_enumerator *enumerator, sd_device *device)
471471
if (hashmap_isempty(enumerator->match_property))
472472
return true;
473473

474-
HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property) {
475-
const char *property, *value;
476-
474+
HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property)
477475
FOREACH_DEVICE_PROPERTY(device, property, value) {
478476
if (fnmatch(property_pattern, property, 0) != 0)
479477
continue;
480478

481479
if (strv_fnmatch(value_patterns, value))
482480
return true;
483481
}
484-
}
485482

486483
return false;
487484
}

src/libsystemd/sd-device/device-monitor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ int device_monitor_send_device(
681681

682682
/* add tag bloom filter */
683683
tag_bloom_bits = 0;
684-
FOREACH_DEVICE_TAG(device, val)
685-
tag_bloom_bits |= string_bloom64(val);
684+
FOREACH_DEVICE_TAG(device, tag)
685+
tag_bloom_bits |= string_bloom64(tag);
686686

687687
if (tag_bloom_bits > 0) {
688688
nlh.filter_tag_bloom_hi = htobe32(tag_bloom_bits >> 32);

0 commit comments

Comments
 (0)