sd-device: make sd_device_get_is_initialized() returns is_initialized by return value
This commit is contained in:
parent
78ffb476f2
commit
5a937ea2f6
|
@ -158,14 +158,14 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i
|
||||||
if (detect_container() <= 0) {
|
if (detect_container() <= 0) {
|
||||||
/* not in a container, udev will be around */
|
/* not in a container, udev will be around */
|
||||||
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
int initialized, r;
|
int r;
|
||||||
|
|
||||||
sprintf(ifindex_str, "n%d", ifindex);
|
sprintf(ifindex_str, "n%d", ifindex);
|
||||||
if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
|
if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
|
||||||
r = sd_device_get_is_initialized(device, &initialized);
|
r = sd_device_get_is_initialized(device);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (!initialized)
|
if (r == 0)
|
||||||
/* not yet ready */
|
/* not yet ready */
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
|
|
|
@ -458,8 +458,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
|
||||||
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
|
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
|
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
|
||||||
dev_t devnum;
|
int initialized, k;
|
||||||
int ifindex, initialized, k;
|
|
||||||
|
|
||||||
if (dent->d_name[0] == '.')
|
if (dent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
@ -478,9 +477,9 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = sd_device_get_is_initialized(device, &initialized);
|
initialized = sd_device_get_is_initialized(device);
|
||||||
if (k < 0) {
|
if (initialized < 0) {
|
||||||
r = k;
|
r = initialized;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,8 +495,8 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
|
||||||
*/
|
*/
|
||||||
if (!enumerator->match_allow_uninitialized &&
|
if (!enumerator->match_allow_uninitialized &&
|
||||||
!initialized &&
|
!initialized &&
|
||||||
(sd_device_get_devnum(device, &devnum) >= 0 ||
|
(sd_device_get_devnum(device, NULL) >= 0 ||
|
||||||
sd_device_get_ifindex(device, &ifindex) >= 0))
|
sd_device_get_ifindex(device, NULL) >= 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!match_parent(enumerator, device))
|
if (!match_parent(enumerator, device))
|
||||||
|
|
|
@ -1374,19 +1374,16 @@ static int device_read_db(sd_device *device) {
|
||||||
return device_read_db_aux(device, false);
|
return device_read_db_aux(device, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_device_get_is_initialized(sd_device *device, int *initialized) {
|
_public_ int sd_device_get_is_initialized(sd_device *device) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_return(device, -EINVAL);
|
assert_return(device, -EINVAL);
|
||||||
assert_return(initialized, -EINVAL);
|
|
||||||
|
|
||||||
r = device_read_db(device);
|
r = device_read_db(device);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
*initialized = device->is_initialized;
|
return device->is_initialized;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec) {
|
_public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ static void test_sd_device_basic(void) {
|
||||||
assert_se(r >= 0 || r == -ENOENT);
|
assert_se(r >= 0 || r == -ENOENT);
|
||||||
|
|
||||||
r = sd_device_get_devnum(d, &devnum);
|
r = sd_device_get_devnum(d, &devnum);
|
||||||
assert_se(r >= 0 || r == -ENOENT);
|
assert_se((r >= 0 && major(devnum) > 0) || r == -ENOENT);
|
||||||
|
|
||||||
r = sd_device_get_ifindex(d, &i);
|
r = sd_device_get_ifindex(d, &i);
|
||||||
assert_se((r >= 0 && i > 0) || r == -ENOENT);
|
assert_se((r >= 0 && i > 0) || r == -ENOENT);
|
||||||
|
@ -47,9 +47,9 @@ static void test_sd_device_basic(void) {
|
||||||
r = sd_device_get_sysnum(d, &val);
|
r = sd_device_get_sysnum(d, &val);
|
||||||
assert_se(r >= 0 || r == -ENOENT);
|
assert_se(r >= 0 || r == -ENOENT);
|
||||||
|
|
||||||
i = 0;
|
r = sd_device_get_is_initialized(d);
|
||||||
assert_se(sd_device_get_is_initialized(d, &i) >= 0);
|
assert_se(r >= 0);
|
||||||
if (i > 0) {
|
if (r > 0) {
|
||||||
r = sd_device_get_usec_since_initialized(d, &usec);
|
r = sd_device_get_usec_since_initialized(d, &usec);
|
||||||
assert_se(r >= 0 || r == -ENODATA);
|
assert_se(r >= 0 || r == -ENODATA);
|
||||||
}
|
}
|
||||||
|
|
|
@ -819,17 +819,17 @@ _public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_
|
||||||
* Returns: 1 if the device is set up. 0 otherwise.
|
* Returns: 1 if the device is set up. 0 otherwise.
|
||||||
**/
|
**/
|
||||||
_public_ int udev_device_get_is_initialized(struct udev_device *udev_device) {
|
_public_ int udev_device_get_is_initialized(struct udev_device *udev_device) {
|
||||||
int r, initialized;
|
int r;
|
||||||
|
|
||||||
assert_return(udev_device, -EINVAL);
|
assert_return(udev_device, -EINVAL);
|
||||||
|
|
||||||
r = sd_device_get_is_initialized(udev_device->device, &initialized);
|
r = sd_device_get_is_initialized(udev_device->device);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
errno = -r;
|
errno = -r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return initialized;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3333,8 +3333,8 @@ ipv4ll_address_fail:
|
||||||
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
int initialized, r;
|
|
||||||
Link *link;
|
Link *link;
|
||||||
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(m->rtnl);
|
assert(m->rtnl);
|
||||||
|
@ -3362,12 +3362,12 @@ int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sd_device_get_is_initialized(device, &initialized);
|
r = sd_device_get_is_initialized(device);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_link_warning_errno(link, r, "Could not determine whether the device is initialized or not: %m");
|
log_link_warning_errno(link, r, "Could not determine whether the device is initialized or not: %m");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (!initialized) {
|
if (r == 0) {
|
||||||
/* not yet ready */
|
/* not yet ready */
|
||||||
log_link_debug(link, "link pending udev initialization...");
|
log_link_debug(link, "link pending udev initialization...");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -395,7 +395,7 @@ int remove_bridge(const char *bridge_name) {
|
||||||
static int parse_interface(const char *name) {
|
static int parse_interface(const char *name) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
||||||
char ifi_str[2 + DECIMAL_STR_MAX(int)];
|
char ifi_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
int ifi, initialized, r;
|
int ifi, r;
|
||||||
|
|
||||||
ifi = (int) if_nametoindex(name);
|
ifi = (int) if_nametoindex(name);
|
||||||
if (ifi <= 0)
|
if (ifi <= 0)
|
||||||
|
@ -406,11 +406,10 @@ static int parse_interface(const char *name) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to get device for interface %s: %m", name);
|
return log_error_errno(r, "Failed to get device for interface %s: %m", name);
|
||||||
|
|
||||||
r = sd_device_get_is_initialized(d, &initialized);
|
r = sd_device_get_is_initialized(d);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to determine whether interface %s is initialized or not: %m", name);
|
return log_error_errno(r, "Failed to determine whether interface %s is initialized or not: %m", name);
|
||||||
|
if (r == 0) {
|
||||||
if (!initialized) {
|
|
||||||
log_error("Network interface %s is not initialized yet.", name);
|
log_error("Network interface %s is not initialized yet.", name);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,12 +111,12 @@ static int wait_for_initialized(
|
||||||
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
|
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
|
||||||
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
||||||
struct DeviceMonitorData data = {};
|
struct DeviceMonitorData data = {};
|
||||||
int initialized, r;
|
int r;
|
||||||
|
|
||||||
assert(device);
|
assert(device);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
if (sd_device_get_is_initialized(device, &initialized) >= 0 && initialized) {
|
if (sd_device_get_is_initialized(device) > 0) {
|
||||||
*ret = sd_device_ref(device);
|
*ret = sd_device_ref(device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ static int wait_for_initialized(
|
||||||
return log_full_errno(IN_SET(r, -ENOENT, -ENXIO, -ENODEV) ? LOG_DEBUG : LOG_ERR, r,
|
return log_full_errno(IN_SET(r, -ENOENT, -ENXIO, -ENODEV) ? LOG_DEBUG : LOG_ERR, r,
|
||||||
"Failed to open device '%s': %m", data.sysname);
|
"Failed to open device '%s': %m", data.sysname);
|
||||||
|
|
||||||
if (sd_device_get_is_initialized(d, &initialized) >= 0 && initialized) {
|
if (sd_device_get_is_initialized(d) > 0) {
|
||||||
*ret = TAKE_PTR(d);
|
*ret = TAKE_PTR(d);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ int sd_device_get_devname(sd_device *device, const char **ret);
|
||||||
int sd_device_get_sysname(sd_device *device, const char **ret);
|
int sd_device_get_sysname(sd_device *device, const char **ret);
|
||||||
int sd_device_get_sysnum(sd_device *device, const char **ret);
|
int sd_device_get_sysnum(sd_device *device, const char **ret);
|
||||||
|
|
||||||
int sd_device_get_is_initialized(sd_device *device, int *initialized);
|
int sd_device_get_is_initialized(sd_device *device);
|
||||||
int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec);
|
int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec);
|
||||||
|
|
||||||
const char *sd_device_get_tag_first(sd_device *device);
|
const char *sd_device_get_tag_first(sd_device *device);
|
||||||
|
|
Loading…
Reference in a new issue