From 7397944de6c11519a5951fc1bcff20225e71c4bd Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 13 Oct 2011 08:38:33 -0700 Subject: [PATCH] ip: fix exit codes Alternative fix to problem reported by: Bin Li The issue is came from https://bugzilla.novell.com/show_bug.cgi?id=681952. In any previous version (since suse ... 10.0?), ip addr add always returned the error code 2 in case the ip address is already set on the interface: inet 172.16.2.3/24 brd 172.16.2.255 scope global bond0 RTNETLINK answers: File exists 2 On 11.4, it returns the exit code 254: inet 172.16.1.1/24 brd 172.16.1.255 scope global eth0 RTNETLINK answers: File exists 254 This of course causes ifup to return an error in this quite common case.. --- ip/ip.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ip/ip.c b/ip/ip.c index 7f0c4688..4e609af9 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -91,31 +91,32 @@ static int do_cmd(const char *argv0, int argc, char **argv) const struct cmd *c; for (c = cmds; c->cmd; ++c) { - if (matches(argv0, c->cmd) == 0) - return c->func(argc-1, argv+1); + if (matches(argv0, c->cmd) == 0) { + return -(c->func(argc-1, argv+1)); + } } fprintf(stderr, "Object \"%s\" is unknown, try \"ip help\".\n", argv0); - return -1; + return EXIT_FAILURE; } static int batch(const char *name) { char *line = NULL; size_t len = 0; - int ret = 0; + int ret = EXIT_SUCCESS; if (name && strcmp(name, "-") != 0) { if (freopen(name, "r", stdin) == NULL) { fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n", name, strerror(errno)); - return -1; + return EXIT_FAILURE; } } if (rtnl_open(&rth, 0) < 0) { fprintf(stderr, "Cannot open rtnetlink\n"); - return -1; + return EXIT_FAILURE; } cmdlineno = 0; @@ -129,7 +130,7 @@ static int batch(const char *name) if (do_cmd(largv[0], largc, largv)) { fprintf(stderr, "Command failed %s:%d\n", name, cmdlineno); - ret = 1; + ret = EXIT_FAILURE; if (!force) break; } -- 2.39.5