mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-17 06:53:26 +08:00
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..
This commit is contained in:
parent
788731b320
commit
7397944de6
15
ip/ip.c
15
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user