* [PATCH iproute2 v2] ipbatch: fix use of 'ip netns exec'
[not found] <20130705141639.56b47e7e@samsung-9>
@ 2013-07-08 9:44 ` Nicolas Dichtel
2013-07-08 23:36 ` Ben Hutchings
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Dichtel @ 2013-07-08 9:44 UTC (permalink / raw)
To: shemminger; +Cc: netdev, junwei.zhang, bhutchings, Nicolas Dichtel
From: JunweiZhang <junwei.zhang@6wind.com>
execvp() does not return when the command succeed, hence all commands in the
batch file after the line 'ip netns exec' are not executed.
Let's fork before calling execvp().
Example:
$ cat test.batch
netns add netns1
netns exec netns1 ip l
netns
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
All command after 'netns exec' are never executed.
With the patch:
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
netns1
Now, existing netns are displayed.
Signed-off-by: JunweiZhang <junwei.zhang@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
v2: keep exit status of the child
add an example in the commit log
ip/ipnetns.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index fa2b681..9f401ca 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -138,6 +138,7 @@ static int netns_exec(int argc, char **argv)
const char *name, *cmd;
char net_path[MAXPATHLEN];
int netns;
+ int pid, status;
if (argc < 1) {
fprintf(stderr, "No netns name specified\n");
@@ -185,10 +186,23 @@ static int netns_exec(int argc, char **argv)
/* Setup bind mounts for config files in /etc */
bind_etc(name);
- if (execvp(cmd, argv + 1) < 0)
- fprintf(stderr, "exec of \"%s\" failed: %s\n",
- cmd, strerror(errno));
- return EXIT_FAILURE;
+ pid = fork();
+ if (pid < 0)
+ return EXIT_FAILURE;
+ else if (pid > 0)
+ waitpid(pid, &status, 0);
+ else {
+ /* Child */
+ if (execvp(cmd, argv + 1) < 0)
+ fprintf(stderr, "exec of \"%s\" failed: %s\n",
+ cmd, strerror(errno));
+ return EXIT_FAILURE;
+ }
+ /* ip must returns the status of the child, but do_cmd() will add a
+ * minus to this returned value, so let's add another one here to
+ * cancel it.
+ */
+ return -WEXITSTATUS(status);
}
static int is_pid(const char *str)
--
1.8.2.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v2] ipbatch: fix use of 'ip netns exec'
2013-07-08 9:44 ` [PATCH iproute2 v2] ipbatch: fix use of 'ip netns exec' Nicolas Dichtel
@ 2013-07-08 23:36 ` Ben Hutchings
2013-07-09 10:26 ` [PATCH iproute2 v3] " Nicolas Dichtel
0 siblings, 1 reply; 9+ messages in thread
From: Ben Hutchings @ 2013-07-08 23:36 UTC (permalink / raw)
To: Nicolas Dichtel; +Cc: shemminger, netdev, junwei.zhang
On Mon, 2013-07-08 at 11:44 +0200, Nicolas Dichtel wrote:
[...]
> --- a/ip/ipnetns.c
> +++ b/ip/ipnetns.c
> @@ -138,6 +138,7 @@ static int netns_exec(int argc, char **argv)
> const char *name, *cmd;
> char net_path[MAXPATHLEN];
> int netns;
> + int pid, status;
>
> if (argc < 1) {
> fprintf(stderr, "No netns name specified\n");
> @@ -185,10 +186,23 @@ static int netns_exec(int argc, char **argv)
> /* Setup bind mounts for config files in /etc */
> bind_etc(name);
>
> - if (execvp(cmd, argv + 1) < 0)
> - fprintf(stderr, "exec of \"%s\" failed: %s\n",
> - cmd, strerror(errno));
> - return EXIT_FAILURE;
> + pid = fork();
> + if (pid < 0)
> + return EXIT_FAILURE;
On failure, this should emit an error message:
perror("fork");
and then return -1, surely?
> + else if (pid > 0)
> + waitpid(pid, &status, 0);
> + else {
> + /* Child */
> + if (execvp(cmd, argv + 1) < 0)
> + fprintf(stderr, "exec of \"%s\" failed: %s\n",
> + cmd, strerror(errno));
> + return EXIT_FAILURE;
No, the child must not return from this function. Otherwise there will
be two processes trying to do the same cleanup on the resources that
they still share. The child should call _exit(127) if exec*() fails.
> + }
> + /* ip must returns the status of the child, but do_cmd() will add a
> + * minus to this returned value, so let's add another one here to
> + * cancel it.
> + */
> + return -WEXITSTATUS(status);
> }
>
> static int is_pid(const char *str)
WEXITSTATUS() is valid only if waitpid() was successful and WIFEXITED()
yields true.
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH iproute2 v3] ipbatch: fix use of 'ip netns exec'
2013-07-08 23:36 ` Ben Hutchings
@ 2013-07-09 10:26 ` Nicolas Dichtel
2013-07-09 13:20 ` Eric Dumazet
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Dichtel @ 2013-07-09 10:26 UTC (permalink / raw)
To: bhutchings; +Cc: shemminger, netdev, junwei.zhang, Nicolas Dichtel
From: JunweiZhang <junwei.zhang@6wind.com>
execvp() does not return when the command succeed, hence all commands in the
batch file after the line 'ip netns exec' are not executed.
Let's fork before calling execvp().
Example:
$ cat test.batch
netns add netns1
netns exec netns1 ip l
netns
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
All command after 'netns exec' are never executed.
With the patch:
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
netns1
Now, existing netns are displayed.
Signed-off-by: JunweiZhang <junwei.zhang@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
v3: be more verbose on error (fork(), waitpid())
when child fails, just exit to avoid double cleanning
check WIFEXITED() and waitpid() before using WEXITSTATUS()
v2: keep exit status of the child
add an example in the commit log
ip/ipnetns.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index fa2b681..474a296 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -138,6 +138,7 @@ static int netns_exec(int argc, char **argv)
const char *name, *cmd;
char net_path[MAXPATHLEN];
int netns;
+ int pid, status;
if (argc < 1) {
fprintf(stderr, "No netns name specified\n");
@@ -185,9 +186,32 @@ static int netns_exec(int argc, char **argv)
/* Setup bind mounts for config files in /etc */
bind_etc(name);
- if (execvp(cmd, argv + 1) < 0)
- fprintf(stderr, "exec of \"%s\" failed: %s\n",
- cmd, strerror(errno));
+ pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ return EXIT_FAILURE;
+ } else if (pid == 0) {
+ /* Child */
+ if (execvp(cmd, argv + 1) < 0)
+ fprintf(stderr, "exec of \"%s\" failed: %s\n",
+ cmd, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ /* Parent */
+ if (waitpid(pid, &status, 0) < 0) {
+ perror("waitpid");
+ return EXIT_FAILURE;
+ }
+
+ if (WIFEXITED(status)) {
+ /* ip must returns the status of the child, but do_cmd() will
+ * add a minus to this returned value, so let's add another one
+ * here to cancel it.
+ */
+ return -WEXITSTATUS(status);
+ }
+
return EXIT_FAILURE;
}
--
1.8.2.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v3] ipbatch: fix use of 'ip netns exec'
2013-07-09 10:26 ` [PATCH iproute2 v3] " Nicolas Dichtel
@ 2013-07-09 13:20 ` Eric Dumazet
2013-07-09 15:55 ` [PATCH iproute2 v4] " Nicolas Dichtel
0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2013-07-09 13:20 UTC (permalink / raw)
To: Nicolas Dichtel; +Cc: bhutchings, shemminger, netdev, junwei.zhang
On Tue, 2013-07-09 at 12:26 +0200, Nicolas Dichtel wrote:
> From: JunweiZhang <junwei.zhang@6wind.com>
>
> execvp() does not return when the command succeed, hence all commands in the
> batch file after the line 'ip netns exec' are not executed.
>
> Let's fork before calling execvp().
>
> Example:
> $ cat test.batch
> netns add netns1
> netns exec netns1 ip l
> netns
> $ ip -b test.batch
> 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> 2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
> link/sit 0.0.0.0 brd 0.0.0.0
>
> All command after 'netns exec' are never executed.
>
> With the patch:
> $ ip -b test.batch
> 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> 2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
> link/sit 0.0.0.0 brd 0.0.0.0
> netns1
>
> Now, existing netns are displayed.
>
> Signed-off-by: JunweiZhang <junwei.zhang@6wind.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>
> v3: be more verbose on error (fork(), waitpid())
> when child fails, just exit to avoid double cleanning
> check WIFEXITED() and waitpid() before using WEXITSTATUS()
>
> v2: keep exit status of the child
> add an example in the commit log
>
> ip/ipnetns.c | 30 +++++++++++++++++++++++++++---
> 1 file changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
> index fa2b681..474a296 100644
> --- a/ip/ipnetns.c
> +++ b/ip/ipnetns.c
> @@ -138,6 +138,7 @@ static int netns_exec(int argc, char **argv)
> const char *name, *cmd;
> char net_path[MAXPATHLEN];
> int netns;
> + int pid, status;
pid_t pid;
>
> if (argc < 1) {
> fprintf(stderr, "No netns name specified\n");
> @@ -185,9 +186,32 @@ static int netns_exec(int argc, char **argv)
> /* Setup bind mounts for config files in /etc */
> bind_etc(name);
>
> - if (execvp(cmd, argv + 1) < 0)
> - fprintf(stderr, "exec of \"%s\" failed: %s\n",
> - cmd, strerror(errno));
> + pid = fork();
> + if (pid < 0) {
> + perror("fork");
> + return EXIT_FAILURE;
> + } else if (pid == 0) {
> + /* Child */
> + if (execvp(cmd, argv + 1) < 0)
> + fprintf(stderr, "exec of \"%s\" failed: %s\n",
> + cmd, strerror(errno));
> + exit(EXIT_FAILURE);
_exit(EXIT_FAILURE);
Or else you could have buffered data in stdout buffer, and it will be
emitted twice.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH iproute2 v4] ipbatch: fix use of 'ip netns exec'
2013-07-09 13:20 ` Eric Dumazet
@ 2013-07-09 15:55 ` Nicolas Dichtel
2013-07-09 16:19 ` Ben Hutchings
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Dichtel @ 2013-07-09 15:55 UTC (permalink / raw)
To: eric.dumazet, shemminger
Cc: netdev, junwei.zhang, bhutchings, Nicolas Dichtel
From: JunweiZhang <junwei.zhang@6wind.com>
execvp() does not return when the command succeed, hence all commands in the
batch file after the line 'ip netns exec' are not executed.
Let's fork before calling execvp() if batch mode is used..
Example:
$ cat test.batch
netns add netns1
netns exec netns1 ip l
netns
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
All command after 'netns exec' are never executed.
With the patch:
$ ip -b test.batch
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT
link/sit 0.0.0.0 brd 0.0.0.0
netns1
Now, existing netns are displayed.
Signed-off-by: JunweiZhang <junwei.zhang@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
v4: use pid_t type for pid
use _exit() instead of exit()
fork only if batch is used
v3: be more verbose on error (fork(), waitpid())
when child fails, just exit to avoid double cleanning
check WIFEXITED() and waitpid() before using WEXITSTATUS()
v2: keep exit status of the child
add an example in the commit log
ip/ipnetns.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index fa2b681..cdc3101 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -42,6 +42,7 @@
#define MS_SHARED (1 << 20)
#endif
+extern char *batch_file;
#ifndef HAVE_SETNS
static int setns(int fd, int nstype)
@@ -185,6 +186,42 @@ static int netns_exec(int argc, char **argv)
/* Setup bind mounts for config files in /etc */
bind_etc(name);
+ if (batch_file) {
+ int status;
+ pid_t pid;
+
+ pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ return EXIT_FAILURE;
+ }
+
+ if (pid == 0) {
+ /* Child */
+ if (execvp(cmd, argv + 1) < 0)
+ fprintf(stderr, "exec of \"%s\" failed: %s\n",
+ cmd, strerror(errno));
+
+ _exit(EXIT_FAILURE);
+ }
+
+ /* Parent */
+ if (waitpid(pid, &status, 0) < 0) {
+ perror("waitpid");
+ return EXIT_FAILURE;
+ }
+
+ if (WIFEXITED(status)) {
+ /* ip must returns the status of the child, but do_cmd()
+ * will add a minus to this returned value, so let's add
+ * another one here to cancel it.
+ */
+ return -WEXITSTATUS(status);
+ }
+
+ return EXIT_FAILURE;
+ }
+
if (execvp(cmd, argv + 1) < 0)
fprintf(stderr, "exec of \"%s\" failed: %s\n",
cmd, strerror(errno));
--
1.8.2.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v4] ipbatch: fix use of 'ip netns exec'
2013-07-09 15:55 ` [PATCH iproute2 v4] " Nicolas Dichtel
@ 2013-07-09 16:19 ` Ben Hutchings
2013-07-09 16:59 ` Nicolas Dichtel
0 siblings, 1 reply; 9+ messages in thread
From: Ben Hutchings @ 2013-07-09 16:19 UTC (permalink / raw)
To: Nicolas Dichtel; +Cc: eric.dumazet, shemminger, netdev, junwei.zhang
On Tue, 2013-07-09 at 17:55 +0200, Nicolas Dichtel wrote:
[...]
> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
> index fa2b681..cdc3101 100644
> --- a/ip/ipnetns.c
> +++ b/ip/ipnetns.c
> @@ -42,6 +42,7 @@
> #define MS_SHARED (1 << 20)
> #endif
>
> +extern char *batch_file;
Should be declared in a header file.
> #ifndef HAVE_SETNS
> static int setns(int fd, int nstype)
> @@ -185,6 +186,42 @@ static int netns_exec(int argc, char **argv)
> /* Setup bind mounts for config files in /etc */
> bind_etc(name);
>
> + if (batch_file) {
> + int status;
> + pid_t pid;
> +
> + pid = fork();
> + if (pid < 0) {
> + perror("fork");
> + return EXIT_FAILURE;
return -1;
> + }
> +
> + if (pid == 0) {
> + /* Child */
> + if (execvp(cmd, argv + 1) < 0)
> + fprintf(stderr, "exec of \"%s\" failed: %s\n",
> + cmd, strerror(errno));
> +
> + _exit(EXIT_FAILURE);
> + }
> +
> + /* Parent */
> + if (waitpid(pid, &status, 0) < 0) {
> + perror("waitpid");
> + return EXIT_FAILURE;
return -1;
> + }
> +
> + if (WIFEXITED(status)) {
> + /* ip must returns the status of the child, but do_cmd()
> + * will add a minus to this returned value, so let's add
> + * another one here to cancel it.
> + */
> + return -WEXITSTATUS(status);
> + }
> +
> + return EXIT_FAILURE;
return -1;
> + }
> +
> if (execvp(cmd, argv + 1) < 0)
> fprintf(stderr, "exec of \"%s\" failed: %s\n",
> cmd, strerror(errno));
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v4] ipbatch: fix use of 'ip netns exec'
2013-07-09 16:19 ` Ben Hutchings
@ 2013-07-09 16:59 ` Nicolas Dichtel
2013-07-09 18:13 ` Ben Hutchings
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Dichtel @ 2013-07-09 16:59 UTC (permalink / raw)
To: Ben Hutchings; +Cc: eric.dumazet, shemminger, netdev, junwei.zhang
Le 09/07/2013 18:19, Ben Hutchings a écrit :
> On Tue, 2013-07-09 at 17:55 +0200, Nicolas Dichtel wrote:
> [...]
>> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
>> index fa2b681..cdc3101 100644
>> --- a/ip/ipnetns.c
>> +++ b/ip/ipnetns.c
>> @@ -42,6 +42,7 @@
>> #define MS_SHARED (1 << 20)
>> #endif
>>
>> +extern char *batch_file;
I let Stephen choose, he suggest me this.
>
> Should be declared in a header file.
>
>> #ifndef HAVE_SETNS
>> static int setns(int fd, int nstype)
>> @@ -185,6 +186,42 @@ static int netns_exec(int argc, char **argv)
>> /* Setup bind mounts for config files in /etc */
>> bind_etc(name);
>>
>> + if (batch_file) {
>> + int status;
>> + pid_t pid;
>> +
>> + pid = fork();
>> + if (pid < 0) {
>> + perror("fork");
>> + return EXIT_FAILURE;
>
> return -1;
man exit says:
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-UNIX
environments) than the use of 0 and some nonzero value like 1 or -1.
And in fact, it was so before my patch.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v4] ipbatch: fix use of 'ip netns exec'
2013-07-09 16:59 ` Nicolas Dichtel
@ 2013-07-09 18:13 ` Ben Hutchings
2013-07-10 9:52 ` Nicolas Dichtel
0 siblings, 1 reply; 9+ messages in thread
From: Ben Hutchings @ 2013-07-09 18:13 UTC (permalink / raw)
To: nicolas.dichtel; +Cc: eric.dumazet, shemminger, netdev, junwei.zhang
On Tue, 2013-07-09 at 18:59 +0200, Nicolas Dichtel wrote:
> Le 09/07/2013 18:19, Ben Hutchings a écrit :
> > On Tue, 2013-07-09 at 17:55 +0200, Nicolas Dichtel wrote:
> > [...]
> >> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
> >> index fa2b681..cdc3101 100644
> >> --- a/ip/ipnetns.c
> >> +++ b/ip/ipnetns.c
> >> @@ -42,6 +42,7 @@
> >> #define MS_SHARED (1 << 20)
> >> #endif
> >>
> >> +extern char *batch_file;
> I let Stephen choose, he suggest me this.
>
> >
> > Should be declared in a header file.
> >
> >> #ifndef HAVE_SETNS
> >> static int setns(int fd, int nstype)
> >> @@ -185,6 +186,42 @@ static int netns_exec(int argc, char **argv)
> >> /* Setup bind mounts for config files in /etc */
> >> bind_etc(name);
> >>
> >> + if (batch_file) {
> >> + int status;
> >> + pid_t pid;
> >> +
> >> + pid = fork();
> >> + if (pid < 0) {
> >> + perror("fork");
> >> + return EXIT_FAILURE;
> >
> > return -1;
> man exit says:
> The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-UNIX
> environments) than the use of 0 and some nonzero value like 1 or -1.
>
> And in fact, it was so before my patch.
As your own earlier comment says, do_cmd() negates the return value.
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH iproute2 v4] ipbatch: fix use of 'ip netns exec'
2013-07-09 18:13 ` Ben Hutchings
@ 2013-07-10 9:52 ` Nicolas Dichtel
0 siblings, 0 replies; 9+ messages in thread
From: Nicolas Dichtel @ 2013-07-10 9:52 UTC (permalink / raw)
To: Ben Hutchings; +Cc: eric.dumazet, shemminger, netdev, junwei.zhang
Le 09/07/2013 20:13, Ben Hutchings a écrit :
> On Tue, 2013-07-09 at 18:59 +0200, Nicolas Dichtel wrote:
>> Le 09/07/2013 18:19, Ben Hutchings a écrit :
>>> On Tue, 2013-07-09 at 17:55 +0200, Nicolas Dichtel wrote:
>>> [...]
>>>> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
>>>> index fa2b681..cdc3101 100644
>>>> --- a/ip/ipnetns.c
>>>> +++ b/ip/ipnetns.c
>>>> @@ -42,6 +42,7 @@
>>>> #define MS_SHARED (1 << 20)
>>>> #endif
>>>>
>>>> +extern char *batch_file;
>> I let Stephen choose, he suggest me this.
>>
>>>
>>> Should be declared in a header file.
>>>
>>>> #ifndef HAVE_SETNS
>>>> static int setns(int fd, int nstype)
>>>> @@ -185,6 +186,42 @@ static int netns_exec(int argc, char **argv)
>>>> /* Setup bind mounts for config files in /etc */
>>>> bind_etc(name);
>>>>
>>>> + if (batch_file) {
>>>> + int status;
>>>> + pid_t pid;
>>>> +
>>>> + pid = fork();
>>>> + if (pid < 0) {
>>>> + perror("fork");
>>>> + return EXIT_FAILURE;
>>>
>>> return -1;
>> man exit says:
>> The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-UNIX
>> environments) than the use of 0 and some nonzero value like 1 or -1.
>>
>> And in fact, it was so before my patch.
>
> As your own earlier comment says, do_cmd() negates the return value.
Yes, but EXIT_FAILURE is used everywhere in ip/ipnetns.c.
Stephen, should I send a patch to replace use of EXIT_FAILURE by -1 in ipnetns.c?
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-07-10 9:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20130705141639.56b47e7e@samsung-9>
2013-07-08 9:44 ` [PATCH iproute2 v2] ipbatch: fix use of 'ip netns exec' Nicolas Dichtel
2013-07-08 23:36 ` Ben Hutchings
2013-07-09 10:26 ` [PATCH iproute2 v3] " Nicolas Dichtel
2013-07-09 13:20 ` Eric Dumazet
2013-07-09 15:55 ` [PATCH iproute2 v4] " Nicolas Dichtel
2013-07-09 16:19 ` Ben Hutchings
2013-07-09 16:59 ` Nicolas Dichtel
2013-07-09 18:13 ` Ben Hutchings
2013-07-10 9:52 ` 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).