&& scols_line_set_data(ln, column_index, proc->command))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
+ case COL_KNAME:
case COL_NAME:
if (file->name
&& scols_line_set_data(ln, column_index, file->name))
if (scols_line_set_data(ln, column_index, sock->protoname))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
- case COL_NAME:
- if (sock->protoname
- && file->name && strncmp(file->name, "socket:", 7) == 0) {
- xasprintf(&str, "%s:%s", sock->protoname, file->name + 7);
- break;
- }
- return false;
case COL_SOURCE:
if (major(file->stat.st_dev) == 0
&& strncmp(file->name, "socket:", 7) == 0) {
if (proc)
comm = proc->command;
- xasprintf(&str, "pidfd: pid=%d comm=%s nspid=%s",
+ xasprintf(&str, "pid=%d comm=%s nspid=%s",
data->pid,
comm? comm: "",
data->nspid? data->nspid: "");
INODE <``number``>::
Inode number.
+KNAME <``string``>::
+//
+// It seems that the manpage backend of asciidoctor has limitations
+// about emitting text with nested face specifications like:
+//
+// `_u_` p
+//
+// Not only u but also p is decorated with underline.
+//
+Raw file name extracted from
+from ``/proc/``_pid_``/fd/``_fd_ or ``/proc/``_pid_``/map_files/``_region_.
+
KTHREAD <``boolean``>::
Whether the process is a kernel thread or not.
Access mode (rwx).
NAME <``string``>::
-Name of the file.
-//
-// It seems that the manpage backend of asciidoctor has limitations
-// about emitting text with nested face specifications like:
-//
-// `_u_` p
-//
-// Not only u but also p is decorated with underline.
-//
-For the most of all files, *lsfd* extracts their names
-from ``/proc/``_pid_``/fd/``_fd_ or ``/proc/``_pid_``/map_files/``_region_.
+Cooked version of KNAME. It is mostly same as KNAME.
+
Some files have special formats and information sources:
+
pidfd:::
-pidfd: pid=_TARGET-PID_ comm=_TARGET-COMMAND_ nspid=_TARGET-NSPIDS_
+pid=_TARGET-PID_ comm=_TARGET-COMMAND_ nspid=_TARGET-NSPIDS_
+
*lsfd* extracts _TARGET-PID_ and _TARGET-NSPIDS_ from
``/proc/``_pid_``/fdinfo/``_fd_.
N_("user ID number of the file's owner") },
[COL_INODE] = { "INODE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
N_("inode number") },
+ [COL_KNAME] = { "KNAME", 0.4, SCOLS_FL_TRUNC, SCOLS_JSON_STRING,
+ N_("name of the file (raw)") },
[COL_KTHREAD] = { "KTHREAD", 0, SCOLS_FL_RIGHT, SCOLS_JSON_BOOLEAN,
N_("opened by a kernel thread") },
[COL_MAJMIN] = { "MAJ:MIN", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
[COL_MODE] = { "MODE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
N_("access mode (rwx)") },
[COL_NAME] = { "NAME", 0.4, SCOLS_FL_TRUNC, SCOLS_JSON_STRING,
- N_("name of the file") },
+ N_("name of the file (cooked)") },
[COL_NLINK] = { "NLINK", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
N_("link count") },
[COL_OWNER] = { "OWNER", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
COL_FD,
COL_FLAGS,
COL_INODE,
+ COL_KNAME,
COL_KTHREAD,
COL_MAJMIN,
COL_MAPLEN,
--- /dev/null
+ 3 /etc/passwd /etc/passwd
+ro-regular-file:ASSOC,KNAME,NAME: 0
+ 3 anon_inode:[pidfd] pid=1 comm= nspid=1
+pidfd:ASSOC,KNAME,NAME: 0
+ 3 socket:[INODENUM] socket:[INODENUM]
+socketpair:ASSOC,KNAME,NAME: 0
- 3 UNKN anon_inodefs pidfd: pid=1 comm=systemd nspid=1
+ 3 UNKN anon_inodefs pid=1 comm=systemd nspid=1
ASSOC,STTYPE,SOURCE,NAME: 0
--- /dev/null
+#!/bin/bash
+#
+# Copyright (C) 2022 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="NAME and KNAME column"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSFD"
+ts_check_test_command "$TS_HELPER_MKFDS"
+ts_check_prog "sed"
+
+ts_cd "$TS_OUTDIR"
+
+PID=
+FD=3
+EXPR="(FD == 3)"
+
+{
+ for C in ro-regular-file pidfd socketpair; do
+ coproc MKFDS {
+ case $C in
+ socketpair)
+ argv="$((FD + 1)) socktype=DGRAM"
+ esac
+ "$TS_HELPER_MKFDS" $C $FD ${argv}
+ }
+ if read -u ${MKFDS[0]} PID; then
+ ${TS_CMD_LSFD} -n -o ASSOC,KNAME,NAME -p "${PID}" -Q "${EXPR}" | {
+ # Replace the unpredictable an inode number for the socket
+ # with "INODENUM".
+ sed -e 's/\[[0-9]\+\]/[INODENUM]/g'
+ }
+ echo "$C"':ASSOC,KNAME,NAME': $?
+
+ kill -CONT ${PID}
+ wait ${MKFDS_PID}
+ fi
+ done
+} > $TS_OUTPUT 2>&1
+
+ts_finalize