network: use cleanup attributes

parent 9c66dc4f
...@@ -319,11 +319,9 @@ errclose: ...@@ -319,11 +319,9 @@ errclose:
return err; return err;
} }
extern int netlink_close(struct nl_handler *handler) extern void netlink_close(struct nl_handler *handler)
{ {
close(handler->fd); close_prot_errno_disarm(handler->fd);
handler->fd = -1;
return 0;
} }
int addattr(struct nlmsghdr *n, size_t maxlen, int type, const void *data, int addattr(struct nlmsghdr *n, size_t maxlen, int type, const void *data,
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include "memory_utils.h"
/* /*
* Use this as a good size to allocate generic netlink messages * Use this as a good size to allocate generic netlink messages
*/ */
...@@ -64,10 +66,9 @@ int netlink_open(struct nl_handler *handler, int protocol); ...@@ -64,10 +66,9 @@ int netlink_open(struct nl_handler *handler, int protocol);
* the handler is no longer valid * the handler is no longer valid
* *
* @handler: a handler to the netlink socket * @handler: a handler to the netlink socket
*
* Returns 0 on success, < 0 otherwise
*/ */
int netlink_close(struct nl_handler *handler); void netlink_close(struct nl_handler *handler);
define_cleanup_function(struct nl_handler *, netlink_close);
/* /*
* netlink_rcv : receive a netlink message from the kernel. * netlink_rcv : receive a netlink message from the kernel.
...@@ -231,6 +232,7 @@ void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len); ...@@ -231,6 +232,7 @@ void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len);
* @nlmsg: the netlink message to be freed * @nlmsg: the netlink message to be freed
*/ */
void nlmsg_free(struct nlmsg *nlmsg); void nlmsg_free(struct nlmsg *nlmsg);
define_cleanup_function(struct nlmsg *, nlmsg_free);
/* /*
* nlmsg_data : returns a pointer to the data contained in the netlink message * nlmsg_data : returns a pointer to the data contained in the netlink message
......
...@@ -21,9 +21,9 @@ extern int rtnetlink_open(struct rtnl_handler *handler) ...@@ -21,9 +21,9 @@ extern int rtnetlink_open(struct rtnl_handler *handler)
return netlink_open(&handler->nlh, NETLINK_ROUTE); return netlink_open(&handler->nlh, NETLINK_ROUTE);
} }
extern int rtnetlink_close(struct rtnl_handler *handler) extern void rtnetlink_close(struct rtnl_handler *handler)
{ {
return netlink_close(&handler->nlh); netlink_close(&handler->nlh);
} }
#pragma GCC diagnostic push #pragma GCC diagnostic push
......
...@@ -44,10 +44,8 @@ extern int rtnetlink_open(struct rtnl_handler *handler); ...@@ -44,10 +44,8 @@ extern int rtnetlink_open(struct rtnl_handler *handler);
* genetlink_close : close a route netlink socket * genetlink_close : close a route netlink socket
* *
* @handler: the handler of the socket to be closed * @handler: the handler of the socket to be closed
*
* Returns 0 on success, < 0 otherwise
*/ */
extern int rtnetlink_close(struct rtnl_handler *handler); extern void rtnetlink_close(struct rtnl_handler *handler);
/* /*
* rtnetlink_rcv : receive a route netlink socket, it is up * rtnetlink_rcv : receive a route netlink socket, it is up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment