Merge pull request #10559 from yuwata/sd-device-prototype-change

sd-device: change prototype of sd_device_get_is_initialized()
This commit is contained in:
Lennart Poettering 2018-10-30 15:36:52 +01:00 committed by GitHub
commit c1b785bb66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 47 deletions

View file

@ -158,14 +158,14 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i
if (detect_container() <= 0) {
/* not in a container, udev will be around */
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
int initialized, r;
int r;
sprintf(ifindex_str, "n%d", ifindex);
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)
return r;
if (!initialized)
if (r == 0)
/* not yet ready */
return -EBUSY;

View file

@ -458,8 +458,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
dev_t devnum;
int ifindex, initialized, k;
int initialized, k;
if (dent->d_name[0] == '.')
continue;
@ -478,9 +477,9 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
continue;
}
k = sd_device_get_is_initialized(device, &initialized);
if (k < 0) {
r = k;
initialized = sd_device_get_is_initialized(device);
if (initialized < 0) {
r = initialized;
continue;
}
@ -496,8 +495,8 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
*/
if (!enumerator->match_allow_uninitialized &&
!initialized &&
(sd_device_get_devnum(device, &devnum) >= 0 ||
sd_device_get_ifindex(device, &ifindex) >= 0))
(sd_device_get_devnum(device, NULL) >= 0 ||
sd_device_get_ifindex(device, NULL) >= 0))
continue;
if (!match_parent(enumerator, device))

View file

@ -271,7 +271,6 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
int r;
assert(device);
assert(mode);
r = device_read_db(device);
if (r < 0)
@ -280,7 +279,8 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
if (device->devmode == (mode_t) -1)
return -ENOENT;
*mode = device->devmode;
if (mode)
*mode = device->devmode;
return 0;
}
@ -289,7 +289,6 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
int r;
assert(device);
assert(uid);
r = device_read_db(device);
if (r < 0)
@ -298,7 +297,8 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
if (device->devuid == (uid_t) -1)
return -ENOENT;
*uid = device->devuid;
if (uid)
*uid = device->devuid;
return 0;
}
@ -327,7 +327,6 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
int r;
assert(device);
assert(gid);
r = device_read_db(device);
if (r < 0)
@ -336,7 +335,8 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
if (device->devgid == (gid_t) -1)
return -ENOENT;
*gid = device->devgid;
if (gid)
*gid = device->devgid;
return 0;
}
@ -726,7 +726,6 @@ int device_get_watch_handle(sd_device *device, int *handle) {
int r;
assert(device);
assert(handle);
r = device_read_db(device);
if (r < 0)
@ -735,7 +734,8 @@ int device_get_watch_handle(sd_device *device, int *handle) {
if (device->watch_handle < 0)
return -ENOENT;
*handle = device->watch_handle;
if (handle)
*handle = device->watch_handle;
return 0;
}

View file

@ -572,7 +572,6 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
int r;
assert_return(device, -EINVAL);
assert_return(ifindex, -EINVAL);
r = device_read_uevent_file(device);
if (r < 0)
@ -581,7 +580,8 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
if (device->ifindex <= 0)
return -ENOENT;
*ifindex = device->ifindex;
if (ifindex)
*ifindex = device->ifindex;
return 0;
}
@ -889,7 +889,6 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
int r;
assert_return(device, -EINVAL);
assert_return(devnum, -EINVAL);
r = device_read_uevent_file(device);
if (r < 0)
@ -898,7 +897,8 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
if (major(device->devnum) <= 0)
return -ENOENT;
*devnum = device->devnum;
if (devnum)
*devnum = device->devnum;
return 0;
}
@ -1374,19 +1374,16 @@ static int device_read_db(sd_device *device) {
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;
assert_return(device, -EINVAL);
assert_return(initialized, -EINVAL);
r = device_read_db(device);
if (r < 0)
return r;
*initialized = device->is_initialized;
return 0;
return device->is_initialized;
}
_public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec) {
@ -1677,7 +1674,6 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
assert_return(device, -EINVAL);
assert_return(key, -EINVAL);
assert_return(_value, -EINVAL);
r = device_properties_prepare(device);
if (r < 0)
@ -1687,7 +1683,8 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
if (!value)
return -ENOENT;
*_value = value;
if (_value)
*_value = value;
return 0;
}

View file

@ -29,7 +29,7 @@ static void test_sd_device_basic(void) {
assert_se(r >= 0 || r == -ENOENT);
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);
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);
assert_se(r >= 0 || r == -ENOENT);
i = 0;
assert_se(sd_device_get_is_initialized(d, &i) >= 0);
if (i > 0) {
r = sd_device_get_is_initialized(d);
assert_se(r >= 0);
if (r > 0) {
r = sd_device_get_usec_since_initialized(d, &usec);
assert_se(r >= 0 || r == -ENODATA);
}

View file

@ -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.
**/
_public_ int udev_device_get_is_initialized(struct udev_device *udev_device) {
int r, initialized;
int r;
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) {
errno = -r;
return 0;
}
return initialized;
return r;
}
/**

View file

@ -3333,8 +3333,8 @@ ipv4ll_address_fail:
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
int initialized, r;
Link *link;
int r;
assert(m);
assert(m->rtnl);
@ -3362,12 +3362,12 @@ int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
goto failed;
}
r = sd_device_get_is_initialized(device, &initialized);
r = sd_device_get_is_initialized(device);
if (r < 0) {
log_link_warning_errno(link, r, "Could not determine whether the device is initialized or not: %m");
goto failed;
}
if (!initialized) {
if (r == 0) {
/* not yet ready */
log_link_debug(link, "link pending udev initialization...");
return 0;

View file

@ -395,7 +395,7 @@ int remove_bridge(const char *bridge_name) {
static int parse_interface(const char *name) {
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
char ifi_str[2 + DECIMAL_STR_MAX(int)];
int ifi, initialized, r;
int ifi, r;
ifi = (int) if_nametoindex(name);
if (ifi <= 0)
@ -406,11 +406,10 @@ static int parse_interface(const char *name) {
if (r < 0)
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)
return log_error_errno(r, "Failed to determine whether interface %s is initialized or not: %m", name);
if (!initialized) {
if (r == 0) {
log_error("Network interface %s is not initialized yet.", name);
return -EBUSY;
}

View file

@ -111,12 +111,12 @@ static int wait_for_initialized(
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
struct DeviceMonitorData data = {};
int initialized, r;
int r;
assert(device);
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);
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,
"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);
return 0;
}

View file

@ -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_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);
const char *sd_device_get_tag_first(sd_device *device);