netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec'
@ 2013-08-27  7:25 Nicolas Dichtel
  2013-08-28  8:13 ` Cong Wang
  2013-08-29 12:29 ` [PATCH iproute2 v2] " Nicolas Dichtel
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2013-08-27  7:25 UTC (permalink / raw)
  To: shemminger; +Cc: netdev, Nicolas Dichtel

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 | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index c8a47920539c..11dd9b89e503 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -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 returns 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);
 		}
 	}
 
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec'
  2013-08-27  7:25 [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec' Nicolas Dichtel
@ 2013-08-28  8:13 ` Cong Wang
  2013-08-29 12:26   ` Nicolas Dichtel
  2013-08-29 12:29 ` [PATCH iproute2 v2] " Nicolas Dichtel
  1 sibling, 1 reply; 4+ messages in thread
From: Cong Wang @ 2013-08-28  8:13 UTC (permalink / raw)
  To: netdev

On Tue, 27 Aug 2013 at 07:25 GMT, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
>  
> -			/* If child failed, propagate status */
> -			if (WIFEXITED(status))
> -				exit(WEXITSTATUS(status));
> +			if (WIFEXITED(status)) {
> +				/* ip must returns the status of the child,

s/returns/return/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec'
  2013-08-28  8:13 ` Cong Wang
@ 2013-08-29 12:26   ` Nicolas Dichtel
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2013-08-29 12:26 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev

Le 28/08/2013 10:13, Cong Wang a écrit :
> On Tue, 27 Aug 2013 at 07:25 GMT, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
>>
>> -			/* If child failed, propagate status */
>> -			if (WIFEXITED(status))
>> -				exit(WEXITSTATUS(status));
>> +			if (WIFEXITED(status)) {
>> +				/* ip must returns the status of the child,
>
> s/returns/return/

Thank you, but please keep all email addresses in cc next time, at least the author!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2 v2] ipnetns: fix ip batch mode when using 'netns exec'
  2013-08-27  7:25 [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec' Nicolas Dichtel
  2013-08-28  8:13 ` Cong Wang
@ 2013-08-29 12:29 ` Nicolas Dichtel
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2013-08-29 12:29 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: shemminger, netdev, Nicolas Dichtel

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>
---

v2: fix a typo in a comment

 ip/ipnetns.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index c8a47920539c..89dda3ffd138 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -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);
 		}
 	}
 
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-29 12:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-27  7:25 [PATCH iproute2] ipnetns: fix ip batch mode when using 'netns exec' Nicolas Dichtel
2013-08-28  8:13 ` Cong Wang
2013-08-29 12:26   ` Nicolas Dichtel
2013-08-29 12:29 ` [PATCH iproute2 v2] " Nicolas Dichtel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).