]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
4 years agolsfd: remove duplicated an O_ flag entry
Masatake YAMATO [Fri, 15 Oct 2021 20:40:17 +0000 (05:40 +0900)] 
lsfd: remove duplicated an O_ flag entry

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agobuild-sys: link lib_common to test_procfs
Masatake YAMATO [Sun, 10 Oct 2021 08:01:40 +0000 (17:01 +0900)] 
build-sys: link lib_common to test_procfs

Suggested by Thomas Weißschuh at
https://github.com/karelzak/util-linux/pull/1418#pullrequestreview-775639562

4 years agolsfd: (adoc) write about filter expression
Masatake YAMATO [Tue, 5 Oct 2021 14:55:30 +0000 (23:55 +0900)] 
lsfd: (adoc) write about filter expression

Charelle Collett helped me improve the setences.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (test) add a case for displaying a directory
Masatake YAMATO [Mon, 11 Oct 2021 22:24:42 +0000 (07:24 +0900)] 
lsfd: (test) add a case for displaying a directory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (test) add cases for displaying a regular file and pipe
Masatake YAMATO [Sun, 10 Oct 2021 00:58:55 +0000 (09:58 +0900)] 
lsfd: (test) add cases for displaying a regular file and pipe

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add FUID and OWNER columns
Masatake YAMATO [Mon, 11 Oct 2021 21:42:37 +0000 (06:42 +0900)] 
lsfd: add FUID and OWNER columns

UID and USER is for processes.
FUID and OWNER is for owners of files.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: fill UID column with the process's uid
Masatake YAMATO [Mon, 11 Oct 2021 21:27:58 +0000 (06:27 +0900)] 
lsfd: fill UID column with the process's uid

The original code fills the column with the owner id of the executable
file. Because lsfd fills USER column field by decoding UID column, the
USER in lsfd meant the owner name of the executable.

On the other hand, lsof fills the USER column with the process's user
name.

To avoid users confusing, this change makes lsfd do the same lsof;
filling UID column with the process's uid.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (filter) implement !~, an operator for regex unmatching
Masatake YAMATO [Sun, 10 Oct 2021 18:59:35 +0000 (03:59 +0900)] 
lsfd: (filter) implement !~, an operator for regex unmatching

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (filter) implement =~, an operator for regex matching
Masatake YAMATO [Fri, 8 Oct 2021 06:51:55 +0000 (15:51 +0900)] 
lsfd: (filter) implement =~, an operator for regex matching

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (filter) make error messages in check_type methods
Masatake YAMATO [Fri, 8 Oct 2021 06:27:23 +0000 (15:27 +0900)] 
lsfd: (filter) make error messages in check_type methods

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (filter) give a name to a constant
Masatake YAMATO [Fri, 8 Oct 2021 03:18:16 +0000 (12:18 +0900)] 
lsfd: (filter) give a name to a constant

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (filter) whitespace cleanup
Masatake YAMATO [Fri, 8 Oct 2021 06:52:43 +0000 (15:52 +0900)] 
lsfd: (filter) whitespace cleanup

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) remove a redundant word
Masatake YAMATO [Thu, 7 Oct 2021 09:08:06 +0000 (18:08 +0900)] 
lsfd: (adoc) remove a redundant word

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agobuild-sys: fix test_procfs SOURCES
Karel Zak [Thu, 7 Oct 2021 08:43:32 +0000 (10:43 +0200)] 
build-sys: fix test_procfs SOURCES

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsns: optimize mountinfo use
Karel Zak [Wed, 6 Oct 2021 11:36:42 +0000 (13:36 +0200)] 
lsns: optimize mountinfo use

Let's parse mountinfo only for unknown namespaces or when
namespace Id is not accessible (unprivileged users).

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: remove unused code
Karel Zak [Wed, 6 Oct 2021 09:22:07 +0000 (11:22 +0200)] 
lsfd: remove unused code

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: function rename
Karel Zak [Wed, 6 Oct 2021 09:20:51 +0000 (11:20 +0200)] 
lsfd: function rename

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobuild-sys: cleanup lsfd related stuff
Karel Zak [Wed, 6 Oct 2021 09:11:16 +0000 (11:11 +0200)] 
build-sys: cleanup lsfd related stuff

