From 19c6e483982456b9cf78c87b9cf3c90e98d63024 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 23 Apr 2023 14:48:46 +0800 Subject: [PATCH] backport fix Fo option -Fo option is for printing file offset. For regular files, the option didn't work. Here is a command session demonstrating the fix: # ./lsof -Fo -o0| grep ^o | sort | uniq -c 90586 o0t0 87 o0t101 84 o0t103 ... Signed-off-by: Masatake YAMATO Reference:https://github.com/lsof-org/lsof/commit/6435e7667cbf5b1a616606aa019892df43f3ade1 Conflict:NA --- main.c | 4 ++++ tests/case-20-offset-field.bash | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/case-20-offset-field.bash diff --git a/main.c b/main.c index 169e334..9e3bbd8 100644 --- a/main.c +++ b/main.c @@ -554,6 +554,10 @@ main(argc, argv) if (i == LSOF_FIX_TERM) Terminator = '\0'; + + if (i == LSOF_FIX_OFFSET) + Foffset = 1; + break; } } diff --git a/tests/case-20-offset-field.bash b/tests/case-20-offset-field.bash new file mode 100644 index 0000000..a5dc369 --- /dev/null +++ b/tests/case-20-offset-field.bash @@ -0,0 +1,24 @@ +name=$(basename $0 .bash) +lsof=$1 +report=$2 +base=$(pwd) + +t=/tmp/lsof-test-reg-file-$$ +p=/tmp/lsof-test-reg-fifo-$$ + +mkfifo $p +{ + printf "%d" 1 + read < $p & +} | cat > $t & + +r=1 +if [ "$($lsof -Fo $t | grep '^o')" = o0t1 ]; then + echo > $p + r=0 +fi + +rm /tmp/lsof-test-reg-file-$$ +rm /tmp/lsof-test-reg-fifo-$$ + +exit $r -- 2.27.0