Skip to content

Commit

Permalink
Merge pull request #319 from lsof-org/fix-pidfs-display-linux-6.9
Browse files Browse the repository at this point in the history
Fix pidfs display linux 6.9
  • Loading branch information
jiegec authored May 17, 2024
2 parents 0a979c5 + c1678e3 commit cd5bb9b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions 00DIST
Original file line number Diff line number Diff line change
Expand Up @@ -5605,6 +5605,9 @@ Supplement Regenerated the 4.04 distribution to correct a non-

[linux] Do not embed kernel version in CFLAGS (#314)

[linux] Linux 6.9 changed the pidfs appearence in procfs. Try
to maintain original output in lsof (#317)


Vic Abell <abe@purdue.edu>
July 14, 2018
Expand Down
13 changes: 13 additions & 0 deletions lib/dialects/linux/dproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,10 @@ static int process_id(struct lsof_context *ctx, /* context */
#endif /* defined(HASEPTOPTS) */
if (rest && rest[0] == '[' && rest[1] == 'p')
fdinfo_mask |= FDINFO_PID;
else if (Lf->ntype == N_REGLR && rest && *rest && strcmp(pbuf, "pidfd") == 0) {
// https://github.com/lsof-org/lsof/issues/317
fdinfo_mask |= FDINFO_PID;
}

if ((av = get_fdinfo(ctx, pathi, fdinfo_mask, &fi)) &
FDINFO_POS) {
Expand Down Expand Up @@ -1338,6 +1342,15 @@ static int process_id(struct lsof_context *ctx, /* context */
Lf->sf |= SELPTYINFO;
}
#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */
else if (Lf->ntype == N_REGLR && rest && *rest && Lf->nm &&
strcmp(Lf->nm, "pidfd") == 0) {
// https://github.com/lsof-org/lsof/issues/317
// pidfd since Linux 6.9 becomes a regular file:
// /proc/PID/fd/FD -> pidfd:[INODE]
(void)snpf(rest, sizeof(pbuf) - (rest - pbuf),
"[pidfd:%d]", fi.pid);
enter_nm(ctx, rest);
}

if (Lf->sf)
link_lfile(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ expectation="n[${v6addr}]:$port"
result=1
if "${lsof}" -p "${pid}" -a -d fd -P -n -F n \
| tee -a "${report}" \
| fgrep -q "$expectation"; then
| grep -Fq "$expectation"; then
result=0
fi

Expand Down
2 changes: 1 addition & 1 deletion lib/dialects/linux/tests/case-20-pidfd-pid.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $TARGET | (
exit 77
fi
line=$($lsof -p $pid -a -d $fd -F pfn| tr '\n' ' ')
if ! fgrep -q "p${pid} f${fd} n[pidfd:$pid]" <<<"$line"; then
if ! grep -Fq "p${pid} f${fd} n[pidfd:$pid]" <<<"$line"; then
$lsof -p $pid -a -d $fd -F pfn
echo
echo $line
Expand Down

0 comments on commit cd5bb9b

Please sign in to comment.