- add lsfd to meson.build
- add Masatake to AUTHORS
- add me to lsfd.c header and man page

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: add new man page to Makemodule.am
Masatake YAMATO [Sun, 3 Oct 2021 19:47:56 +0000 (04:47 +0900)] 
lsfd: add new man page to Makemodule.am

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) write more about the -o option
Masatake YAMATO [Sun, 3 Oct 2021 19:44:21 +0000 (04:44 +0900)] 
lsfd: (adoc) write more about the -o option

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) add proc(5) to SEE ALSO section
Masatake YAMATO [Sun, 3 Oct 2021 18:57:06 +0000 (03:57 +0900)] 
lsfd: (adoc) add proc(5) to SEE ALSO section

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) reorder the options
Masatake YAMATO [Sun, 3 Oct 2021 08:56:47 +0000 (17:56 +0900)] 
lsfd: (adoc) reorder the options

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) update DESCRIPTION
Masatake YAMATO [Sun, 3 Oct 2021 06:58:38 +0000 (15:58 +0900)] 
lsfd: (adoc) update DESCRIPTION

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) reorder the sections
Masatake YAMATO [Sun, 3 Oct 2021 07:06:20 +0000 (16:06 +0900)] 
lsfd: (adoc) reorder the sections

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: (adoc) put missing :: at the end of options
Masatake YAMATO [Sun, 3 Oct 2021 19:22:09 +0000 (04:22 +0900)] 
lsfd: (adoc) put missing :: at the end of options

4 years agolsfd: fix a typo in DEVTYPE description
Masatake YAMATO [Sun, 3 Oct 2021 19:37:19 +0000 (04:37 +0900)] 
lsfd: fix a typo in DEVTYPE description

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: wrap code for debugging with #ifdef DEBUG/#endif
Masatake YAMATO [Fri, 1 Oct 2021 17:24:31 +0000 (02:24 +0900)] 
lsfd: wrap code for debugging with #ifdef DEBUG/#endif

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: convert lines introducing local variable to a block with {...}
Masatake YAMATO [Fri, 1 Oct 2021 17:15:00 +0000 (02:15 +0900)] 
lsfd: convert lines introducing local variable to a block with {...}

The following code causing an error on test run on GitHub Action:

  case FOO:
      type localvar;

This change converts above code to:

  case FOO: {
      type localvar;
  }

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: change the license of the filtering engine to LGPL
Masatake YAMATO [Fri, 1 Oct 2021 16:53:14 +0000 (01:53 +0900)] 
lsfd: change the license of the filtering engine to LGPL

This change is for moving the filtering engine to libsmartcols in the
future.

In addition to the change, I made myself a copyright holder of the
code.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: Add new man page to po4a.cfg
Mario Blättermann [Fri, 1 Oct 2021 19:35:42 +0000 (21:35 +0200)] 
lsfd: Add new man page to po4a.cfg

4 years agolsfd: Add initial man page
Mario Blättermann [Fri, 1 Oct 2021 18:40:12 +0000 (20:40 +0200)] 
lsfd: Add initial man page

4 years agolsfd: Fix typos in lsfd.c
Mario Blättermann [Fri, 1 Oct 2021 18:39:48 +0000 (20:39 +0200)] 
lsfd: Fix typos in lsfd.c

4 years agolsfd: use new scols_line_get_column_data()
Karel Zak [Fri, 1 Oct 2021 11:10:46 +0000 (13:10 +0200)] 
lsfd: use new scols_line_get_column_data()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibsmartcols: add scols_line_get_column_data()
Karel Zak [Fri, 1 Oct 2021 11:10:06 +0000 (13:10 +0200)] 
libsmartcols: add scols_line_get_column_data()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: collect threads level information if TID is specified in a filter
Masatake YAMATO [Tue, 28 Sep 2021 12:57:31 +0000 (21:57 +0900)] 
lsfd: collect threads level information if TID is specified in a filter

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: introduce --source filter option
Masatake YAMATO [Fri, 24 Sep 2021 19:32:27 +0000 (04:32 +0900)] 
lsfd: introduce --source filter option

Reflecting the review comment:

    add filter by SOURCE (lsfd --source sda1)

