]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: separate wait/print when waiting for an event
authorJohannes Berg <johannes.berg@intel.com>
Thu, 22 Nov 2018 12:59:03 +0000 (13:59 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 1 Feb 2019 21:58:21 +0000 (22:58 +0100)
We usually only wanted to print the event that we waited
for, but with measurements that's changing, we want to
wait for the complete event and print the results.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
connect.c
event.c
iw.h

index 4a847a11671ff550f7ee92ac34e3339d9a4938bd..3237a277dca3579c9135fa6429c1538fd78f5dc4 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -154,7 +154,10 @@ static int iw_connect(struct nl80211_state *state,
         * Alas, the kernel doesn't do that (yet).
         */
 
-       __do_listen_events(state, ARRAY_SIZE(cmds), cmds, &printargs);
+       __do_listen_events(state,
+                          ARRAY_SIZE(cmds), cmds,
+                          ARRAY_SIZE(cmds), cmds,
+                          &printargs);
        return 0;
 }
 TOPLEVEL(connect, "[-w] <SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465] [mfp:req/opt/no]",
diff --git a/event.c b/event.c
index 3945e81e57e200d7da62f0e811f6f19f25da8c0e..6c9d745bf32cd2d1b73412310f3178bb3eaa2c9c 100644 (file)
--- a/event.c
+++ b/event.c
@@ -795,8 +795,9 @@ static int print_event(struct nl_msg *msg, void *arg)
 }
 
 struct wait_event {
-       int n_cmds;
+       int n_cmds, n_prints;
        const __u32 *cmds;
+       const __u32 *prints;
        __u32 cmd;
        struct print_event_args *pargs;
 };
@@ -807,14 +808,18 @@ static int wait_event(struct nl_msg *msg, void *arg)
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
        int i;
 
-       for (i = 0; i < wait->n_cmds; i++) {
-               if (gnlh->cmd == wait->cmds[i]) {
-                       wait->cmd = gnlh->cmd;
-                       if (wait->pargs)
+       if (wait->pargs) {
+               for (i = 0; i < wait->n_prints; i++) {
+                       if (gnlh->cmd == wait->prints[i])
                                print_event(msg, wait->pargs);
                }
        }
 
+       for (i = 0; i < wait->n_cmds; i++) {
+               if (gnlh->cmd == wait->cmds[i])
+                       wait->cmd = gnlh->cmd;
+       }
+
        return NL_SKIP;
 }
 
@@ -874,6 +879,7 @@ int __prepare_listen_events(struct nl80211_state *state)
 
 __u32 __do_listen_events(struct nl80211_state *state,
                         const int n_waits, const __u32 *waits,
+                        const int n_prints, const __u32 *prints,
                         struct print_event_args *args)
 {
        struct nl_cb *cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT);
@@ -891,6 +897,8 @@ __u32 __do_listen_events(struct nl80211_state *state,
        if (n_waits && waits) {
                wait_ev.cmds = waits;
                wait_ev.n_cmds = n_waits;
+               wait_ev.prints = prints;
+               wait_ev.n_prints = n_prints;
                wait_ev.pargs = args;
                register_handler(wait_event, &wait_ev);
        } else
@@ -915,7 +923,7 @@ __u32 listen_events(struct nl80211_state *state,
        if (ret)
                return ret;
 
-       return __do_listen_events(state, n_waits, waits, NULL);
+       return __do_listen_events(state, n_waits, waits, 0, NULL, NULL);
 }
 
 static int print_events(struct nl80211_state *state,
@@ -954,7 +962,7 @@ static int print_events(struct nl80211_state *state,
        if (ret)
                return ret;
 
-       return __do_listen_events(state, 0, NULL, &args);
+       return __do_listen_events(state, 0, NULL, 0, NULL, &args);
 }
 TOPLEVEL(event, "[-t|-r] [-f]", 0, 0, CIB_NONE, print_events,
        "Monitor events from the kernel.\n"
diff --git a/iw.h b/iw.h
index 69ca3992d419514b583b03aeeff7898534b97140..16ff0765307ea3d46114e4f9939d7e716cb61f18 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -171,6 +171,7 @@ __u32 listen_events(struct nl80211_state *state,
 int __prepare_listen_events(struct nl80211_state *state);
 __u32 __do_listen_events(struct nl80211_state *state,
                         const int n_waits, const __u32 *waits,
+                        const int n_prints, const __u32 *prints,
                         struct print_event_args *args);
 
 int valid_handler(struct nl_msg *msg, void *arg);