}
int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
- sd_rtnl *rtnl;
+ _cleanup_sd_rtnl_unref_ sd_rtnl *rtnl = NULL;
int r;
r = sd_rtnl_new(&rtnl);
return r;
rtnl->fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_ROUTE);
- if (rtnl->fd < 0) {
- r = -errno;
- sd_rtnl_unref(rtnl);
- return r;
- }
+ if (rtnl->fd < 0)
+ return -errno;
rtnl->sockaddr.nl.nl_groups = groups;
r = bind(rtnl->fd, &rtnl->sockaddr.sa, sizeof(rtnl->sockaddr));
- if (r < 0) {
- r = -errno;
- sd_rtnl_unref(rtnl);
- return r;
- }
+ if (r < 0)
+ return -errno;
*ret = rtnl;
+ rtnl = NULL;
return 0;
}
uint64_t usec,
sd_rtnl_message **ret) {
struct pollfd p[1] = {};
- sd_rtnl_message *reply;
struct timespec left;
usec_t timeout;
int r, serial;
p[0].events = POLLIN;
for (;;) {
+ _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *reply = NULL;
+
if (usec != (uint64_t) -1) {
usec_t n;
if (received_serial == serial) {
r = message_get_errno(reply);
- if (r < 0) {
- sd_rtnl_message_unref(reply);
+ if (r < 0)
return r;
- }
- if (ret)
+ if (ret) {
*ret = reply;
- else
- reply = sd_rtnl_message_unref(reply);
+ reply = NULL;
+ }
break;;
}
-
- reply = sd_rtnl_message_unref(reply);
}
}