Example output:

    # ./lsfd --source proc | head
    COMMAND             PID   USER ASSOC MODE TYPE SOURCE MNTID      INODE NAME
    systemd               1   root    10  r--  REG   proc    23      18542 /proc/1/mountinfo
    systemd               1   root    14  r--  REG   proc    23 4026532082 /proc/swaps
    systemd-resolve     856   root     7  r--  REG   proc   254      24841 /proc/sys/kernel/hostname
    low-memory-moni     898   root     7  rw-  REG   proc   425 4026532073 /proc/pressure/memory
    low-memory-moni     898   root     8  rw-  REG   proc   425 4026532073 /proc/pressure/memory
    low-memory-moni     898   root     9  rw-  REG   proc   425 4026532073 /proc/pressure/memory
    packagekitd       25205   root    12  r--  REG   proc    23      69645 /proc/25205/mountinfo
    systemd           26466   root    10  r--  REG   proc    23      71813 /proc/26466/mountinfo
    systemd           26466   root    14  r--  REG   proc    23 4026532082 /proc/swaps

    # ./lsfd --source proc -Q '(PID == 898)'
    COMMAND           PID USER ASSOC MODE TYPE SOURCE MNTID      INODE NAME
    low-memory-moni   898 root     7  rw-  REG   proc   425 4026532073 /proc/pressure/memory
    low-memory-moni   898 root     8  rw-  REG   proc   425 4026532073 /proc/pressure/memory
    low-memory-moni   898 root     9  rw-  REG   proc   425 4026532073 /proc/pressure/memory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: introduce -Q option for generic filtering
Masatake YAMATO [Mon, 20 Sep 2021 17:58:48 +0000 (02:58 +0900)] 
lsfd: introduce -Q option for generic filtering

Examples:

    # ./lsfd -Q "(FD <= 9) and (TYPE == 'SOCK')" -Q "COMMAND == 'ssh'" | head
    COMMAND     PID USER ASSOC MODE TYPE SOURCE MNTID    INODE NAME
    ssh      153907 root     4  rw- SOCK sockfs     9  2450021 TCP:[2450021]
    ssh     1657696 root     4  rw- SOCK sockfs     9 64357645 TCP:[64357645]
    ssh     1657696 root     5  rw- SOCK sockfs     9 64363596 UNIX:[64363596]
    ssh     2345473 root     4  rw- SOCK sockfs     9 81978848 TCP:[81978848]
    ssh     2345473 root     5  rw- SOCK sockfs     9 81980736 UNIX:[81980736]
    ssh     2345473 root     9  rw- SOCK sockfs     9 81980737 UNIX:[81980737]
    ssh     2345475 root     4  rw- SOCK sockfs     9 81975091 UNIX:[81975091]
    ssh     3958804 root     0  rw- SOCK sockfs     9 87840900 UNIX:[87840900]
    ssh     3958804 root     4  rw- SOCK sockfs     9 87836642 TCP:[87836642]

    # ./lsfd -Q "((ASSOC == 'exe') || (ASSOC == 'pid')) and (USER == 'yamato')"
    COMMAND        PID   USER ASSOC MODE TYPE SOURCE MNTID      INODE NAME
    lsfd        690292 yamato   exe  ---  REG   dm-2     0   34474245 /home/yamato/var/util-linux/util-linux/.libs/lsfd
    lsfd        690292 yamato   pid  ---  REG   nsfs     0 4026531836 pid:[4026531836]
    pidns      1458677 yamato   exe  ---  REG   dm-2     0   34212178 /home/yamato/var/kernel-essential-training/container/pidns
    pidns      1458677 yamato   pid  ---  REG   nsfs     0 4026533715 pid:[4026533715]
    fd-catalog 1677961 yamato   exe  ---  REG   dm-2     0  128715536 /home/yamato/var/fd-catalog/fd-catalog (deleted)
    fd-catalog 1677961 yamato   pid  ---  REG   nsfs     0 4026531836 pid:[4026531836]

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add filter engine
Masatake YAMATO [Mon, 20 Sep 2021 17:57:37 +0000 (02:57 +0900)] 
lsfd: add filter engine

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: fix a typo in comment
Masatake YAMATO [Fri, 24 Sep 2021 17:14:05 +0000 (02:14 +0900)] 
lsfd: fix a typo in comment

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: optimize symlinks use
Karel Zak [Thu, 30 Sep 2021 09:11:30 +0000 (11:11 +0200)] 
lsfd: optimize symlinks use

