]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
fix up some error handling
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 16:18:45 +0000 (18:18 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 16:18:45 +0000 (18:18 +0200)
iw.h
mpath.c
station.c
util.c

diff --git a/iw.h b/iw.h
index 0e2d771754090a09a66030702d1f2097c836d6cf..a7b47a2bc1ab00f1a125e77156f980f1f8d09d08 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -51,6 +51,8 @@ extern struct cmd __stop___cmd;
 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
 int mac_addr_n2a(char *mac_addr, unsigned char *arg);
 
+int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg);
+
 const char *iftype_name(enum nl80211_iftype iftype);
 
 #endif /* __IW_H */
diff --git a/mpath.c b/mpath.c
index dd634d9e9fa10ec72418e28ad4dd007768ba6df5..2e32976671382dbedd45f67e66cf00462eab2de7 100644 (file)
--- a/mpath.c
+++ b/mpath.c
@@ -36,13 +36,6 @@ static int wait_handler(struct nl_msg *msg, void *arg)
        return NL_STOP;
 }
 
-static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
-                        void *arg)
-{
-       fprintf(stderr, "nl80211 error %d\n", err->error);
-       exit(err->error);
-}
-
 static int print_mpath_handler(struct nl_msg *msg, void *arg)
 {
        struct nlattr *tb[NL80211_ATTR_MAX + 1];
@@ -248,7 +241,7 @@ static int handle_mpath_dump(struct nl80211_state *state,
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, wait_handler, &finished);
 
        nl_recvmsgs(state->nl_handle, cb);
-       err = 0;
+       err = finished;
 
        if (!finished)
                err = nl_wait_for_ack(state->nl_handle);
index 8f5e6e8e2ebd570b0d7d87fc9da5d423ccf663af..0996d0accaae01a30b701da473d3030fe7c996a5 100644 (file)
--- a/station.c
+++ b/station.c
@@ -36,13 +36,6 @@ static int wait_handler(struct nl_msg *msg, void *arg)
        return NL_STOP;
 }
 
-static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
-                        void *arg)
-{
-       fprintf(stderr, "nl80211 error %d\n", err->error);
-       exit(err->error);
-}
-
 static int print_sta_handler(struct nl_msg *msg, void *arg)
 {
        struct nlattr *tb[NL80211_ATTR_MAX + 1];
@@ -269,10 +262,11 @@ static int handle_station_dump(struct nl80211_state *state,
                goto out;
 
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_sta_handler, NULL);
+       nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &finished);
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, wait_handler, &finished);
 
        nl_recvmsgs(state->nl_handle, cb);
-       err = 0;
+       err = finished;
 
        if (!finished)
                err = nl_wait_for_ack(state->nl_handle);
diff --git a/util.c b/util.c
index 0212867a2914116869f9e42140841e1621ff7e39..b1565c5f15fdd2bdab87b9e70af6253a8abb3a85 100644 (file)
--- a/util.c
+++ b/util.c
@@ -65,3 +65,10 @@ const char *iftype_name(enum nl80211_iftype iftype)
        sprintf(modebuf, "Unknown mode (%d)", iftype);
        return modebuf;
 }
+
+int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
+{
+       int *ret = arg;
+       *ret = err->error;
+       return NL_STOP;
+}