]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
3 years agolsfd: cleanup --summary semantic
Karel Zak [Wed, 24 Nov 2021 14:00:45 +0000 (15:00 +0100)] 
lsfd: cleanup --summary semantic

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolsfd: add --dump-counters option
Masatake YAMATO [Thu, 18 Nov 2021 15:14:50 +0000 (00:14 +0900)] 
lsfd: add --dump-counters option

User may wonder how the built-in counters are defined.
Describing their definitions in lsfd(1) is one of choice.
However, the definitions may drastically change in the future
development.

--dump-counters option is for making lsfd self descriptive.
Users who understand the filter expressions can understand
directly the meaning of the counters.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.doc: write anout --summary and --counter options
Masatake YAMATO [Thu, 18 Nov 2021 15:11:13 +0000 (00:11 +0900)] 
lsfd.1.doc: write anout --summary and --counter options

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: implement --summary and --counter options
Masatake YAMATO [Sun, 31 Oct 2021 19:52:48 +0000 (04:52 +0900)] 
lsfd: implement --summary and --counter options

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: add a helper function for building filter
Masatake YAMATO [Fri, 29 Oct 2021 21:53:30 +0000 (06:53 +0900)] 
lsfd: add a helper function for building filter

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (filter) make some data structures its source file local
Masatake YAMATO [Sat, 13 Nov 2021 10:48:16 +0000 (19:48 +0900)] 
lsfd: (filter) make some data structures its source file local

Unintentionally they were extern'ed.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: don't define a local variable in the middle of a block
Masatake YAMATO [Sat, 13 Nov 2021 10:14:34 +0000 (19:14 +0900)] 
lsfd: don't define a local variable in the middle of a block

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.doc: use delimited literal block notation in the EXAMPLE section
Masatake YAMATO [Thu, 18 Nov 2021 14:43:11 +0000 (23:43 +0900)] 
lsfd.1.doc: use delimited literal block notation in the EXAMPLE section

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.adoc: remove redundant parenthesis from the examples
Masatake YAMATO [Tue, 16 Nov 2021 19:58:51 +0000 (04:58 +0900)] 
lsfd.1.adoc: remove redundant parenthesis from the examples

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.adoc: add caution about the CLI stability
Masatake YAMATO [Tue, 16 Nov 2021 19:53:20 +0000 (04:53 +0900)] 
lsfd.1.adoc: add caution about the CLI stability

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.adoc: fix a typo
Masatake YAMATO [Tue, 16 Nov 2021 19:56:09 +0000 (04:56 +0900)] 
lsfd.1.adoc: fix a typo

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd.1.adoc: Add missing underscores
Mario Blättermann [Tue, 2 Nov 2021 13:00:24 +0000 (14:00 +0100)] 
lsfd.1.adoc: Add missing underscores

3 years agolsfd: remove unused --sysroot
Karel Zak [Tue, 2 Nov 2021 08:15:13 +0000 (09:15 +0100)] 
lsfd: remove unused --sysroot

It's unnecessary to redirect to any /proc dump if we can use 'test_mkfds'.

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolsfd: delete an unnecessary semicolon
Masatake YAMATO [Fri, 22 Oct 2021 08:10:02 +0000 (17:10 +0900)] 
lsfd: delete an unnecessary semicolon

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: introduce -p/--pid option, pids filter working in the early stage
Masatake YAMATO [Fri, 22 Oct 2021 03:48:47 +0000 (12:48 +0900)] 
lsfd: introduce -p/--pid option, pids filter working in the early stage

    $ time sudo ./lsfd -Q '(PID == 1) or (PID == 2)' > /dev/null

    real 0m0.508s
    user 0m0.230s
    sys 0m0.267s

    $ time sudo ./lsfd -p 1,2 > /dev/null

    real 0m0.088s
    user 0m0.036s
    sys 0m0.033s

    $ [ $(./lsfd -p 1,2) = $(./lsfd -Q '(PID == 1) or (PID == 2)') ]
    $ echo $?
    0

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: introduce -p/--pid option, pids filter working in the early stage
Masatake YAMATO [Fri, 22 Oct 2021 03:48:47 +0000 (12:48 +0900)] 
lsfd: introduce -p/--pid option, pids filter working in the early stage

    $ time sudo ./lsfd -Q '(PID == 1) or (PID == 2)' > /dev/null

    real 0m0.508s
    user 0m0.230s
    sys 0m0.267s

    $ time sudo ./lsfd -p 1,2 > /dev/null

    real 0m0.088s
    user 0m0.036s
    sys 0m0.033s

    $ [ $(./lsfd -p 1,2) = $(./lsfd -Q '(PID == 1) or (PID == 2)') ]
    $ echo $?
    0

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (adoc) add more exapmles
Masatake YAMATO [Wed, 20 Oct 2021 14:22:28 +0000 (23:22 +0900)] 
lsfd: (adoc) add more exapmles

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: remove --source option
Masatake YAMATO [Wed, 20 Oct 2021 13:29:45 +0000 (22:29 +0900)] 
lsfd: remove --source option