Like the previous commit, this patch tries to reuse
/proc/#/{fd,ns,cwd,root} symlinks if possible. On my machine it
saves ~2000 stat() calls.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: optimize maps use
Karel Zak [Thu, 30 Sep 2021 08:42:02 +0000 (10:42 +0200)] 
lsfd: optimize maps use

The /proc/#/maps file usually contains the same file more than once.
This patch tries to reuse previous file to reduce number of stat()
calls, see "strace --summary-only" output below, the syscall is reduce
in 50%.

old version:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 55.57    0.118708           2     50756      5414 newfstatat

new version:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 39.17    0.058501           2     24436      5382 newfstatat

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: use only "/proc/#/maps" file
Karel Zak [Mon, 20 Sep 2021 13:23:58 +0000 (15:23 +0200)] 
lsfd: use only "/proc/#/maps" file

* do not read /proc/#/map_files symlinks
* use paths from /proc/#/maps
* do not maintain map entries

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: don't use 'long int' for file data
Karel Zak [Mon, 20 Sep 2021 11:30:28 +0000 (13:30 +0200)] 
lsfd: don't use 'long int' for file data

Let's always assume positions, offsets, etc.. as 64-bit numbers.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: cleanup fdinfo handling
Karel Zak [Mon, 20 Sep 2021 11:16:06 +0000 (13:16 +0200)] 
lsfd: cleanup fdinfo handling

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd:remove struct fdinfo_data
Karel Zak [Mon, 20 Sep 2021 10:46:31 +0000 (12:46 +0200)] 
lsfd:remove struct fdinfo_data

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: split new_file(), remove map_file_data
Karel Zak [Mon, 20 Sep 2021 10:28:50 +0000 (12:28 +0200)] 
lsfd: split new_file(), remove map_file_data

Don't initialize entire 'struct file' in one step. It seems better to
use different ways according to file source (map, symlink, etc.).

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: rename DEVNAME column to SOURCE
Masatake YAMATO [Thu, 16 Sep 2021 16:04:48 +0000 (01:04 +0900)] 
lsfd: rename DEVNAME column to SOURCE

Reflecting the review comment:

    maybe rename DEVNAME to SOURCE as we have here things like 'devtmpfs' etc.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: remove redundant "nodev:" prefix from DEVNAME column
Masatake YAMATO [Thu, 16 Sep 2021 15:46:39 +0000 (00:46 +0900)] 
lsfd: remove redundant "nodev:" prefix from DEVNAME column

Reflecting the review comment:

    remove "nodev:" from DEVNAME

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add DEVTYPE column
Masatake YAMATO [Thu, 16 Sep 2021 15:22:14 +0000 (00:22 +0900)] 
lsfd: add DEVTYPE column

Reflecting the review comment:

    add DEVTYPE for blk, char, and nodev

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: sort the enumerators about columns
Masatake YAMATO [Thu, 16 Sep 2021 15:07:45 +0000 (00:07 +0900)] 
lsfd: sort the enumerators about columns

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: rename the column DEVICE to MAJ:MIN
Masatake YAMATO [Thu, 16 Sep 2021 15:01:30 +0000 (00:01 +0900)] 
lsfd: rename the column DEVICE to MAJ:MIN

Reflecting the review comment:

    add MAJ:MIN for major and minor numbers, remove DEVICE (we use
    MAJ:MIN in other tools)

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: don't duplicate ASSOC_EXE processing
Karel Zak [Wed, 8 Sep 2021 12:42:05 +0000 (14:42 +0200)] 
lsfd: don't duplicate ASSOC_EXE processing

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: use one function to all symlinks
Karel Zak [Wed, 8 Sep 2021 12:32:31 +0000 (14:32 +0200)] 
lsfd: use one function to all symlinks

