All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] iproute2: exit code fixes
@ 2015-05-06 16:57 Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 1/4] ip: document exit code Stephen Hemminger
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Stephen Hemminger @ 2015-05-06 16:57 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

The exit code for ip command has always been 0 on success,
1 on syntax error, and 2 on kernel (netlink) error; but it isn't
documented and there were some regressions and places it was not
being done correctly.

Stephen Hemminger (4):
  ip: document exit code
  ip: return correct exit code on route failure
  ip: fix exit code for rule failures
  ip: fix exit code for addrlabel

 ip/ipaddrlabel.c | 6 +++---
 ip/iproute.c     | 2 +-
 ip/iprule.c      | 2 +-
 man/man8/ip.8    | 4 ++++
 4 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.1.4

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

* [PATCH 1/4] ip: document exit code
  2015-05-06 16:57 [PATCH 0/4] iproute2: exit code fixes Stephen Hemminger
@ 2015-05-06 16:58 ` Stephen Hemminger
  2015-05-06 17:16   ` Vadim Kochan
  2015-05-06 16:58 ` [PATCH 2/4] ip: return correct exit code on route failure Stephen Hemminger
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2015-05-06 16:58 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

From: Stephen Hemminger <shemming@brocade.com>

The ip command has always had a consistent exit status
document it so that developers see it.
---
 man/man8/ip.8 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/man/man8/ip.8 b/man/man8/ip.8
index 43ddac9..9574a50 100644
--- a/man/man8/ip.8
+++ b/man/man8/ip.8
@@ -275,6 +275,10 @@ Usually it is
 or, if the objects of this class cannot be listed,
 .BR "help" .
 
+.SH EXIT STATUS
+Exit statsis is 0 if command was sucessful, and 1 if there is a syntax error.
+If an error was reported by the kernel exit status is 2.
+
 .SH HISTORY
 .B ip
 was written by Alexey N. Kuznetsov and added in Linux 2.2.
-- 
2.1.4

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

* [PATCH 2/4] ip: return correct exit code on route failure
  2015-05-06 16:57 [PATCH 0/4] iproute2: exit code fixes Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 1/4] ip: document exit code Stephen Hemminger
@ 2015-05-06 16:58 ` Stephen Hemminger
  2015-05-06 17:19   ` roopa
  2015-05-06 17:25   ` Vadim Kochan
  2015-05-06 16:58 ` [PATCH 3/4] ip: fix exit code for rule failures Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 4/4] ip: fix exit code for addrlabel Stephen Hemminger
  3 siblings, 2 replies; 8+ messages in thread
From: Stephen Hemminger @ 2015-05-06 16:58 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

From: Stephen Hemminger <shemming@brocade.com>

If kernel complains about ip route request, exit status should be
2 not 1.

This fixes regression introduced by:
commit 42ecedd4bae534fc688194a795eb4548c6530cda
Author: Roopa Prabhu <roopa@cumulusnetworks.com>
Date:   Tue Mar 17 19:26:32 2015 -0700

    fix ip -force -batch to continue on errors
---
 ip/iproute.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index e0a6159..06aea6f 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1164,7 +1164,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 		req.r.rtm_family = AF_INET;
 
 	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
-		return -1;
+		return -2;
 
 	return 0;
 }
-- 
2.1.4

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

* [PATCH 3/4] ip: fix exit code for rule failures
  2015-05-06 16:57 [PATCH 0/4] iproute2: exit code fixes Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 1/4] ip: document exit code Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 2/4] ip: return correct exit code on route failure Stephen Hemminger
@ 2015-05-06 16:58 ` Stephen Hemminger
  2015-05-06 16:58 ` [PATCH 4/4] ip: fix exit code for addrlabel Stephen Hemminger
  3 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2015-05-06 16:58 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

From: Stephen Hemminger <shemming@brocade.com>

If ip rule command fails talking to kernel, exit code should be 2.
The sub-command is called by cmd loop and the exit code is negative
of return value from the command callback.
---
 ip/iprule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ip/iprule.c b/ip/iprule.c
index 967969c..986a5bc 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -381,7 +381,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
 		req.r.rtm_table = RT_TABLE_MAIN;
 
 	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
-		return 2;
+		return -2;
 
 	return 0;
 }
-- 
2.1.4

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

* [PATCH 4/4] ip: fix exit code for addrlabel
  2015-05-06 16:57 [PATCH 0/4] iproute2: exit code fixes Stephen Hemminger
                   ` (2 preceding siblings ...)
  2015-05-06 16:58 ` [PATCH 3/4] ip: fix exit code for rule failures Stephen Hemminger
@ 2015-05-06 16:58 ` Stephen Hemminger
  3 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2015-05-06 16:58 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

From: Stephen Hemminger <shemming@brocade.com>

The exit code for ip label was not correct.
The return from the command function is negated and turned into
the exit code on failure.
---
 ip/ipaddrlabel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index f6a638b..19a9308 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -183,7 +183,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
 		req.ifal.ifal_family = AF_INET6;
 
 	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
-		return 2;
+		return -2;
 
 	return 0;
 }
