Skip to contentSkip to conversation

iproute2: exit code fixes

PATCH In review Stephen Hemminger 3 participants 8 messages May 6, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover iproute2: exit code fixes

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(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/4 ip: document exit code

From: Stephen Hemminger <[email protected]>

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(+)
man/man8/ip.8 +4 -0
index 43ddac9..9574a50 100644
@@ -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.
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/4] ip: document exit code

Hi,

Quoted 13 lines · Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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(+)
man/man8/ip.8 +0 -0
index 43ddac9..9574a50 100644

man/man8/ip.8 Usually it is · line 279

Quoted 5 lines
man/man8/ip.8 +2 -0
@@ -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 ?

Quoted 12 lines
man/man8/ip.8 +2 -0
+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.
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/4 ip: return correct exit code on route failure

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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

This fixes regression introduced by:
commit 42ecedd4bae534fc688194a795eb4548c6530cda

Author: Roopa Prabhu <[email protected]>
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(-)
ip/iproute.c +1 -1
index e0a6159..06aea6f 100644
@@ -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;
 }
Signature · 1 line
2.1.4
Acked-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] ip: return correct exit code on route failure

Quoted 20 lines · Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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

This fixes regression introduced by:
commit 42ecedd4bae534fc688194a795eb4548c6530cda

Author: Roopa Prabhu <[email protected]>
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(-)
ip/iproute.c +0 -0
index e0a6159..06aea6f 100644

ip/iproute.c static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) · line 1170

Quoted 8 lines
ip/iproute.c +1 -1
@@ -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;
  }

Thanks for documenting the error code convention.

#5 lore raw

Re: [PATCH 2/4] ip: return correct exit code on route failure

In reply to Stephen Hemminger
Quoted 20 lines · Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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

This fixes regression introduced by:
commit 42ecedd4bae534fc688194a795eb4548c6530cda

Author: Roopa Prabhu <[email protected]>
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(-)
ip/iproute.c +0 -0
index e0a6159..06aea6f 100644

ip/iproute.c static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) · line 1167

Quoted 5 lines
ip/iproute.c +1 -1
@@ -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 ?

Quoted 10 lines
ip/iproute.c +0 -0
 	return 0;
 }
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

PATCH 3/4 ip: fix exit code for rule failures

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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(-)
ip/iprule.c +1 -1
index 967969c..986a5bc 100644
@@ -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;
 }
Signature · 1 line
2.1.4
#7 lore raw

PATCH 4/4 ip: fix exit code for addrlabel

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>

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(-)
ip/ipaddrlabel.c +3 -3
index f6a638b..19a9308 100644
@@ -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;
Signature · 1 line
2.1.4