]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipnetns: fix ip batch mode when using 'netns exec'
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Thu, 29 Aug 2013 12:29:07 +0000 (14:29 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 3 Sep 2013 15:20:16 +0000 (08:20 -0700)
Since commit a05f6511f543, 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 a05f6511f543.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
ip/ipnetns.c

index c8a47920539c7b1e355f496e8ba6acba8e25ebbe..89dda3ffd138b320437f4d9f86b23b718a52d7f6 100644 (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);
                }
        }