Skip to contentSkip to conversation

man: fix doc ip will exit with -1

PATCH In review Jiayun Chen 2 participants 4 messages Apr 23, 2024 – Apr 27, 2024

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

PATCH 1/1 man: fix doc ip will exit with -1

The exit code of -1 (255) is not documented:

$ ip link set dev; echo $?
255
$ ip route help; echo $?
255

It appears that ip returns -1 on syntax error, e.g., invalid device, buffer size. Here is a patch for documenting this behavior.

---
 man/man8/ip.8 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
man/man8/ip.8 +2 -2
index fdae57c5..e7bd9eb4 100644
@@ -405,8 +405,8 @@ If this value is 0-6 or 8, chose colors suitable for dark background:
 COLORFGBG=";0" ip -c a
 
 .SH EXIT STATUS
-Exit status is 0 if command was successful, and 1 if there is a syntax error.
-If an error was reported by the kernel exit status is 2.
+Exit status is 0 if command was successful, and -1 or 1 if there is a 
+syntax error. If an error was reported by the kernel exit status is 2.
 
 .SH "EXAMPLES"
 .PP
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · On Tue, 23 Apr 2024 15:03:46 +0800 Jiayun Chen <[email protected]> wrote:

The exit code of -1 (255) is not documented:

$ ip link set dev; echo $?
255
$ ip route help; echo $?
255
Quoted 7 lines

It appears that ip returns -1 on syntax error, e.g., invalid device, buffer size. Here is a patch for documenting this behavior.

---
 man/man8/ip.8 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I wish Alexey had used the semi-standard exit codes from bash. The convention is to use 2 for incorrect usage. Probably too late to fix now?

#2 lore raw

But a checker based on the manual doesn't know
what such an undefined value means and how to
handle it.

So I suggest fixing the manual only, not the code.

Quoted 23 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 23 Apr 2024 15:03:46 +0800 Jiayun Chen <[email protected]> wrote:

The exit code of -1 (255) is not documented:

$ ip link set dev; echo $?
255
$ ip route help; echo $?
255
Quoted 7 lines

It appears that ip returns -1 on syntax error, e.g., invalid device, buffer size. Here is a patch for documenting this behavior.

---
 man/man8/ip.8 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I wish Alexey had used the semi-standard exit codes from bash. The convention is to use 2 for incorrect usage. Probably too late to fix now?

#3 lore raw
In reply to Jiayun Chen
Quoted 5 lines · On Tue, 23 Apr 2024 15:03:46 +0800 Jiayun Chen <[email protected]> wrote:

The exit code of -1 (255) is not documented:

$ ip link set dev; echo $?
255
Quoted 8 lines
$ ip route help; echo $?
255

It appears that ip returns -1 on syntax error, e.g., invalid device, buffer size. Here is a patch for documenting this behavior.

---

I would rather fix all of iproute2 commands (ip, bridge, tc, devlink, etc) to follow the conventions used by other Linux utilities of return 2 for errors in command line arguments. Doing that is unlikely to break any scripts because a sane script will be checking for exit status of non-zero.