@@ -232,12 +232,12 @@ static int ipaddrlabel_flush(int argc, char **argv)
 
 	if (rtnl_wilddump_request(&rth, af, RTM_GETADDRLABEL) < 0) {
 		perror("Cannot send dump request");
-		return 1;
+		return -1;
 	}
 
 	if (rtnl_dump_filter(&rth, flush_addrlabel, NULL) < 0) {
 		fprintf(stderr, "Flush terminated\n");
-		return 1;
+		return -1;
 	}
 
 	return 0;
-- 
2.1.4

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

* Re: [PATCH 1/4] ip: document exit code
  2015-05-06 16:58 ` [PATCH 1/4] ip: document exit code Stephen Hemminger
@ 2015-05-06 17:16   ` Vadim Kochan
  0 siblings, 0 replies; 8+ messages in thread
From: Vadim Kochan @ 2015-05-06 17:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Stephen Hemminger

Hi,

On Wed, May 06, 2015 at 09:58:00AM -0700, Stephen Hemminger wrote:
> From: Stephen Hemminger <shemming@brocade.com>
> 
> The ip command has always had a consistent exit status
> document it so that developers see it.
> ---
>  man/man8/ip.8 | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/man/man8/ip.8 b/man/man8/ip.8
> index 43ddac9..9574a50 100644
> --- a/man/man8/ip.8
> +++ b/man/man8/ip.8
> @@ -275,6 +275,10 @@ Usually it is
>  or, if the objects of this class cannot be listed,
>  .BR "help" .
>  
> +.SH EXIT STATUS
> +Exit statsis is 0 if command was sucessful, and 1 if there is a syntax error.
statsis -> status ?                 sucessful -> successful ?

> +If an error was reported by the kernel exit status is 2.
> +
>  .SH HISTORY
>  .B ip
>  was written by Alexey N. Kuznetsov and added in Linux 2.2.
> -- 
> 2.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/4] ip: return correct exit code on route failure
  2015-05-06 16:58 ` [PATCH 2/4] ip: return correct exit code on route failure Stephen Hemminger
@ 2015-05-06 17:19   ` roopa
  2015-05-06 17:25   ` Vadim Kochan
  1 sibling, 0 replies; 8+ messages in thread
From: roopa @ 2015-05-06 17:19 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Stephen Hemminger

On 5/6/15, 9:58 AM, Stephen Hemminger wrote:
> From: Stephen Hemminger <shemming@brocade.com>
>
> If kernel complains about ip route request, exit status should be
> 2 not 1.
>
> This fixes regression introduced by:
> commit 42ecedd4bae534fc688194a795eb4548c6530cda
> Author: Roopa Prabhu <roopa@cumulusnetworks.com>
> Date:   Tue Mar 17 19:26:32 2015 -0700
>
>      fix ip -force -batch to continue on errors
> ---
>   ip/iproute.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/ip/iproute.c b/ip/iproute.c
> index e0a6159..06aea6f 100644
> --- a/ip/iproute.c
> +++ b/ip/iproute.c
> @@ -1164,7 +1164,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
>   		req.r.rtm_family = AF_INET;
>   
>   	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
> -		return -1;
> +		return -2;
>   
>   	return 0;
>   }
Acked-by: Roopa Prabhu <roopa@cumulusnetworks.com>

Thanks for documenting the error code convention.

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

* Re: [PATCH 2/4] ip: return correct exit code on route failure
  2015-05-06 16:58 ` [PATCH 2/4] ip: return correct exit code on route failure Stephen Hemminger
  2015-05-06 17:19   ` roopa
@ 2015-05-06 17:25   ` Vadim Kochan
  1 sibling, 0 replies; 8+ messages in thread
From: Vadim Kochan @ 2015-05-06 17:25 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Stephen Hemminger

On Wed, May 06, 2015 at 09:58:01AM -0700, Stephen Hemminger wrote:
> From: Stephen Hemminger <shemming@brocade.com>
> 
> If kernel complains about ip route request, exit status should be
> 2 not 1.
> 
> This fixes regression introduced by:
> commit 42ecedd4bae534fc688194a795eb4548c6530cda
> Author: Roopa Prabhu <roopa@cumulusnetworks.com>
> Date:   Tue Mar 17 19:26:32 2015 -0700
> 
>     fix ip -force -batch to continue on errors
> ---
>  ip/iproute.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ip/iproute.c b/ip/iproute.c
> index e0a6159..06aea6f 100644
> --- a/ip/iproute.c
> +++ b/ip/iproute.c
> @@ -1164,7 +1164,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
>  		req.r.rtm_family = AF_INET;
>  
>  	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
> -		return -1;
> +		return -2;
May be it would be good to have a #define's like ERR_APP & ERR_KERN ?

>  
>  	return 0;
>  }
> -- 
> 2.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-05-06 17:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06 16:57 [PATCH 0/4] iproute2: exit code fixes Stephen Hemminger
2015-05-06 16:58 ` [PATCH 1/4] ip: document exit code Stephen Hemminger
2015-05-06 17:16   ` Vadim Kochan
2015-05-06 16:58 ` [PATCH 2/4] ip: return correct exit code on route failure Stephen Hemminger
2015-05-06 17:19   ` roopa
2015-05-06 17:25   ` Vadim Kochan
2015-05-06 16:58 ` [PATCH 3/4] ip: fix exit code for rule failures Stephen Hemminger
2015-05-06 16:58 ` [PATCH 4/4] ip: fix exit code for addrlabel Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.