From 03f8f5811ebc0f8fac1c3ccb76c14007d250bd38 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 18 Feb 2016 14:05:04 +0100 Subject: [PATCH] fix ip -force -batch to continue on errors Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1288042 Upstream Status: iproute2.git commit 42ecedd4bae53 Conflicts: Context changed due to missing other commits adding policy flags (e.g. learning_sync). commit 42ecedd4bae534fc688194a795eb4548c6530cda Author: Roopa Prabhu Date: Tue Mar 17 19:26:32 2015 -0700 fix ip -force -batch to continue on errors This patch replaces exits with returns in several iproute2 commands. This fixes `ip -batch -force` to not exit but continue on errors. $cat c.txt route del 1.2.3.0/24 dev eth0 route del 1.2.4.0/24 dev eth0 route del 1.2.5.0/24 dev eth0 route add 1.2.3.0/24 dev eth0 $ip -force -batch c.txt RTNETLINK answers: No such process Command failed c.txt:2 RTNETLINK answers: No such process Command failed c.txt:3 Reported-by: Sven-Haegar Koch Signed-off-by: Roopa Prabhu --- bridge/fdb.c | 6 +++--- bridge/link.c | 18 +++++++++--------- bridge/mdb.c | 8 ++++---- bridge/vlan.c | 4 ++-- ip/iproute.c | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index 513b3f9..b8138cb 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -287,7 +287,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) if (d == NULL || addr == NULL) { fprintf(stderr, "Device and address are required arguments.\n"); - exit(-1); + return -1; } /* Assume self */ @@ -302,7 +302,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) abuf, abuf+1, abuf+2, abuf+3, abuf+4, abuf+5) != 6) { fprintf(stderr, "Invalid mac address %s\n", addr); - exit(-1); + return -1; } addattr_l(&req.n, sizeof(req), NDA_LLADDR, abuf, ETH_ALEN); @@ -330,7 +330,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) } if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) - exit(2); + return -1; return 0; } diff --git a/bridge/link.c b/bridge/link.c index 48be938..c5e7ae5 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -268,19 +268,19 @@ static int brlink_modify(int argc, char **argv) } else if (strcmp(*argv, "guard") == 0) { NEXT_ARG(); if (!on_off("guard", &bpdu_guard, *argv)) - exit(-1); + return -1; } else if (strcmp(*argv, "hairpin") == 0) { NEXT_ARG(); if (!on_off("hairping", &hairpin, *argv)) - exit(-1); + return -1; } else if (strcmp(*argv, "fastleave") == 0) { NEXT_ARG(); if (!on_off("fastleave", &fast_leave, *argv)) - exit(-1); + return -1; } else if (strcmp(*argv, "root_block") == 0) { NEXT_ARG(); if (!on_off("root_block", &root_block, *argv)) - exit(-1); + return -1; } else if (strcmp(*argv, "cost") == 0) { NEXT_ARG(); cost = atoi(*argv); @@ -299,7 +299,7 @@ static int brlink_modify(int argc, char **argv) if (state == nstates) { fprintf(stderr, "Error: invalid STP port state\n"); - exit(-1); + return -1; } } } else if (strcmp(*argv, "hwmode") == 0) { @@ -313,7 +313,7 @@ static int brlink_modify(int argc, char **argv) fprintf(stderr, "Mode argument must be \"vepa\" or " "\"veb\".\n"); - exit(-1); + return -1; } } else { usage(); @@ -322,14 +322,14 @@ static int brlink_modify(int argc, char **argv) } if (d == NULL) { fprintf(stderr, "Device is a required argument.\n"); - exit(-1); + return -1; } req.ifm.ifi_index = ll_name_to_index(d); if (req.ifm.ifi_index == 0) { fprintf(stderr, "Cannot find bridge device \"%s\"\n", d); - exit(-1); + return -1; } /* Nested PROTINFO attribute. Contains: port flags, cost, priority and @@ -377,7 +377,7 @@ static int brlink_modify(int argc, char **argv) } if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) - exit(2); + return -1; return 0; } diff --git a/bridge/mdb.c b/bridge/mdb.c index 81d479b..ab3a792 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -145,12 +145,12 @@ static int mdb_show(int argc, char **argv) if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETMDB) < 0) { perror("Cannot send dump request"); - exit(1); + return -1; } if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) { fprintf(stderr, "Dump terminated\n"); - exit(1); + return -1; } return 0; @@ -198,7 +198,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv) if (d == NULL || grp == NULL || p == NULL) { fprintf(stderr, "Device, group address and port name are required arguments.\n"); - exit(-1); + return -1; } req.bpm.ifindex = ll_name_to_index(d); @@ -225,7 +225,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv) addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry)); if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) - exit(2); + return -1; return 0; } diff --git a/bridge/vlan.c b/bridge/vlan.c index 83c4088..ba54b0e 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -69,7 +69,7 @@ static int vlan_modify(int cmd, int argc, char **argv) if (d == NULL || vid == -1) { fprintf(stderr, "Device and VLAN ID are required arguments.\n"); - exit(-1); + return -1; } req.ifm.ifi_index = ll_name_to_index(d); @@ -96,7 +96,7 @@ static int vlan_modify(int cmd, int argc, char **argv) addattr_nest_end(&req.n, afspec); if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) - exit(2); + return -1; return 0; } diff --git a/ip/iproute.c b/ip/iproute.c index 586039d..fbe5268 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1030,7 +1030,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) req.r.rtm_family = AF_INET; if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) - exit(2); + return -1; return 0; } -- 1.8.3.1