mirror of
https://github.com/systemd/systemd
synced 2024-07-24 11:44:41 +00:00
tree-wide: use sd_device_new_from_ifindex/ifname()
This commit is contained in:
parent
bd44a727f7
commit
0ac655a63b
|
@ -167,14 +167,12 @@ int dhcp_identifier_set_iaid(
|
|||
const char *name = NULL;
|
||||
uint64_t id;
|
||||
uint32_t id32;
|
||||
int r;
|
||||
|
||||
if (detect_container() <= 0) {
|
||||
/* not in a container, udev will be around */
|
||||
char ifindex_str[1 + DECIMAL_STR_MAX(int)];
|
||||
int r;
|
||||
|
||||
xsprintf(ifindex_str, "n%d", ifindex);
|
||||
if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
|
||||
if (sd_device_new_from_ifindex(&device, ifindex) >= 0) {
|
||||
r = sd_device_get_is_initialized(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
|
|
@ -753,9 +753,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
|
|||
|
||||
links[c].needs_freeing = true;
|
||||
|
||||
char devid[2 + DECIMAL_STR_MAX(int)];
|
||||
xsprintf(devid, "n%i", links[c].ifindex);
|
||||
(void) sd_device_new_from_device_id(&links[c].sd_device, devid);
|
||||
(void) sd_device_new_from_ifindex(&links[c].sd_device, links[c].ifindex);
|
||||
|
||||
acquire_ether_link_info(&fd, &links[c]);
|
||||
acquire_wlan_link_info(&links[c]);
|
||||
|
|
|
@ -1394,7 +1394,6 @@ static int link_initialized(Link *link, sd_device *device) {
|
|||
|
||||
static int link_check_initialized(Link *link) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
@ -1404,8 +1403,7 @@ static int link_check_initialized(Link *link) {
|
|||
return link_initialized_and_synced(link);
|
||||
|
||||
/* udev should be around */
|
||||
xsprintf(ifindex_str, "n%d", link->ifindex);
|
||||
r = sd_device_new_from_device_id(&device, ifindex_str);
|
||||
r = sd_device_new_from_ifindex(&device, link->ifindex);
|
||||
if (r < 0) {
|
||||
log_link_debug_errno(link, r, "Could not find device, waiting for device initialization: %m");
|
||||
return 0;
|
||||
|
|
|
@ -467,20 +467,14 @@ int remove_bridge(const char *bridge_name) {
|
|||
|
||||
int test_network_interface_initialized(const char *name) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *d = NULL;
|
||||
int ifi, r;
|
||||
char ifi_str[2 + DECIMAL_STR_MAX(int)];
|
||||
int r;
|
||||
|
||||
if (path_is_read_only_fs("/sys"))
|
||||
return 0;
|
||||
|
||||
/* udev should be around. */
|
||||
|
||||
ifi = rtnl_resolve_interface_or_warn(NULL, name);
|
||||
if (ifi < 0)
|
||||
return ifi;
|
||||
|
||||
sprintf(ifi_str, "n%i", ifi);
|
||||
r = sd_device_new_from_device_id(&d, ifi_str);
|
||||
r = sd_device_new_from_ifname(&d, name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device %s: %m", name);
|
||||
|
||||
|
|
Loading…
Reference in a new issue