mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
sd-netlink: minor coding style fixes
This commit is contained in:
@@ -751,7 +751,7 @@ int sd_netlink_message_read(sd_netlink_message *m, unsigned short type, size_t s
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_data(sd_netlink_message *m, unsigned short type, size_t *ret_size, void **ret_data) {
|
||||
void *attr_data, *data;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
@@ -761,6 +761,8 @@ int sd_netlink_message_read_data(sd_netlink_message *m, unsigned short type, siz
|
||||
return r;
|
||||
|
||||
if (ret_data) {
|
||||
void *data;
|
||||
|
||||
data = memdup(attr_data, r);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
@@ -776,7 +778,6 @@ int sd_netlink_message_read_data(sd_netlink_message *m, unsigned short type, siz
|
||||
|
||||
int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short type, char **data) {
|
||||
void *attr_data;
|
||||
char *str;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
@@ -790,6 +791,8 @@ int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short
|
||||
return r;
|
||||
|
||||
if (data) {
|
||||
char *str;
|
||||
|
||||
str = strndup(attr_data, r);
|
||||
if (!str)
|
||||
return -ENOMEM;
|
||||
@@ -801,8 +804,8 @@ int sd_netlink_message_read_string_strdup(sd_netlink_message *m, unsigned short
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, const char **data) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -813,7 +816,8 @@ int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, c
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if (strnlen(attr_data, r) >= (size_t) r)
|
||||
|
||||
if (strnlen(attr_data, r) >= (size_t) r)
|
||||
return -EIO;
|
||||
|
||||
if (data)
|
||||
@@ -823,8 +827,8 @@ int sd_netlink_message_read_string(sd_netlink_message *m, unsigned short type, c
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_u8(sd_netlink_message *m, unsigned short type, uint8_t *data) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -835,7 +839,8 @@ int sd_netlink_message_read_u8(sd_netlink_message *m, unsigned short type, uint8
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(uint8_t))
|
||||
|
||||
if ((size_t) r < sizeof(uint8_t))
|
||||
return -EIO;
|
||||
|
||||
if (data)
|
||||
@@ -858,7 +863,8 @@ int sd_netlink_message_read_u16(sd_netlink_message *m, unsigned short type, uint
|
||||
r = netlink_message_read_internal(m, type, &attr_data, &net_byteorder);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(uint16_t))
|
||||
|
||||
if ((size_t) r < sizeof(uint16_t))
|
||||
return -EIO;
|
||||
|
||||
if (data) {
|
||||
@@ -885,7 +891,8 @@ int sd_netlink_message_read_u32(sd_netlink_message *m, unsigned short type, uint
|
||||
r = netlink_message_read_internal(m, type, &attr_data, &net_byteorder);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(uint32_t))
|
||||
|
||||
if ((size_t) r < sizeof(uint32_t))
|
||||
return -EIO;
|
||||
|
||||
if (data) {
|
||||
@@ -899,8 +906,8 @@ int sd_netlink_message_read_u32(sd_netlink_message *m, unsigned short type, uint
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short type, struct ether_addr *data) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -911,7 +918,8 @@ int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short typ
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(struct ether_addr))
|
||||
|
||||
if ((size_t) r < sizeof(struct ether_addr))
|
||||
return -EIO;
|
||||
|
||||
if (data)
|
||||
@@ -921,8 +929,8 @@ int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short typ
|
||||
}
|
||||
|
||||
int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, struct hw_addr_data *data) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -933,7 +941,8 @@ int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, str
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if (r > HW_ADDR_MAX_SIZE)
|
||||
|
||||
if (r > HW_ADDR_MAX_SIZE)
|
||||
return -EIO;
|
||||
|
||||
if (data) {
|
||||
@@ -945,8 +954,8 @@ int netlink_message_read_hw_addr(sd_netlink_message *m, unsigned short type, str
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short type, struct ifa_cacheinfo *info) {
|
||||
int r;
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
@@ -957,7 +966,8 @@ int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short typ
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(struct ifa_cacheinfo))
|
||||
|
||||
if ((size_t) r < sizeof(struct ifa_cacheinfo))
|
||||
return -EIO;
|
||||
|
||||
if (info)
|
||||
@@ -980,7 +990,8 @@ int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short typ
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < FAMILY_ADDRESS_SIZE(family))
|
||||
|
||||
if ((size_t) r < FAMILY_ADDRESS_SIZE(family))
|
||||
return -EIO;
|
||||
|
||||
if (data)
|
||||
|
||||
@@ -81,13 +81,11 @@ int socket_bind(sd_netlink *nl) {
|
||||
|
||||
addrlen = sizeof(nl->sockaddr);
|
||||
|
||||
r = bind(nl->fd, &nl->sockaddr.sa, addrlen);
|
||||
/* ignore EINVAL to allow binding an already bound socket */
|
||||
if (r < 0 && errno != EINVAL)
|
||||
if (bind(nl->fd, &nl->sockaddr.sa, addrlen) < 0 && errno != EINVAL)
|
||||
return -errno;
|
||||
|
||||
r = getsockname(nl->fd, &nl->sockaddr.sa, &addrlen);
|
||||
if (r < 0)
|
||||
if (getsockname(nl->fd, &nl->sockaddr.sa, &addrlen) < 0)
|
||||
return -errno;
|
||||
|
||||
return broadcast_groups_get(nl);
|
||||
@@ -328,7 +326,7 @@ int socket_read_message(sd_netlink *nl) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
|
||||
size_t size;
|
||||
|
||||
if (!group && new_msg->nlmsg_pid != nl->sockaddr.nl.nl_pid)
|
||||
if (group == 0 && new_msg->nlmsg_pid != nl->sockaddr.nl.nl_pid)
|
||||
/* not broadcast and not for us */
|
||||
continue;
|
||||
|
||||
@@ -365,7 +363,7 @@ int socket_read_message(sd_netlink *nl) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
m->broadcast = !!group;
|
||||
m->broadcast = group != 0;
|
||||
|
||||
m->hdr = memdup(new_msg, new_msg->nlmsg_len);
|
||||
if (!m->hdr)
|
||||
|
||||
@@ -81,8 +81,7 @@ int sd_netlink_new_from_fd(sd_netlink **ret, int fd) {
|
||||
|
||||
addrlen = sizeof(nl->sockaddr);
|
||||
|
||||
r = getsockname(fd, &nl->sockaddr.sa, &addrlen);
|
||||
if (r < 0)
|
||||
if (getsockname(fd, &nl->sockaddr.sa, &addrlen) < 0)
|
||||
return -errno;
|
||||
|
||||
if (nl->sockaddr.nl.nl_family != AF_NETLINK)
|
||||
@@ -483,15 +482,12 @@ static int process_running(sd_netlink *nl, sd_netlink_message **ret) {
|
||||
if (!m)
|
||||
goto null_message;
|
||||
|
||||
if (sd_netlink_message_is_broadcast(m)) {
|
||||
if (sd_netlink_message_is_broadcast(m))
|
||||
r = process_match(nl, m);
|
||||
if (r != 0)
|
||||
goto null_message;
|
||||
} else {
|
||||
else
|
||||
r = process_reply(nl, m);
|
||||
if (r != 0)
|
||||
goto null_message;
|
||||
}
|
||||
if (r != 0)
|
||||
goto null_message;
|
||||
|
||||
if (ret) {
|
||||
*ret = TAKE_PTR(m);
|
||||
|
||||
Reference in New Issue
Block a user