From: Johannes Berg Date: Wed, 13 Apr 2016 11:45:24 +0000 (+0200) Subject: iw: fix "iw reg get" double output X-Git-Tag: v4.7~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94af668bdd6511b9d0a372542eb994ea67e8057d;p=thirdparty%2Fiw.git iw: fix "iw reg get" double output 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 Signed-off-by: Johannes Berg --- diff --git a/iw.c b/iw.c index 0f511d9..fe394b2 100644 --- 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 d91a33e..b78e21b 100644 --- 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 1dca13a..cee0b5e 100644 --- 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.");