]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsfd: utilize /proc/tty/drivers for filling SOURCE column of tty devices
authorMasatake YAMATO <yamato@redhat.com>
Wed, 1 Nov 2023 15:05:12 +0000 (00:05 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sat, 4 Nov 2023 08:03:05 +0000 (17:03 +0900)
commitf5bc75bff728036d140e9fdd54594166437f5114
treeabc6d46dbcd7b8ad555621f26e5b6bf412ca8089
parent837c9eeccdc4bc99382394121bbb1b63eba2b866
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>
misc-utils/lsfd-cdev.c