]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
check return value of rtnl_send and related functions
authorStephen Hemminger <stephen@networkplumber.org>
Fri, 20 Dec 2013 16:15:02 +0000 (08:15 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 20 Dec 2013 16:24:44 +0000 (08:24 -0800)
Use warn_unused_result to enforce checking return value of rtnl_send,
and fix where the errors are.

Suggested by initial patch from Petr Písař <ppisar@redhat.com>

include/libnetlink.h
ip/iplink.c
ip/ipnetconf.c
misc/arpd.c
misc/ss.c

index ec3d6576e9ef22ae8f7091839bc14bd14a044ad4..fe7d5d386264494a09e9e928430055fe3e4d7af5 100644 (file)
@@ -22,13 +22,22 @@ struct rtnl_handle
 
 extern int rcvbuf;
 
-extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
-extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol);
+extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
+       __attribute__((warn_unused_result));
+
+extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
+                            int protocol)
+       __attribute__((warn_unused_result));
+
 extern void rtnl_close(struct rtnl_handle *rth);
-extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
+extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type)
+       __attribute__((warn_unused_result));
 extern int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type,
-                                   __u32 filt_mask);
-extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
+                                   __u32 filt_mask)
+       __attribute__((warn_unused_result));
+extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
+                            int len)
+       __attribute__((warn_unused_result));
 
 typedef int (*rtnl_filter_t)(const struct sockaddr_nl *,
                             struct nlmsghdr *n, void *);
@@ -44,9 +53,12 @@ extern int rtnl_dump_filter_l(struct rtnl_handle *rth,
 extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
                            void *arg);
 extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
-                    unsigned groups, struct nlmsghdr *answer);
-extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int);
-extern int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int);
+                    unsigned groups, struct nlmsghdr *answer)
+       __attribute__((warn_unused_result));
+extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
+       __attribute__((warn_unused_result));
+extern int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
+       __attribute__((warn_unused_result));
 
 extern int addattr(struct nlmsghdr *n, int maxlen, int type);
 extern int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
index 58b6c2032db13fd41f36b6ecc7365c1dc9b2b399..e0c14e621d633ce92b64cc92b7c5c32b437fc0a3 100644 (file)
@@ -178,7 +178,10 @@ static int iplink_have_newlink(void)
                req.n.nlmsg_type = RTM_NEWLINK;
                req.i.ifi_family = AF_UNSPEC;
 
-               rtnl_send(&rth, &req.n, req.n.nlmsg_len);
+               if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
+                       perror("request send failed");
+                       exit(1);
+               }
                rtnl_listen(&rth, accept_msg, NULL);
        }
        return have_rtnl_newlink;
index 9a77ecbf787f6515daaa30990c51938f4a21b157..37aaf450346f04df62c0e815d1582710c858c1fe 100644 (file)
@@ -161,7 +161,10 @@ static int do_show(int argc, char **argv)
                        addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
                                  &filter.ifindex, sizeof(filter.ifindex));
 
-               rtnl_send(&rth, &req.n, req.n.nlmsg_len);
+               if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
+                       perror("Can not send request");
+                       exit(1);
+               }
                rtnl_listen(&rth, print_netconf, stdout);
        } else {
 dump:
index ec9d570f86d6c8e36f48fde44aa28d2ccd1a9932..bfe7de94feb82639045bbef24c6de64c63e29289 100644 (file)
@@ -428,7 +428,11 @@ static int do_one_request(struct nlmsghdr *n)
 
 static void load_initial_table(void)
 {
-       rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH);
+       if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH) < 0) {
+               perror("dump request failed");
+               exit(1);
+       }
+               
 }
 
 static void get_kern_msg(void)
index 6f38ae7ed3524b5b5ad62e9a9e810dd8ba1ad50a..e59ca5c7611815b9fb170f2ec7b791ff6cf69564 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -996,7 +996,9 @@ static int xll_initted = 0;
 static void xll_init(void)
 {
        struct rtnl_handle rth;
-       rtnl_open(&rth, 0);
+       if (rtnl_open(&rth, 0) < 0)
+               exit(1);
+
        ll_init_map(&rth);
        rtnl_close(&rth);
        xll_initted = 1;