]> git.ipfire.org Git - thirdparty/iproute2.git/commit
lib/namespace: fix ip -all netns return code
authorAndrea Claudi <aclaudi@redhat.com>
Mon, 22 Feb 2021 11:40:36 +0000 (12:40 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 23 Feb 2021 02:17:56 +0000 (18:17 -0800)
commit1e25de9a9239cd6d7cc1d0ec3f7552d4ee7087e8
tree0588df2c995ec0cad759689a09ed82ed10b02d57
parente833dbe140c529ab0b50eaa01ef37cb7b1c00e22
lib/namespace: fix ip -all netns return code

When ip -all netns {del,exec} are called and no netns is present, ip
exit with status 0. However this does not happen if no netns has been
created since boot time: in that case, indeed, the NETNS_RUN_DIR is not
present and netns_foreach() exit with code 1.

$ ls /var/run/netns
ls: cannot access '/var/run/netns': No such file or directory
$ ip -all netns exec ip link show
$ echo $?
1
$ ip -all netns del
$ echo $?
1
$ ip netns add test
$ ip netns del test
$ ip -all netns del
$ echo $?
0
$ ls -a /var/run/netns
.  ..

This leaves us in the unpleasant situation where the same command, when
no netns is present, does the same stuff (in this case, nothing), but
exit with two different statuses.

Fix this treating ENOENT in a different way from other errors, similarly
to what we already do in ipnetns.c netns_identify_pid()

Fixes: e998e118ddc3 ("lib: Exec func on each netns")
Reported-by: Jianlin Shi <jishi@redhat.com>
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/namespace.c