-Q '(SOURCE == ...)' works well for the same purpose.
See https://github.com/karelzak/util-linux/pull/1418#issuecomment-945643880

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: add KTHREAD column
Masatake YAMATO [Tue, 19 Oct 2021 08:05:08 +0000 (17:05 +0900)] 
lsfd: add KTHREAD column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for displaying symlinks
Masatake YAMATO [Fri, 15 Oct 2021 20:38:49 +0000 (05:38 +0900)] 
lsfd: (test) add a case for displaying symlinks

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for displaying COMMAND column
Masatake YAMATO [Fri, 15 Oct 2021 19:24:28 +0000 (04:24 +0900)] 
lsfd: (test) add a case for displaying COMMAND column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for displaying socket pairs
Masatake YAMATO [Fri, 15 Oct 2021 18:48:43 +0000 (03:48 +0900)] 
lsfd: (test) add a case for displaying socket pairs

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for displaying DEV column
Masatake YAMATO [Fri, 15 Oct 2021 17:47:03 +0000 (02:47 +0900)] 
lsfd: (test) add a case for displaying DEV column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) improve the code converting file descriptor numbers
Masatake YAMATO [Fri, 15 Oct 2021 17:34:38 +0000 (02:34 +0900)] 
lsfd: (helper) improve the code converting file descriptor numbers

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for displaying a character device
Masatake YAMATO [Fri, 15 Oct 2021 16:42:57 +0000 (01:42 +0900)] 
lsfd: (test) add a case for displaying a character device

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: add --debug-filter option
Masatake YAMATO [Fri, 15 Oct 2021 02:24:23 +0000 (11:24 +0900)] 
lsfd: add --debug-filter option

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for testing SIZE column
Masatake YAMATO [Fri, 15 Oct 2021 02:04:27 +0000 (11:04 +0900)] 
lsfd: (test) add a case for testing SIZE column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) add a case for testing FLAGS (wronly,nonblock) column
Masatake YAMATO [Fri, 15 Oct 2021 01:59:05 +0000 (10:59 +0900)] 
lsfd: (test) add a case for testing FLAGS (wronly,nonblock) column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) add "nonblock" parameter to pipe-no-fork factory
Masatake YAMATO [Fri, 15 Oct 2021 01:58:03 +0000 (10:58 +0900)] 
lsfd: (helper) add "nonblock" parameter to pipe-no-fork factory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) update examples in the help message
Masatake YAMATO [Fri, 15 Oct 2021 01:28:09 +0000 (10:28 +0900)] 
lsfd: (helper) update examples in the help message

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) add "dentries" parameter to directory factory
Masatake YAMATO [Thu, 14 Oct 2021 15:17:43 +0000 (00:17 +0900)] 
lsfd: (helper) add "dentries" parameter to directory factory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) add "dir" parameter to directory factory
Masatake YAMATO [Thu, 14 Oct 2021 15:01:49 +0000 (00:01 +0900)] 
lsfd: (helper) add "dir" parameter to directory factory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (test) test POS column
Masatake YAMATO [Thu, 14 Oct 2021 13:55:28 +0000 (22:55 +0900)] 
lsfd: (test) test POS column

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) add "offset" parameter to ro-regular-file factory
Masatake YAMATO [Thu, 14 Oct 2021 13:51:49 +0000 (22:51 +0900)] 
lsfd: (helper) add "offset" parameter to ro-regular-file factory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) accept an integer argument for a parameter
Masatake YAMATO [Thu, 14 Oct 2021 13:51:18 +0000 (22:51 +0900)] 
lsfd: (helper) accept an integer argument for a parameter

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) add "file" parameter to ro-regular-file factory
Masatake YAMATO [Thu, 14 Oct 2021 09:49:34 +0000 (18:49 +0900)] 
lsfd: (helper) add "file" parameter to ro-regular-file factory

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) allow to pass extra parameters
Masatake YAMATO [Thu, 14 Oct 2021 09:47:39 +0000 (18:47 +0900)] 
lsfd: (helper) allow to pass extra parameters

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) use more "const" modifiers
Masatake YAMATO [Thu, 14 Oct 2021 09:34:48 +0000 (18:34 +0900)] 
lsfd: (helper) use more "const" modifiers

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (helper) set proper errno before calling err()
Masatake YAMATO [Thu, 14 Oct 2021 13:46:30 +0000 (22:46 +0900)] 
lsfd: (helper) set proper errno before calling err()

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (filter) accept % char as a part of column name
Masatake YAMATO [Fri, 15 Oct 2021 21:08:38 +0000 (06:08 +0900)] 
lsfd: (filter) accept % char as a part of column name

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: (filter) fix a memory leak
Masatake YAMATO [Thu, 21 Oct 2021 11:54:38 +0000 (20:54 +0900)] 
lsfd: (filter) fix a memory leak

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: remove prototype decls for removed functions
Masatake YAMATO [Sun, 17 Oct 2021 11:01:09 +0000 (20:01 +0900)] 
lsfd: remove prototype decls for removed functions

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agolsfd: declare local variables at the beginning of block
Masatake YAMATO [Thu, 21 Oct 2021 12:01:28 +0000 (21:01 +0900)] 
lsfd: declare local variables at the beginning of block

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 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>
3 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

3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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

3 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>
3 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>
3 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>
3 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>
3 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

3 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

3 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

3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>