From: Masatake YAMATO Date: Mon, 29 Dec 2025 07:22:24 +0000 (+0900) Subject: lslocks: special-case PID for filtering (skip −1) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c492f0fc468de0fce6650501ea0e74ca2c687efd;p=thirdparty%2Futil-linux.git lslocks: special-case PID for filtering (skip −1) 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 --- diff --git a/misc-utils/lslocks.8.adoc b/misc-utils/lslocks.8.adoc index 46b75d2af..31829eb43 100644 --- a/misc-utils/lslocks.8.adoc +++ b/misc-utils/lslocks.8.adoc @@ -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] diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index 2fe36feb9..00dff4f76 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -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); }