mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-12 08:58:20 +03:00
device-util: Declare iterator variables inline
This commit is contained in:
parent
26b682e816
commit
a1af83728f
@ -47,7 +47,6 @@ static int help(void) {
|
||||
|
||||
static int has_multiple_graphics_cards(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
bool found = false;
|
||||
int r;
|
||||
|
||||
@ -173,7 +172,7 @@ static int same_device(sd_device *a, sd_device *b) {
|
||||
static int validate_device(sd_device *device) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *enumerate = NULL;
|
||||
const char *v, *sysname, *subsystem;
|
||||
sd_device *parent, *other;
|
||||
sd_device *parent;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
|
@ -800,7 +800,7 @@ static int device_setup_devlink_unit_one(Manager *m, const char *devlink, Set **
|
||||
|
||||
static int device_setup_extra_units(Manager *m, sd_device *dev, Set **ready_units, Set **not_ready_units) {
|
||||
_cleanup_strv_free_ char **aliases = NULL;
|
||||
const char *devlink, *syspath, *devname = NULL;
|
||||
const char *syspath, *devname = NULL;
|
||||
Device *l;
|
||||
int r;
|
||||
|
||||
@ -1017,7 +1017,6 @@ static void device_shutdown(Manager *m) {
|
||||
|
||||
static void device_enumerate(Manager *m) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
@ -491,7 +491,7 @@ fail:
|
||||
|
||||
static void swap_process_new(Manager *m, const char *device, int prio, bool set_flags) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
||||
const char *dn, *devlink;
|
||||
const char *dn;
|
||||
struct stat st, st_link;
|
||||
int r;
|
||||
|
||||
@ -1405,7 +1405,7 @@ fail:
|
||||
|
||||
int swap_process_device_new(Manager *m, sd_device *dev) {
|
||||
_cleanup_free_ char *e = NULL;
|
||||
const char *dn, *devlink;
|
||||
const char *dn;
|
||||
Unit *u;
|
||||
int r;
|
||||
|
||||
|
@ -1699,7 +1699,6 @@ static int action_detach(const char *path) {
|
||||
|
||||
} else if (S_ISREG(st.st_mode)) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
|
||||
/* If a regular file is specified, search for a loopback block device that is backed by it */
|
||||
|
||||
|
@ -1337,7 +1337,6 @@ static int manager_watch_devices(Manager *m) {
|
||||
|
||||
static int manager_enumerate_devices(Manager *m) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
@ -237,12 +237,12 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
|
||||
}
|
||||
|
||||
j = 0;
|
||||
FOREACH_DEVICE_DEVLINK(d, g) {
|
||||
FOREACH_DEVICE_DEVLINK(d, link) {
|
||||
|
||||
if (j >= N_IOVEC_UDEV_FIELDS)
|
||||
break;
|
||||
|
||||
b = strjoin("_UDEV_DEVLINK=", g);
|
||||
b = strjoin("_UDEV_DEVLINK=", link);
|
||||
if (b) {
|
||||
iovec[n++] = IOVEC_MAKE_STRING(b);
|
||||
z++;
|
||||
|
@ -471,9 +471,7 @@ static bool match_property(sd_device_enumerator *enumerator, sd_device *device)
|
||||
if (hashmap_isempty(enumerator->match_property))
|
||||
return true;
|
||||
|
||||
HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property) {
|
||||
const char *property, *value;
|
||||
|
||||
HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property)
|
||||
FOREACH_DEVICE_PROPERTY(device, property, value) {
|
||||
if (fnmatch(property_pattern, property, 0) != 0)
|
||||
continue;
|
||||
@ -481,7 +479,6 @@ static bool match_property(sd_device_enumerator *enumerator, sd_device *device)
|
||||
if (strv_fnmatch(value_patterns, value))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -681,8 +681,8 @@ int device_monitor_send_device(
|
||||
|
||||
/* add tag bloom filter */
|
||||
tag_bloom_bits = 0;
|
||||
FOREACH_DEVICE_TAG(device, val)
|
||||
tag_bloom_bits |= string_bloom64(val);
|
||||
FOREACH_DEVICE_TAG(device, tag)
|
||||
tag_bloom_bits |= string_bloom64(tag);
|
||||
|
||||
if (tag_bloom_bits > 0) {
|
||||
nlh.filter_tag_bloom_hi = htobe32(tag_bloom_bits >> 32);
|
||||
|
@ -525,7 +525,6 @@ int device_new_from_nulstr(sd_device **ret, char *nulstr, size_t len) {
|
||||
static int device_update_properties_bufs(sd_device *device) {
|
||||
_cleanup_free_ char **buf_strv = NULL, *buf_nulstr = NULL;
|
||||
size_t nulstr_len = 0, num = 0;
|
||||
const char *val, *prop;
|
||||
|
||||
assert(device);
|
||||
|
||||
@ -728,7 +727,6 @@ static int device_tag(sd_device *device, const char *tag, bool add) {
|
||||
}
|
||||
|
||||
int device_tag_index(sd_device *device, sd_device *device_old, bool add) {
|
||||
const char *tag;
|
||||
int r = 0, k;
|
||||
|
||||
if (add && device_old)
|
||||
@ -819,11 +817,9 @@ int device_update_db(sd_device *device) {
|
||||
}
|
||||
|
||||
if (has_info) {
|
||||
const char *property, *value, *tag;
|
||||
const char *property, *value, *ct;
|
||||
|
||||
if (major(device->devnum) > 0) {
|
||||
const char *devlink;
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(device, devlink)
|
||||
fprintf(f, "S:%s\n", devlink + STRLEN("/dev/"));
|
||||
|
||||
@ -840,8 +836,8 @@ int device_update_db(sd_device *device) {
|
||||
FOREACH_DEVICE_TAG(device, tag)
|
||||
fprintf(f, "G:%s\n", tag); /* Any tag */
|
||||
|
||||
SET_FOREACH(tag, device->current_tags)
|
||||
fprintf(f, "Q:%s\n", tag); /* Current tag */
|
||||
SET_FOREACH(ct, device->current_tags)
|
||||
fprintf(f, "Q:%s\n", ct); /* Current tag */
|
||||
|
||||
/* Always write the latest database version here, instead of the value stored in
|
||||
* device->database_version, as which may be 0. */
|
||||
|
@ -14,32 +14,32 @@
|
||||
unref_and_replace_full(a, b, sd_device_ref, sd_device_unref)
|
||||
|
||||
#define FOREACH_DEVICE_PROPERTY(device, key, value) \
|
||||
for (key = sd_device_get_property_first(device, &(value)); \
|
||||
for (const char *value, *key = sd_device_get_property_first(device, &(value)); \
|
||||
key; \
|
||||
key = sd_device_get_property_next(device, &(value)))
|
||||
|
||||
#define FOREACH_DEVICE_TAG(device, tag) \
|
||||
for (tag = sd_device_get_tag_first(device); \
|
||||
for (const char *tag = sd_device_get_tag_first(device); \
|
||||
tag; \
|
||||
tag = sd_device_get_tag_next(device))
|
||||
|
||||
#define FOREACH_DEVICE_CURRENT_TAG(device, tag) \
|
||||
for (tag = sd_device_get_current_tag_first(device); \
|
||||
for (const char *tag = sd_device_get_current_tag_first(device); \
|
||||
tag; \
|
||||
tag = sd_device_get_current_tag_next(device))
|
||||
|
||||
#define FOREACH_DEVICE_SYSATTR(device, attr) \
|
||||
for (attr = sd_device_get_sysattr_first(device); \
|
||||
for (const char *attr = sd_device_get_sysattr_first(device); \
|
||||
attr; \
|
||||
attr = sd_device_get_sysattr_next(device))
|
||||
|
||||
#define FOREACH_DEVICE_DEVLINK(device, devlink) \
|
||||
for (devlink = sd_device_get_devlink_first(device); \
|
||||
for (const char *devlink = sd_device_get_devlink_first(device); \
|
||||
devlink; \
|
||||
devlink = sd_device_get_devlink_next(device))
|
||||
|
||||
#define _FOREACH_DEVICE_CHILD(device, child, suffix_ptr) \
|
||||
for (child = sd_device_get_child_first(device, suffix_ptr); \
|
||||
for (sd_device *child = sd_device_get_child_first(device, suffix_ptr); \
|
||||
child; \
|
||||
child = sd_device_get_child_next(device, suffix_ptr))
|
||||
|
||||
@ -50,12 +50,12 @@
|
||||
_FOREACH_DEVICE_CHILD(device, child, &suffix)
|
||||
|
||||
#define FOREACH_DEVICE(enumerator, device) \
|
||||
for (device = sd_device_enumerator_get_device_first(enumerator); \
|
||||
for (sd_device *device = sd_device_enumerator_get_device_first(enumerator); \
|
||||
device; \
|
||||
device = sd_device_enumerator_get_device_next(enumerator))
|
||||
|
||||
#define FOREACH_SUBSYSTEM(enumerator, device) \
|
||||
for (device = sd_device_enumerator_get_subsystem_first(enumerator); \
|
||||
for (sd_device *device = sd_device_enumerator_get_subsystem_first(enumerator); \
|
||||
device; \
|
||||
device = sd_device_enumerator_get_subsystem_next(enumerator))
|
||||
|
||||
|
@ -53,7 +53,7 @@ static void test_receive_device_fail(void) {
|
||||
|
||||
static void test_send_receive_one(sd_device *device, bool subsystem_filter, bool tag_filter, bool use_bpf) {
|
||||
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
|
||||
const char *syspath, *subsystem, *tag, *devtype = NULL;
|
||||
const char *syspath, *subsystem, *devtype = NULL;
|
||||
|
||||
log_device_info(device, "/* %s(subsystem_filter=%s, tag_filter=%s, use_bpf=%s) */", __func__,
|
||||
true_false(subsystem_filter), true_false(tag_filter), true_false(use_bpf));
|
||||
@ -90,7 +90,6 @@ static void test_subsystem_filter(sd_device *device) {
|
||||
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
const char *syspath, *subsystem;
|
||||
sd_device *d;
|
||||
|
||||
log_device_info(device, "/* %s */", __func__);
|
||||
|
||||
@ -131,7 +130,6 @@ static void test_tag_filter(sd_device *device) {
|
||||
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
const char *syspath;
|
||||
sd_device *d;
|
||||
|
||||
log_device_info(device, "/* %s */", __func__);
|
||||
|
||||
@ -170,7 +168,6 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) {
|
||||
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
const char *syspath, *sysattr_value;
|
||||
sd_device *d;
|
||||
|
||||
log_device_info(device, "/* %s(%s) */", __func__, sysattr);
|
||||
|
||||
@ -216,7 +213,7 @@ static void test_parent_filter(sd_device *device) {
|
||||
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
const char *syspath, *parent_syspath;
|
||||
sd_device *parent, *d;
|
||||
sd_device *parent;
|
||||
int r;
|
||||
|
||||
log_device_info(device, "/* %s */", __func__);
|
||||
|
@ -27,7 +27,6 @@ static void* thread(void *p) {
|
||||
int main(int argc, char *argv[]) {
|
||||
sd_device *loopback;
|
||||
pthread_t t;
|
||||
const char *key, *value;
|
||||
int r;
|
||||
|
||||
r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo");
|
||||
|
@ -194,7 +194,6 @@ static void test_sd_device_one(sd_device *d) {
|
||||
|
||||
TEST(sd_device_enumerator_devices) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0);
|
||||
@ -211,7 +210,6 @@ TEST(sd_device_enumerator_devices) {
|
||||
|
||||
TEST(sd_device_enumerator_subsystems) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0);
|
||||
@ -227,7 +225,7 @@ static void test_sd_device_enumerator_filter_subsystem_one(
|
||||
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
unsigned n_new_dev = 0, n_removed_dev = 0;
|
||||
sd_device *d;
|
||||
sd_device *dev;
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, true) >= 0);
|
||||
@ -248,14 +246,14 @@ static void test_sd_device_enumerator_filter_subsystem_one(
|
||||
assert_se(!sd_device_unref(t));
|
||||
}
|
||||
|
||||
HASHMAP_FOREACH(d, h) {
|
||||
HASHMAP_FOREACH(dev, h) {
|
||||
const char *syspath;
|
||||
|
||||
assert_se(sd_device_get_syspath(d, &syspath) >= 0);
|
||||
assert_se(sd_device_get_syspath(dev, &syspath) >= 0);
|
||||
log_warning("Device removed: subsystem:%s syspath:%s", subsystem, syspath);
|
||||
n_removed_dev++;
|
||||
|
||||
assert_se(!sd_device_unref(d));
|
||||
assert_se(!sd_device_unref(dev));
|
||||
}
|
||||
|
||||
hashmap_free(h);
|
||||
@ -268,7 +266,6 @@ static bool test_sd_device_enumerator_filter_subsystem_trial(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
_cleanup_hashmap_free_ Hashmap *subsystems = NULL;
|
||||
unsigned n_new_dev = 0, n_removed_dev = 0;
|
||||
sd_device *d;
|
||||
Hashmap *h;
|
||||
char *s;
|
||||
|
||||
@ -405,7 +402,6 @@ TEST(sd_device_enumerator_add_match_property) {
|
||||
static void check_parent_match(sd_device_enumerator *e, sd_device *dev) {
|
||||
const char *syspath;
|
||||
bool found = false;
|
||||
sd_device *d;
|
||||
|
||||
assert_se(sd_device_get_syspath(dev, &syspath) >= 0);
|
||||
|
||||
@ -429,7 +425,6 @@ static void check_parent_match(sd_device_enumerator *e, sd_device *dev) {
|
||||
|
||||
TEST(sd_device_enumerator_add_match_parent) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
@ -475,7 +470,6 @@ TEST(sd_device_enumerator_add_match_parent) {
|
||||
|
||||
TEST(sd_device_get_child) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
@ -490,7 +484,7 @@ TEST(sd_device_get_child) {
|
||||
|
||||
FOREACH_DEVICE(e, dev) {
|
||||
const char *syspath, *parent_syspath, *expected_suffix, *suffix;
|
||||
sd_device *parent, *child;
|
||||
sd_device *parent;
|
||||
bool found = false;
|
||||
|
||||
assert_se(sd_device_get_syspath(dev, &syspath) >= 0);
|
||||
@ -580,7 +574,6 @@ TEST(sd_device_new_from_nulstr) {
|
||||
TEST(sd_device_new_from_path) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert_se(mkdtemp_malloc("/tmp/test-sd-device.XXXXXXX", &tmpdir) >= 0);
|
||||
|
@ -635,8 +635,6 @@ _public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev
|
||||
|
||||
if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation ||
|
||||
!udev_device->devlinks_read) {
|
||||
const char *devlink;
|
||||
|
||||
udev_list_cleanup(udev_device->devlinks);
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(udev_device->device, devlink)
|
||||
@ -667,8 +665,6 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud
|
||||
|
||||
if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation ||
|
||||
!udev_device->properties_read) {
|
||||
const char *key, *value;
|
||||
|
||||
udev_list_cleanup(udev_device->properties);
|
||||
|
||||
FOREACH_DEVICE_PROPERTY(udev_device->device, key, value)
|
||||
@ -787,8 +783,6 @@ _public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_
|
||||
assert_return_errno(udev_device, NULL, EINVAL);
|
||||
|
||||
if (!udev_device->sysattrs_read) {
|
||||
const char *sysattr;
|
||||
|
||||
udev_list_cleanup(udev_device->sysattrs);
|
||||
|
||||
FOREACH_DEVICE_SYSATTR(udev_device->device, sysattr)
|
||||
@ -842,8 +836,6 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev
|
||||
|
||||
if (device_get_tags_generation(udev_device->device) != udev_device->all_tags_generation ||
|
||||
!udev_device->all_tags_read) {
|
||||
const char *tag;
|
||||
|
||||
udev_list_cleanup(udev_device->all_tags);
|
||||
|
||||
FOREACH_DEVICE_TAG(udev_device->device, tag)
|
||||
@ -862,8 +854,6 @@ _public_ struct udev_list_entry *udev_device_get_current_tags_list_entry(struct
|
||||
|
||||
if (device_get_tags_generation(udev_device->device) != udev_device->current_tags_generation ||
|
||||
!udev_device->current_tags_read) {
|
||||
const char *tag;
|
||||
|
||||
udev_list_cleanup(udev_device->current_tags);
|
||||
|
||||
FOREACH_DEVICE_CURRENT_TAG(udev_device->device, tag)
|
||||
|
@ -565,7 +565,6 @@ static bool manager_is_docked(Manager *m) {
|
||||
|
||||
static int manager_count_external_displays(Manager *m) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r, n = 0;
|
||||
|
||||
r = sd_device_enumerator_new(&e);
|
||||
|
@ -1296,7 +1296,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
|
||||
return sd_bus_reply_method_return(message, NULL);
|
||||
}
|
||||
|
||||
static int trigger_device(Manager *m, sd_device *d) {
|
||||
static int trigger_device(Manager *m, sd_device *parent) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
int r;
|
||||
|
||||
@ -1310,8 +1310,8 @@ static int trigger_device(Manager *m, sd_device *d) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (d) {
|
||||
r = sd_device_enumerator_add_match_parent(e, d);
|
||||
if (parent) {
|
||||
r = sd_device_enumerator_add_match_parent(e, parent);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -190,7 +190,6 @@ static Manager* manager_free(Manager *m) {
|
||||
|
||||
static int manager_enumerate_devices(Manager *m) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -219,7 +218,6 @@ static int manager_enumerate_devices(Manager *m) {
|
||||
|
||||
static int manager_enumerate_buttons(Manager *m) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
@ -779,7 +779,6 @@ static int find_mount_points(const char *what, char ***list) {
|
||||
|
||||
static int find_loop_device(const char *backing_file, sd_device **ret) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert(backing_file);
|
||||
@ -1366,7 +1365,6 @@ enum {
|
||||
static int list_devices(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
sd_device *d;
|
||||
unsigned c;
|
||||
int r;
|
||||
|
||||
|
@ -230,7 +230,7 @@ static int link_set_sr_iov_phys_port(Link *link) {
|
||||
|
||||
static int link_set_sr_iov_virt_ports(Link *link) {
|
||||
const char *dev_port, *name;
|
||||
sd_device *pci_dev, *child;
|
||||
sd_device *pci_dev;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
@ -12,7 +12,7 @@
|
||||
static int device_is_power_sink(sd_device *device) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
bool found_source = false, found_sink = false;
|
||||
sd_device *parent, *d;
|
||||
sd_device *parent;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
@ -109,7 +109,6 @@ static bool battery_is_discharging(sd_device *d) {
|
||||
int on_ac_power(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
bool found_ac_online = false, found_discharging_battery = false;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
r = sd_device_enumerator_new(&e);
|
||||
@ -234,7 +233,6 @@ int battery_read_capacity_percentage(sd_device *dev) {
|
||||
int battery_is_discharging_and_low(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
bool unsure = false, found_low = false;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
/* We have not used battery capacity_level since value is set to full
|
||||
|
@ -107,7 +107,6 @@ int block_device_get_whole_disk(sd_device *dev, sd_device **ret) {
|
||||
static int block_device_get_originating(sd_device *dev, sd_device **ret) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *first_found = NULL;
|
||||
const char *suffix;
|
||||
sd_device *child;
|
||||
dev_t devnum = 0; /* avoid false maybe-uninitialized warning */
|
||||
|
||||
/* For the specified block device tries to chase it through the layers, in case LUKS-style DM
|
||||
@ -665,7 +664,6 @@ int block_device_remove_all_partitions(sd_device *dev, int fd) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *dev_unref = NULL;
|
||||
_cleanup_close_ int fd_close = -EBADF;
|
||||
bool has_partitions = false;
|
||||
sd_device *part;
|
||||
int r, k = 0;
|
||||
|
||||
assert(dev || fd >= 0);
|
||||
|
@ -143,7 +143,6 @@ int devnode_acl_all(const char *seat,
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
_cleanup_set_free_ Set *nodes = NULL;
|
||||
_cleanup_closedir_ DIR *dir = NULL;
|
||||
sd_device *d;
|
||||
char *n;
|
||||
int r;
|
||||
|
||||
|
@ -143,7 +143,6 @@ int get_capacity_by_name(Hashmap *capacities_by_name, const char *name) {
|
||||
int fetch_batteries_capacity_by_name(Hashmap **ret) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
_cleanup_hashmap_free_ Hashmap *batteries_capacity_by_name = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@ -334,7 +333,6 @@ int estimate_battery_discharge_rate_per_hour(
|
||||
usec_t after_timestamp) {
|
||||
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
bool trunc = true;
|
||||
int r;
|
||||
|
||||
@ -394,7 +392,6 @@ int estimate_battery_discharge_rate_per_hour(
|
||||
int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
usec_t total_suspend_interval = 0;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
assert(last_capacity);
|
||||
@ -450,7 +447,6 @@ int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) {
|
||||
/* Return true if all batteries have acpi_btp support */
|
||||
int battery_trip_point_alarm_exists(void) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
|
||||
r = battery_enumerator_new(&e);
|
||||
|
@ -165,8 +165,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
|
||||
if (data->devlink) {
|
||||
const char *devlink;
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(device, devlink)
|
||||
if (path_equal(devlink, data->devlink))
|
||||
FOREACH_DEVICE_DEVLINK(device, link)
|
||||
if (path_equal(link, data->devlink))
|
||||
goto found;
|
||||
|
||||
if (sd_device_get_devname(device, &devlink) >= 0 && path_equal(devlink, data->devlink))
|
||||
|
@ -42,7 +42,6 @@ static void device_mapper_list_free(DeviceMapper **head) {
|
||||
|
||||
static int dm_list_get(DeviceMapper **head) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(head);
|
||||
|
@ -44,7 +44,6 @@ static void loopback_device_list_free(LoopbackDevice **head) {
|
||||
|
||||
static int loopback_list_get(LoopbackDevice **head) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(head);
|
||||
|
@ -44,7 +44,6 @@ static void raid_device_list_free(RaidDevice **head) {
|
||||
|
||||
static int md_list_get(RaidDevice **head) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
sd_device *d;
|
||||
int r;
|
||||
|
||||
assert(head);
|
||||
|
@ -164,7 +164,7 @@ static int builtin_keyboard(UdevEvent *event, int argc, char *argv[], bool test)
|
||||
unsigned release[1024];
|
||||
unsigned release_count = 0;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
const char *node, *key, *value;
|
||||
const char *node;
|
||||
int has_abs = -1, r;
|
||||
|
||||
r = sd_device_get_devname(dev, &node);
|
||||
|
@ -110,7 +110,6 @@ static sd_device *skip_virtio(sd_device *dev) {
|
||||
static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, char **ret_suffix) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
|
||||
const char *syspath, *name;
|
||||
sd_device *child;
|
||||
int r;
|
||||
|
||||
assert(pcidev);
|
||||
@ -619,7 +618,7 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) {
|
||||
|
||||
static int dev_devicetree_onboard(sd_device *dev, NetNames *names) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *aliases_dev = NULL, *ofnode_dev = NULL, *devicetree_dev = NULL;
|
||||
const char *alias, *ofnode_path, *ofnode_syspath, *devicetree_syspath;
|
||||
const char *ofnode_path, *ofnode_syspath, *devicetree_syspath;
|
||||
sd_device *parent;
|
||||
int r;
|
||||
|
||||
|
@ -411,11 +411,11 @@ static ssize_t udev_event_subst_format(
|
||||
}
|
||||
break;
|
||||
case FORMAT_SUBST_LINKS:
|
||||
FOREACH_DEVICE_DEVLINK(dev, val) {
|
||||
FOREACH_DEVICE_DEVLINK(dev, link) {
|
||||
if (s == dest)
|
||||
strpcpy_full(&s, l, val + STRLEN("/dev/"), &truncated);
|
||||
strpcpy_full(&s, l, link + STRLEN("/dev/"), &truncated);
|
||||
else
|
||||
strpcpyl_full(&s, l, &truncated, " ", val + STRLEN("/dev/"), NULL);
|
||||
strpcpyl_full(&s, l, &truncated, " ", link + STRLEN("/dev/"), NULL);
|
||||
if (truncated)
|
||||
break;
|
||||
}
|
||||
@ -1107,7 +1107,6 @@ static int event_execute_rules_on_remove(
|
||||
}
|
||||
|
||||
static int copy_all_tags(sd_device *d, sd_device *s) {
|
||||
const char *tag;
|
||||
int r;
|
||||
|
||||
assert(d);
|
||||
|
@ -531,7 +531,6 @@ static int device_get_devpath_by_devnum(sd_device *dev, char **ret) {
|
||||
|
||||
int udev_node_update(sd_device *dev, sd_device *dev_old) {
|
||||
_cleanup_free_ char *filename = NULL;
|
||||
const char *devlink;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
@ -577,7 +576,6 @@ int udev_node_update(sd_device *dev, sd_device *dev_old) {
|
||||
|
||||
int udev_node_remove(sd_device *dev) {
|
||||
_cleanup_free_ char *filename = NULL;
|
||||
const char *devlink;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
@ -1780,7 +1780,6 @@ static int get_property_from_string(char *line, char **ret_key, char **ret_value
|
||||
}
|
||||
|
||||
static int import_parent_into_properties(sd_device *dev, const char *filter) {
|
||||
const char *key, *val;
|
||||
sd_device *parent;
|
||||
int r;
|
||||
|
||||
@ -1896,14 +1895,11 @@ static int udev_rule_apply_token_to_event(
|
||||
|
||||
return token_match_string(token, val);
|
||||
}
|
||||
case TK_M_DEVLINK: {
|
||||
const char *val;
|
||||
|
||||
case TK_M_DEVLINK:
|
||||
FOREACH_DEVICE_DEVLINK(dev, val)
|
||||
if (token_match_string(token, strempty(startswith(val, "/dev/"))) == (token->op == OP_MATCH))
|
||||
return token->op == OP_MATCH;
|
||||
return token->op == OP_NOMATCH;
|
||||
}
|
||||
case TK_M_NAME:
|
||||
return token_match_string(token, event->name);
|
||||
case TK_M_ENV: {
|
||||
@ -1928,14 +1924,11 @@ static int udev_rule_apply_token_to_event(
|
||||
return token_match_string(token, val);
|
||||
}
|
||||
case TK_M_TAG:
|
||||
case TK_M_PARENTS_TAG: {
|
||||
const char *val;
|
||||
|
||||
case TK_M_PARENTS_TAG:
|
||||
FOREACH_DEVICE_CURRENT_TAG(dev, val)
|
||||
if (token_match_string(token, val) == (token->op == OP_MATCH))
|
||||
return token->op == OP_MATCH;
|
||||
return token->op == OP_NOMATCH;
|
||||
}
|
||||
case TK_M_SUBSYSTEM:
|
||||
case TK_M_PARENTS_SUBSYSTEM: {
|
||||
const char *val;
|
||||
|
@ -86,7 +86,7 @@ static int sysattr_compare(const SysAttr *a, const SysAttr *b) {
|
||||
|
||||
static int print_all_attributes(sd_device *device, bool is_parent) {
|
||||
_cleanup_free_ SysAttr *sysattrs = NULL;
|
||||
const char *name, *value;
|
||||
const char *value;
|
||||
size_t n_items = 0;
|
||||
int r;
|
||||
|
||||
@ -180,7 +180,7 @@ static int print_device_chain(sd_device *device) {
|
||||
}
|
||||
|
||||
static int print_record(sd_device *device, const char *prefix) {
|
||||
const char *str, *val, *subsys;
|
||||
const char *str, *subsys;
|
||||
dev_t devnum;
|
||||
uint64_t q;
|
||||
int i, ifi;
|
||||
@ -232,14 +232,16 @@ static int print_record(sd_device *device, const char *prefix) {
|
||||
printf("%sI: %s%i%s\n", prefix, ansi_highlight_cyan(), ifi, ansi_normal());
|
||||
|
||||
if (sd_device_get_devname(device, &str) >= 0) {
|
||||
const char *val;
|
||||
|
||||
assert_se(val = path_startswith(str, "/dev/"));
|
||||
printf("%sN: %s%s%s\n", prefix, ansi_highlight_cyan(), val, ansi_normal());
|
||||
|
||||
if (device_get_devlink_priority(device, &i) >= 0)
|
||||
printf("%sL: %s%i%s\n", prefix, ansi_highlight_cyan(), i, ansi_normal());
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(device, str) {
|
||||
assert_se(val = path_startswith(str, "/dev/"));
|
||||
FOREACH_DEVICE_DEVLINK(device, link) {
|
||||
assert_se(val = path_startswith(link, "/dev/"));
|
||||
printf("%sS: %s%s%s\n", prefix, ansi_highlight_cyan(), val, ansi_normal());
|
||||
}
|
||||
}
|
||||
@ -250,8 +252,8 @@ static int print_record(sd_device *device, const char *prefix) {
|
||||
if (sd_device_get_driver(device, &str) >= 0)
|
||||
printf("%sV: %s%s%s\n", prefix, ansi_highlight_yellow4(), str, ansi_normal());
|
||||
|
||||
FOREACH_DEVICE_PROPERTY(device, str, val)
|
||||
printf("%sE: %s=%s\n", prefix, str, val);
|
||||
FOREACH_DEVICE_PROPERTY(device, key, val)
|
||||
printf("%sE: %s=%s\n", prefix, key, val);
|
||||
|
||||
if (isempty(prefix))
|
||||
puts("");
|
||||
@ -425,7 +427,7 @@ static int query_device(QueryType query, sd_device* device) {
|
||||
}
|
||||
|
||||
case QUERY_SYMLINK: {
|
||||
const char *devlink, *prefix = "";
|
||||
const char *prefix = "";
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(device, devlink) {
|
||||
if (!arg_root)
|
||||
@ -448,9 +450,7 @@ static int query_device(QueryType query, sd_device* device) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QUERY_PROPERTY: {
|
||||
const char *key, *value;
|
||||
|
||||
case QUERY_PROPERTY:
|
||||
FOREACH_DEVICE_PROPERTY(device, key, value) {
|
||||
if (arg_properties && !strv_contains(arg_properties, key))
|
||||
continue;
|
||||
@ -464,7 +464,6 @@ static int query_device(QueryType query, sd_device* device) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QUERY_ALL:
|
||||
return print_record(device, NULL);
|
||||
|
@ -48,8 +48,6 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
|
||||
devpath, subsystem);
|
||||
|
||||
if (arg_show_property) {
|
||||
const char *key, *value;
|
||||
|
||||
FOREACH_DEVICE_PROPERTY(device, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
|
||||
|
@ -88,7 +88,7 @@ int test_main(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(udev_rules_freep) UdevRules *rules = NULL;
|
||||
_cleanup_(udev_event_freep) UdevEvent *event = NULL;
|
||||
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
|
||||
const char *cmd, *key, *value;
|
||||
const char *cmd;
|
||||
sigset_t mask, sigmask_orig;
|
||||
void *val;
|
||||
int r;
|
||||
|
@ -166,8 +166,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
|
||||
if (path_strv_contains(arg_devices, name))
|
||||
return check_and_exit(sd_device_monitor_get_event(monitor));
|
||||
|
||||
FOREACH_DEVICE_DEVLINK(device, name)
|
||||
if (path_strv_contains(arg_devices, name))
|
||||
FOREACH_DEVICE_DEVLINK(device, link)
|
||||
if (path_strv_contains(arg_devices, link))
|
||||
return check_and_exit(sd_device_monitor_get_event(monitor));
|
||||
|
||||
return 0;
|
||||
|
@ -1381,7 +1381,6 @@ static int synthesize_change(sd_device *dev) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
bool part_table_read;
|
||||
const char *sysname;
|
||||
sd_device *d;
|
||||
int r, k;
|
||||
|
||||
r = sd_device_get_sysname(dev, &sysname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user