lsfd: utilize /proc/tty/drivers for filling SOURCE column of tty devices
The original code referenced /proc/devices using major numbers as keys to obtain
the name of the device driver corresponding to a file descriptor.
However, it turnes out that some drivers share a same major number;
there are cases that a key is not unique.
Character devices:
1 mem
4 /dev/vc/0
4 tty
4 ttyS
...
About tty-related devices, /proc/tty/drivers is better information
source; both major and minor numbers can be used as keys:
/dev/tty /dev/tty 5 0 system:/dev/tty
/dev/console /dev/console 5 1 system:console
/dev/ptmx /dev/ptmx 5 2 system
/dev/vc/0 /dev/vc/0 4 0 system:vtmaster
usbserial /dev/ttyUSB 188 0-511 serial
dbc_serial /dev/ttyDBC 242 0-63 serial
serial /dev/ttyS 4 64-95 serial
pty_slave /dev/pts 136 0-
1048575 pty:slave
pty_master /dev/ptm 128 0-
1048575 pty:master
unknown /dev/tty 4 1-63 console
This commit extracts the second column of the /proc/tty/drivers as
driver names after removing "/dev": tty, console, ptmx, ...
With the orinal code:
# lsfd -n -p 1789 -Q '(FD == 25)'
systemd-logind 1789 root 25 rw- CHR /dev/vc/0:6 432 25 /dev/tty6
--------------------------------------------^^^^^^^^^^^
With this commit:
# ./lsfd -n -p 1789 -Q '(FD == 25)'
systemd-logind 1789 root 25 rw---- CHR tty:6 432 25 /dev/tty6
----------------------------------------------^^^^^
Signed-off-by: Masatake YAMATO <yamato@redhat.com>