From: Masatake YAMATO <yamato@redhat.com>
To: util-linux@vger.kernel.org
Cc: yamato@redhat.com
Subject: [PATCH v2 2/7] lsns: disable netnsid column by default
Date: Fri, 24 Nov 2017 19:31:04 +0900 [thread overview]
Message-ID: <20171124103110.17077-3-yamato@redhat.com> (raw)
In-Reply-To: <20171124103110.17077-1-yamato@redhat.com>
Enable only when
* --type=net is given, or
* -o NETNSID is given.
Suggested by Karel Zak.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
sys-utils/lsns.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 7ccc733a4..bb7d3956d 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -839,6 +839,7 @@ int main(int argc, char *argv[])
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+ bool enabling_netnsid = false;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -891,6 +892,8 @@ int main(int argc, char *argv[])
errx(EXIT_FAILURE, _("unknown namespace type: %s"), optarg);
ls.fltr_types[type] = 1;
ls.fltr_ntypes++;
+ if (type == LSNS_ID_NET)
+ enabling_netnsid = true;
break;
}
default:
@@ -900,6 +903,7 @@ int main(int argc, char *argv[])
if (!ls.fltr_ntypes) {
size_t i;
+
for (i = 0; i < ARRAY_SIZE(ns_names); i++)
ls.fltr_types[i] = 1;
}
@@ -924,14 +928,24 @@ int main(int argc, char *argv[])
columns[ncolumns++] = COL_NPROCS;
columns[ncolumns++] = COL_PID;
columns[ncolumns++] = COL_USER;
- columns[ncolumns++] = COL_NETNSID;
+ if (enabling_netnsid)
+ columns[ncolumns++] = COL_NETNSID;
columns[ncolumns++] = COL_COMMAND;
}
- if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
- &ncolumns, column_name_to_id) < 0)
- return EXIT_FAILURE;
+ if (outarg) {
+ size_t i;
+ if (string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+ &ncolumns, column_name_to_id) < 0)
+ return EXIT_FAILURE;
+ for (i = 0; i < ncolumns; i++) {
+ if (columns[i] == COL_NETNSID) {
+ enabling_netnsid = true;
+ break;
+ }
+ }
+ }
scols_init_debug(0);
uid_cache = new_idcache();
@@ -939,7 +953,8 @@ int main(int argc, char *argv[])
err(EXIT_FAILURE, _("failed to allocate UID cache"));
#ifdef HAVE_LINUX_NET_NAMESPACE_H
- netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (enabling_netnsid)
+ netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
#endif
r = read_processes(&ls);
if (!r)
--
2.13.6
next prev parent reply other threads:[~2017-11-24 10:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 1/7] lsns: add netnsid column Masatake YAMATO
2017-11-24 10:31 ` Masatake YAMATO [this message]
2017-11-24 10:31 ` [PATCH v2 3/7] lsns: add a case for testing " Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 4/7] lsns: add nsfs column Masatake YAMATO
2017-11-24 10:31 ` [PATCH 5/5] lsns: add a case for testing " Masatake YAMATO
2017-11-24 10:34 ` Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 5/7] lsns: add --nowrap(-W) option Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 6/7] lsns: add a case for testing nsfs column Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 7/7] man: write about using multi-line in NSFS cell of lsns Masatake YAMATO
2017-11-24 12:04 ` [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Karel Zak
2017-11-27 16:46 ` Karel Zak
2017-11-27 17:06 ` Masatake YAMATO
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171124103110.17077-3-yamato@redhat.com \
--to=yamato@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).