This commit introduces collect_file_symlink() to gather info from
arbitrary symlink (e.g. /proc/#/exe, /proc/#/fd/1).

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/path: add ul_path_next_dirent()
Karel Zak [Wed, 8 Sep 2021 11:44:20 +0000 (13:44 +0200)] 
lib/path: add ul_path_next_dirent()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/path: use flags for fstatat()
Karel Zak [Wed, 8 Sep 2021 11:16:29 +0000 (13:16 +0200)] 
lib/path: use flags for fstatat()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: fix ASSOC_EXE use, make file->association use more robust
Karel Zak [Wed, 8 Sep 2021 10:52:43 +0000 (12:52 +0200)] 
lsfd: fix ASSOC_EXE use, make file->association use more robust

Let's use is_association() macro in the code rather than directly
check file->association as this struct member has special semantic.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: cleanup collect_outofbox_files stuff
Karel Zak [Wed, 8 Sep 2021 09:22:15 +0000 (11:22 +0200)] 
lsfd: cleanup collect_outofbox_files stuff

* use path_cxt
* call fstat() only once (no extra call to get uid)
* reduce names to variables to get function calls to one line ;-)
* fix use of procfs_process_get_cmdname()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: small cleanup to mountinfo/nodev code
Karel Zak [Wed, 8 Sep 2021 08:49:43 +0000 (10:49 +0200)] 
lsfd: small cleanup to mountinfo/nodev code

* use path_cxt to open mountinfo (so remove open_mountinfo())
* move all nodev code to one place
* merge add_nodev() to add_nodevs()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: use path_cxt to read process
Karel Zak [Wed, 8 Sep 2021 08:28:14 +0000 (10:28 +0200)] 
lsfd: use path_cxt to read process

* path_cxt is based on openat-like functions and lib/path.c provides
  large number of utils to use it
* one handler is re-used for all processes to reduce memory allocation
* list of process is moved to lsfd_control to make it available everywhere
* read tasks when we read process, no later
* lists initialization is done when object (process) is allocated

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: fix typo, rename function
Karel Zak [Tue, 7 Sep 2021 15:53:06 +0000 (17:53 +0200)] 
lsfd: fix typo, rename function

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobuild-sys: remove lib/procutils.c
Karel Zak [Tue, 7 Sep 2021 15:42:37 +0000 (17:42 +0200)] 
build-sys: remove lib/procutils.c

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:40:55 +0000 (17:40 +0200)] 
lsfd: use lib/procfs.c

4 years agolsns: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:40:04 +0000 (17:40 +0200)] 
lsns: use lib/procfs.c

4 years agolsipc: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:39:54 +0000 (17:39 +0200)] 
lsipc: use lib/procfs.c

4 years agouclampset: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:39:33 +0000 (17:39 +0200)] 
uclampset: use lib/procfs.c

4 years agotaskset: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:39:16 +0000 (17:39 +0200)] 
taskset: use lib/procfs.c

4 years agochrt: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:39:00 +0000 (17:39 +0200)] 
chrt: use lib/procfs.c

4 years agolslocks: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:38:47 +0000 (17:38 +0200)] 
lslocks: use lib/procfs.c

4 years agokill: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:38:31 +0000 (17:38 +0200)] 
kill: use lib/procfs.c

4 years agolib/caputils: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:38:04 +0000 (17:38 +0200)] 
lib/caputils: use lib/procfs.c

4 years agolslogins: use lib/procfs.c
Karel Zak [Tue, 7 Sep 2021 15:37:46 +0000 (17:37 +0200)] 
lslogins: use lib/procfs.c

4 years agolib/procfs: add functions to read /proc/#/ stuff
Karel Zak [Tue, 7 Sep 2021 15:32:01 +0000 (17:32 +0200)] 
lib/procfs: add functions to read /proc/#/ stuff

This is extension to lib/path.c (the same as lib/sysfs.c for block
devices) to read info about processes.

* replaces code from lib/procutils.c
* remove proc_{open,close}_processes(), opendir and readdir is good enough
* add procfs_dirent_*() functions to work with readdir() from /proc
* add new path_cxt based API (will be extended in next commits) for
  complex tasks

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/path: fstat dir itself
Karel Zak [Mon, 6 Sep 2021 09:52:09 +0000 (11:52 +0200)] 
lib/path: fstat dir itself

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: revert include/path.h use
Karel Zak [Thu, 2 Sep 2021 14:32:33 +0000 (16:32 +0200)] 
lsfd: revert include/path.h use

