aboutsummaryrefslogtreecommitdiffstats
path: root/misc-utils/lsfd.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2022-09-30 10:44:55 +0200
committerKarel Zak <kzak@redhat.com>2022-09-30 10:44:55 +0200
commite70e5258c05b856842ce5bd2ab2d6cb4d440162b (patch)
tree65521f077e5ce93c500febb376fa174e3c324cf7 /misc-utils/lsfd.c
parente0b15af484e6e0c05d3af1bf6cd226ca9252849a (diff)
parent55529a2620d5fd3cc549c38bf50455748da9020f (diff)
downloadutil-linux-e70e5258c05b856842ce5bd2ab2d6cb4d440162b.tar.gz
Merge branch 'lsfd-sock-unix-xinfo' of https://github.com/masatake/util-linux
* 'lsfd-sock-unix-xinfo' of https://github.com/masatake/util-linux: tests: (lsfd) add a case for testing SOCKNETNS column tests: (lsfd) extend unix-stream test case to test SEQPACKET socket tests: (lsfd) add a case testing UNIX+DGRAM socket tests: (lsfd) add a case testing UNIX-STREAM sockets tests: (mkfds) add a factory making unix sockets lsfd: (man) write about UNIX-STREAM and UNIX sockets lsfd: use extra information loaded from /proc/net/unix lsfd: add new columns: SOCKNETNS, SOCKSTATE, and SOCKTYPE as stubs lsfd: facilitate the way to attach extra info loaded from /proc/net/* to sockets tests: (mkfds) quit when a byte is given via standard input tests: (mkfds) call close method of factory only when it is specified tests: (mkfds) cosmetic change, deleting empty lines tests: (mkfds) add boolean, a new parameter type tests: (mkfds) add a method for printing factory specific data to struct factory tests: (mkfds) allow a factory to make a factory specific temporarily data tests: (mkfds) delete unused "child" parameter for factories tests: (mkfds) delete per-factory "fork" field
Diffstat (limited to 'misc-utils/lsfd.c')
-rw-r--r--misc-utils/lsfd.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c
index 0d7e7e58a1..d403513961 100644
--- a/misc-utils/lsfd.c
+++ b/misc-utils/lsfd.c
@@ -185,6 +185,12 @@ static struct colinfo infos[] = {
N_("device ID (if special file)") },
[COL_SIZE] = { "SIZE", 4, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
N_("file size"), },
+ [COL_SOCKNETNS]={"SOCKNETNS", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
+ N_("inode identifying network namespace where the socket belongs to") },
+ [COL_SOCKSTATE]={"SOCKSTATE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
+ N_("State of socket") },
+ [COL_SOCKTYPE] ={"SOCKTYPE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
+ N_("Type of socket") },
[COL_SOURCE] = { "SOURCE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
N_("file system, partition, or device containing file") },
[COL_STTYPE] = { "STTYPE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
@@ -195,6 +201,8 @@ static struct colinfo infos[] = {
N_("file type (cooked)") },
[COL_UID] = { "UID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
N_("user ID number of the process") },
+ [COL_UNIX_PATH]={ "UNIX.PATH",0.4,SCOLS_FL_TRUNC,SCOLS_JSON_STRING,
+ N_("filesystem pathname for UNIX doamin socketo") },
[COL_USER] = { "USER", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
N_("user of the process") },
};
@@ -605,6 +613,8 @@ static struct file *collect_file_symlink(struct path_cxt *pc,
if (is_association(f, NS_MNT))
proc->ns_mnt = f->stat.st_ino;
+ else if (is_association(f, NS_NET))
+ load_sock_xinfo(pc, name, f->stat.st_ino);
else if (assoc >= 0) {
/* file-descriptor based association */
@@ -613,6 +623,9 @@ static struct file *collect_file_symlink(struct path_cxt *pc,
if (ul_path_stat(pc, &sb, AT_SYMLINK_NOFOLLOW, name) == 0)
f->mode = sb.st_mode;
+ if (is_nsfs_dev(f->stat.st_dev))
+ load_sock_xinfo(pc, name, f->stat.st_ino);
+
fdinfo = ul_path_fopenf(pc, "r", "fdinfo/%d", assoc);
if (fdinfo) {
read_fdinfo(f, fdinfo);
@@ -1620,6 +1633,22 @@ static void emit_summary(struct lsfd_control *ctl, struct lsfd_counter **counter
scols_unref_table(tb);
}
+static void attach_xinfos(struct list_head *procs)
+{
+ struct list_head *p;
+
+ list_for_each (p, procs) {
+ struct proc *proc = list_entry(p, struct proc, procs);
+ struct list_head *f;
+
+ list_for_each (f, &proc->files) {
+ struct file *file = list_entry(f, struct file, files);
+ if (file->class->attach_xinfo)
+ file->class->attach_xinfo(file);
+ }
+ }
+}
+
int main(int argc, char *argv[])
{
int c;
@@ -1806,6 +1835,8 @@ int main(int argc, char *argv[])
collect_processes(&ctl, pids, n_pids);
free(pids);
+ attach_xinfos(&ctl.procs);
+
convert(&ctl.procs, &ctl);
/* print */