]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslocks: special-case PID for filtering (skip −1)
authorMasatake YAMATO <yamato@redhat.com>
Mon, 29 Dec 2025 07:22:24 +0000 (16:22 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 29 Dec 2025 08:08:32 +0000 (17:08 +0900)
The PID column may be printed as −1 for locks that are not tied to a
process or are inaccessible to lslocks (e.g., permission constraints).
The libsmartcols filter engine does not support negative integers, so
PID = −1 cannot be compared reliably.

Attach the PID as cell userdata only when PID >= 0, and use that value
for filter evaluation. Rows with PID = −1 are thus excluded from PID
comparisons.

No change to printed output.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lslocks.8.adoc
misc-utils/lslocks.c

index 46b75d2af6c95ecb4511067fb6e617ff86164160..31829eb432f9ba5ac67a84194ad7dda1ac05cb9d 100644 (file)
@@ -140,6 +140,10 @@ the holder process of a lease (or a lock) is not uniquely determined.
 
 The default output is subject to change. So whenever possible, you should avoid using default output in your scripts.
 
+For OFD locks, the PID column may show -1. Such lines cannot be
+selected by the filter, because the current filter engine does not
+support negative numbers.
+
 == AUTHORS
 
 mailto:dave@gnu.org[Davidlohr Bueso]
index 2fe36feb99aa93b20003f276f403a80b7affe0bc..00dff4f765fd308f9eada0c3dd84a7479c22e9f8 100644 (file)
@@ -635,6 +635,8 @@ static char *get_data(struct lslocks *lslocks, struct lock *l, int num,
                break;
        case COL_PID:
                xasprintf(&str, "%d", l->pid);
+               if (l->pid >= 0)
+                       *rawdata = (uint64_t)l->pid;
                break;
        case COL_TYPE:
                xasprintf(&str, "%s", l->type);
@@ -1028,7 +1030,7 @@ static void init_scols_filter(struct libscols_table *tb, struct libscols_filter
                        scols_column_set_json_type(col, json_type);
                }
 
-               if (id == COL_SIZE && !bytes) {
+               if ((id == COL_SIZE && !bytes) || id == COL_PID) {
                        scols_column_set_data_type(col, SCOLS_DATA_U64);
                        scols_column_set_data_func(col, get_u64_cell, NULL);
                }