ip netns: Identify netns for the current process
As 'ip' util will share the same netns from the caller
process then we can just look at /proc/self/.. to show
the netns of the current process by:
ip netns id
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 90a496f..1c8aa02 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -59,7 +59,7 @@
fprintf(stderr, "Usage: ip netns list\n");
fprintf(stderr, " ip netns add NAME\n");
fprintf(stderr, " ip netns delete NAME\n");
- fprintf(stderr, " ip netns identify PID\n");
+ fprintf(stderr, " ip netns identify [PID]\n");
fprintf(stderr, " ip netns pids NAME\n");
fprintf(stderr, " ip netns exec NAME cmd ...\n");
fprintf(stderr, " ip netns monitor\n");
@@ -299,19 +299,17 @@
struct dirent *entry;
if (argc < 1) {
- fprintf(stderr, "No pid specified\n");
- return -1;
- }
- if (argc > 1) {
+ pidstr = "self";
+ } else if (argc > 1) {
fprintf(stderr, "extra arguments specified\n");
return -1;
- }
- pidstr = argv[0];
-
- if (!is_pid(pidstr)) {
- fprintf(stderr, "Specified string '%s' is not a pid\n",
- pidstr);
- return -1;
+ } else {
+ pidstr = argv[0];
+ if (!is_pid(pidstr)) {
+ fprintf(stderr, "Specified string '%s' is not a pid\n",
+ pidstr);
+ return -1;
+ }
}
snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);