]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: fix "iw reg get" double output
authorJohannes Berg <johannes.berg@intel.com>
Wed, 13 Apr 2016 11:45:24 +0000 (13:45 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 13 Apr 2016 11:48:17 +0000 (13:48 +0200)
Axel reports that running "iw reg get" results in the (global)
output being printed twice. The reason for this is that we try
to use the dump facility, and if that succeeds we also do the
get command.

To prevent this, allow handlers to return HANDLER_RET_DONE, in
which case the command will be treated as successful but will
not actually execute another netlink command.

Reported-by: Axel Köllhofer <AxelKoellhofer@web.de>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
iw.c
iw.h
reg.c

diff --git a/iw.c b/iw.c
index 0f511d98f2e1e151648a14aa7d830ce995964716..fe394b2be74b76387a31319b3b6abfedee9bcd9e 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -575,6 +575,8 @@ int main(int argc, char **argv)
                        usage_cmd(cmd);
                else
                        usage(0, NULL);
+       } else if (err == HANDLER_RET_DONE) {
+               err = 0;
        } else if (err < 0)
                fprintf(stderr, "command failed: %s (%d)\n", strerror(-err), err);
 
diff --git a/iw.h b/iw.h
index d91a33ec1f3c65bfa8781dae25c3d8b8b69dbb70..b78e21b1aac8b0fec5822a1dac1218e71274f9a4 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -38,6 +38,8 @@ enum id_input {
        II_WDEV,
 };
 
+#define HANDLER_RET_DONE 3
+
 struct cmd {
        const char *name;
        const char *args;
diff --git a/reg.c b/reg.c
index 1dca13a35d50294f2c0c57eea13d48ed780332cb..cee0b5e8cedbe09d1908965e8426f5f6c58b33db 100644 (file)
--- a/reg.c
+++ b/reg.c
@@ -244,14 +244,14 @@ static int handle_reg_get(struct nl80211_state *state,
        int err;
 
        err = handle_cmd(state, CIB_NONE, 2, dump_args);
-       /* dump might fail since it's not supported on older kernels */
-       if (err == -EOPNOTSUPP) {
-               register_handler(print_reg_handler,
-                         NULL);
+       /*
+        * dump might fail since it's not supported on older kernels,
+        * in that case the handler is still registered already
+        */
+       if (err == -EOPNOTSUPP)
                return 0;
-       }
 
-       return err;
+       return err ?: HANDLER_RET_DONE;
 }
 COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_NONE, handle_reg_get,
        "Print out the kernel's current regulatory domain information.");