ipnetns: fix ip batch mode when using 'netns exec'

Since commit a05f6511f5, ip batch mode is broken when using 'netns exec' cmd.

When WIFEXITED() returns true, it means that the child exited normally, hence
we must not call exit() but just returns the status. If we call exit, the next
commands in the file file are not executed.
If WIFEXITED() returns false, we can call exit() because it means that the
child failed.

This patch partially reverts commit a05f6511f5.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
This commit is contained in:
Nicolas Dichtel 2013-08-29 14:29:07 +02:00 committed by Stephen Hemminger
parent efa4dde4c7
commit 3c61c01a66
1 changed files with 8 additions and 4 deletions

View File

@ -205,11 +205,15 @@ static int netns_exec(int argc, char **argv)
exit(1);
}
/* If child failed, propagate status */
if (WIFEXITED(status))
exit(WEXITSTATUS(status));
if (WIFEXITED(status)) {
/* ip must return the status of the child,
* but do_cmd() will add a minus to this,
* so let's add another one here to cancel it.
*/
return -WEXITSTATUS(status);
}
return 0;
exit(1);
}
}