diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-05-12 14:07:14 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-05-14 02:18:29 +0200 |
commit | 1a3caa49d757ed0b90f86d0f1c3eee55a1588e61 (patch) | |
tree | deed0a1663b26e3a83816c789f5b6059e9caba51 /src/libsystemd/sd-network | |
parent | network: move and rename network_get() -> link_get_network() (diff) | |
download | systemd-1a3caa49d757ed0b90f86d0f1c3eee55a1588e61.tar.xz systemd-1a3caa49d757ed0b90f86d0f1c3eee55a1588e61.zip |
udev,network: make link_get_type_string() return negative errno on failure
And make net_match_config() propagate the error.
Diffstat (limited to 'src/libsystemd/sd-network')
-rw-r--r-- | src/libsystemd/sd-network/network-util.c | 19 | ||||
-rw-r--r-- | src/libsystemd/sd-network/network-util.h | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/libsystemd/sd-network/network-util.c b/src/libsystemd/sd-network/network-util.c index c1d3a9f6a2..4570098388 100644 --- a/src/libsystemd/sd-network/network-util.c +++ b/src/libsystemd/sd-network/network-util.c @@ -119,24 +119,31 @@ int parse_operational_state_range(const char *str, LinkOperationalStateRange *ou return 0; } -char *link_get_type_string(sd_device *device, unsigned short iftype) { +int link_get_type_string(sd_device *device, unsigned short iftype, char **ret) { const char *t; char *p; if (device && sd_device_get_devtype(device, &t) >= 0 && - !isempty(t)) - return strdup(t); + !isempty(t)) { + p = strdup(t); + if (!p) + return -ENOMEM; + + *ret = p; + return 0; + } t = arphrd_to_name(iftype); if (!t) - return NULL; + return -ENOENT; p = strdup(t); if (!p) - return NULL; + return -ENOMEM; - return ascii_strlower(p); + *ret = ascii_strlower(p); + return 0; } const char *net_get_name_persistent(sd_device *device) { diff --git a/src/libsystemd/sd-network/network-util.h b/src/libsystemd/sd-network/network-util.h index 3bd10c42de..d33f42cfb0 100644 --- a/src/libsystemd/sd-network/network-util.h +++ b/src/libsystemd/sd-network/network-util.h @@ -76,6 +76,6 @@ typedef struct LinkOperationalStateRange { int parse_operational_state_range(const char *str, LinkOperationalStateRange *out); -char *link_get_type_string(sd_device *device, unsigned short iftype); +int link_get_type_string(sd_device *device, unsigned short iftype, char **ret); int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *result); const char *net_get_name_persistent(sd_device *device); |