We need something better to handle work with processes.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: add reference to proc from file
Karel Zak [Thu, 2 Sep 2021 12:30:58 +0000 (14:30 +0200)] 
lsfd: add reference to proc from file

* add to file struct reference to process
* add file to the list of the process' files in new_file()

This makes things more straightforward.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: move list_free() to list.h
Karel Zak [Thu, 2 Sep 2021 12:13:49 +0000 (14:13 +0200)] 
lsfd: move list_free() to list.h

4 years agolsfd: reorder function
Karel Zak [Thu, 2 Sep 2021 12:00:44 +0000 (14:00 +0200)] 
lsfd: reorder function

Keep free_() after new_().

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: remove collect_file()
Karel Zak [Thu, 2 Sep 2021 11:58:49 +0000 (13:58 +0200)] 
lsfd: remove collect_file()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: cleanup new file initialization
Karel Zak [Wed, 1 Sep 2021 17:10:20 +0000 (19:10 +0200)] 
lsfd: cleanup new file initialization

Don't use new_<class>() functions if we have already have
file_class callbacks.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: keep main() at the end of the code
Karel Zak [Wed, 1 Sep 2021 16:12:09 +0000 (18:12 +0200)] 
lsfd: keep main() at the end of the code

and usage() before main().

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: use 'new_' prefix when we allocate something
Karel Zak [Wed, 1 Sep 2021 15:50:51 +0000 (17:50 +0200)] 
lsfd: use 'new_' prefix when we allocate something

It's more readable than rather than 'make_'.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: add --sysroot, use lib/path.c
Karel Zak [Wed, 1 Sep 2021 15:36:29 +0000 (17:36 +0200)] 
lsfd: add --sysroot, use lib/path.c

* use struct path_cxt to read from /procfs

* add --sysroot to redirect lsfd to alternative location (necessary
  for regression tests)

* merge collect_procs() into collect()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: add --notruncate
Karel Zak [Wed, 1 Sep 2021 14:50:04 +0000 (16:50 +0200)] 
lsfd: add --notruncate

* make COMMAND and NAME truncated by default (to keep output on terminal readable)
* add --notruncate to disable the default behaviour

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: tiny change to default colummns initialization
Karel Zak [Wed, 1 Sep 2021 14:35:42 +0000 (16:35 +0200)] 
lsfd: tiny change to default colummns initialization

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsfd: unify nodev lists into global one
Masatake YAMATO [Thu, 13 May 2021 20:24:21 +0000 (05:24 +0900)] 
lsfd: unify nodev lists into global one

4 years agolsfd: don't use threads
Masatake YAMATO [Thu, 13 May 2021 19:23:19 +0000 (04:23 +0900)] 
lsfd: don't use threads

4 years agolsfd: fill PROTONAME field of file for mmap'ed socket
Masatake YAMATO [Mon, 10 May 2021 03:56:56 +0000 (12:56 +0900)] 
lsfd: fill PROTONAME field of file for mmap'ed socket

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add MAPLEN column
Masatake YAMATO [Mon, 10 May 2021 03:54:55 +0000 (12:54 +0900)] 
lsfd: add MAPLEN column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: introduce a data structure for storing common fdinfo data
Masatake YAMATO [Mon, 10 May 2021 02:07:23 +0000 (11:07 +0900)] 
lsfd: introduce a data structure for storing common fdinfo data

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: increase the threads to collect information
Masatake YAMATO [Tue, 4 May 2021 17:50:14 +0000 (02:50 +0900)] 
lsfd: increase the threads to collect information

$ sudo ./lsfd -l | wc -l
75837

[NUM_COLLECTORS 1]
sudo ./lsfd -l > /dev/null  1.16s user 0.62s system 98% cpu 1.805 total
sudo ./lsfd -l > /dev/null  1.12s user 0.50s system 99% cpu 1.630 total
sudo ./lsfd -l > /dev/null  1.14s user 0.49s system 99% cpu 1.642 total

[NUM_COLLECTORS 2]
sudo ./lsfd -l > /dev/null  1.18s user 0.53s system 127% cpu 1.343 total
sudo ./lsfd -l > /dev/null  1.21s user 0.50s system 126% cpu 1.350 total
sudo ./lsfd -l > /dev/null  1.14s user 0.51s system 128% cpu 1.291 total

