aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2016-08-17 16:11:26 -0700
committerStephen Hemminger <stephen@networkplumber.org>2016-08-17 16:17:11 -0700
commit821a7352431bc0b814aea4248d6af2bed46446d9 (patch)
treef910411450e5cfac31eaa585d2922c3e7c3df3c0
parent44d276b223d8f57c892cb0a18a1ab87917baa1ea (diff)
downloadbridge-utils-821a7352431bc0b814aea4248d6af2bed46446d9.tar.gz
brctl: better error handling
When calling brctl show with incorrect device name, the error handling was quite confusing. Before: $ brctl show nosuchdev bridge name bridge id STP enabled interfaces nosuchdev can't get info No such device After: $ brctl show nosuchdev bridge nosuchdev does not exist! $ brctl show eth0 device eth0 is not a bridge! Reported-by: Olaf Bohlen <olaf.bohlen@ewe.de>
-rw-r--r--brctl/brctl_cmd.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/brctl/brctl_cmd.c b/brctl/brctl_cmd.c
index b4ed104..5f12e6f 100644
--- a/brctl/brctl_cmd.c
+++ b/brctl/brctl_cmd.c
@@ -305,30 +305,41 @@ static int br_cmd_stp(int argc, char *const* argv)
static int br_cmd_showstp(int argc, char *const* argv)
{
struct bridge_info info;
+ const char *name = argv[1];
+
+ if (br_get_bridge_info(name, &info)) {
+ if (errno == ENODEV)
+ fprintf(stderr, "bridge %s does not exist!\n", name);
+ else
+ fprintf(stderr, "device %s is not a bridge!\n", name);
- if (br_get_bridge_info(argv[1], &info)) {
- fprintf(stderr, "%s: can't get info %s\n", argv[1],
- strerror(errno));
return 1;
}
- br_dump_info(argv[1], &info);
+ br_dump_info(name, &info);
return 0;
}
static int show_bridge(const char *name, void *arg)
{
struct bridge_info info;
-
- printf("%s\t\t", name);
- fflush(stdout);
+ static int show_header = 1;
if (br_get_bridge_info(name, &info)) {
- fprintf(stderr, "can't get info %s\n",
- strerror(errno));
+ if (errno == ENODEV)
+ fprintf(stderr, "bridge %s does not exist!\n", name);
+ else
+ fprintf(stderr, "device %s is not a bridge!\n", name);
+
return 1;
}
+ if (show_header) {
+ printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n");
+ show_header = 0;
+ }
+
+ printf("%s\t\t", name);
br_dump_bridge_id((unsigned char *)&info.bridge_id);
printf("\t%s\t\t", info.stp_enabled?"yes":"no");
@@ -338,16 +349,15 @@ static int show_bridge(const char *name, void *arg)
static int br_cmd_show(int argc, char *const* argv)
{
- int i;
+ int i, errs = 0;
- printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n");
if (argc == 1)
br_foreach_bridge(show_bridge, NULL);
else
for(i = 2; i <= argc; i++)
- show_bridge(argv[i - 1], NULL);
+ errs += show_bridge(argv[i - 1], NULL);
- return 0;
+ return errs > 0;
}
static int compare_fdbs(const void *_f0, const void *_f1)