[NUM_COLLECTORS 3]
sudo ./lsfd -l > /dev/null  1.21s user 0.55s system 138% cpu 1.278 total
sudo ./lsfd -l > /dev/null  1.15s user 0.51s system 139% cpu 1.187 total
sudo ./lsfd -l > /dev/null  1.15s user 0.51s system 140% cpu 1.180 total

[NUM_COLLECTORS 4]
sudo ./lsfd -l > /dev/null  1.23s user 0.66s system 154% cpu 1.218 total
sudo ./lsfd -l > /dev/null  1.22s user 0.54s system 154% cpu 1.137 total
sudo ./lsfd -l > /dev/null  1.14s user 0.64s system 158% cpu 1.123 total

[NUM_COLLECTORS 5]
sudo ./lsfd -l > /dev/null  1.19s user 0.72s system 171% cpu 1.118 total
sudo ./lsfd -l > /dev/null  1.14s user 0.62s system 165% cpu 1.063 total
sudo ./lsfd -l > /dev/null  1.15s user 0.73s system 176% cpu 1.063 total

[NUM_COLLECTORS 6]
sudo ./lsfd -l > /dev/null  1.23s user 0.70s system 173% cpu 1.115 total
sudo ./lsfd -l > /dev/null  1.29s user 0.67s system 169% cpu 1.157 total
sudo ./lsfd -l > /dev/null  1.24s user 0.75s system 185% cpu 1.070 total

[NUM_COLLECTORS 7]
sudo ./lsfd -l > /dev/null  1.32s user 0.74s system 182% cpu 1.130 total
sudo ./lsfd -l > /dev/null  1.25s user 0.82s system 195% cpu 1.058 total
sudo ./lsfd -l > /dev/null  1.22s user 0.74s system 188% cpu 1.041 total

[NUM_COLLECTORS 8]
sudo ./lsfd -l > /dev/null  1.30s user 0.92s system 194% cpu 1.141 total
sudo ./lsfd -l > /dev/null  1.21s user 0.81s system 197% cpu 1.027 total
sudo ./lsfd -l > /dev/null  1.22s user 0.79s system 199% cpu 1.005 total

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: introduce DEVNAME column and use it as default
Masatake YAMATO [Sun, 9 May 2021 03:16:43 +0000 (12:16 +0900)] 
lsfd: introduce DEVNAME column and use it as default

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add a function to get the name of filesystem from a given minor number
Masatake YAMATO [Sun, 9 May 2021 01:41:34 +0000 (10:41 +0900)] 
lsfd: add a function to get the name of filesystem from a given minor number

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add a stub for fifo type
Masatake YAMATO [Sun, 9 May 2021 02:36:07 +0000 (11:36 +0900)] 
lsfd: add a stub for fifo type

4 years agolsfd: add MISCDEV column
Masatake YAMATO [Fri, 7 May 2021 19:47:23 +0000 (04:47 +0900)] 
lsfd: add MISCDEV column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: read misc character device names from /proc/misc
Masatake YAMATO [Fri, 7 May 2021 19:46:11 +0000 (04:46 +0900)] 
lsfd: read misc character device names from /proc/misc

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add CHRDRV column
Masatake YAMATO [Fri, 7 May 2021 18:51:25 +0000 (03:51 +0900)] 
lsfd: add CHRDRV column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: read character driver names from /proc/devices
Masatake YAMATO [Fri, 7 May 2021 18:50:16 +0000 (03:50 +0900)] 
lsfd: read character driver names from /proc/devices

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: add PARTITION column
Masatake YAMATO [Fri, 7 May 2021 18:28:46 +0000 (03:28 +0900)] 
lsfd: add PARTITION column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: read /proc/partitions
Masatake YAMATO [Fri, 7 May 2021 18:25:30 +0000 (03:25 +0900)] 
lsfd: read /proc/partitions

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
4 years agolsfd: introduce name_manager
Masatake YAMATO [Fri, 7 May 2021 16:50:20 +0000 (01:50 +0900)] 
lsfd: introduce name_manager

Signed-off-by: Masatake YAMATO <yamato@redhat.com>