From dee2b0f8c4980be22599b2e2c48c6ed1915453de Mon Sep 17 00:00:00 2001 From: Narrat Date: Sun, 7 Jan 2024 20:23:20 +0100 Subject: [PATCH] list_processes: use lsof to list processes Parsing the output from lsof had possibilities for race conditions. Either due to short lived processes or issuing "tomb ps" from a terminal which cwd is from inside the tomb. This would spit out available users on the system. To avoid this use the lsof output directly. In the future formatting could be reintroduced via commands like "lsof +D "$tombmount" -F Lc" or "lsof +D "$tombmount" -F Lc0". This fixes #503 --- tomb | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tomb b/tomb index 83257e0..779fe5b 100755 --- a/tomb +++ b/tomb @@ -3192,10 +3192,8 @@ umount_tomb() { list_processes() { # $1 = (optional) name of tomb - # returns a list of process UIDs, one per line + # runs lsof on the mounted_tombs local mounted_tombs i - local pnum puid pcmd powner found - found=0 mounted_tombs=(`list_tomb_mounts $1`) if [[ "${#mounted_tombs}" -gt 0 ]]; then if [[ -z $1 ]]; then @@ -3207,21 +3205,9 @@ list_processes() { for i in ${mounted_tombs}; do _verbose "scanning tomb: ::1 tombmount::" $i tombmount="${i[(ws:;:)2]}" - tombname=${i[(ws:;:)5]} - for pnum in ${(f)"$(_sudo lsof -t +D "$tombmount")"}; do - found=$(($found + 1)) - _verbose "process found: $pnum" - puid=$(cat /proc/${pnum}/loginuid) - pcmd=$(cat /proc/${pnum}/cmdline) - powner=`_get_username $puid` - _verbose "process found: $pnum $pcmd ($powner)" - _message "::1 tombname:: ::2 cmd:: (::3 owner::)" \ - $tombname $pcmd $powner - done + _sudo lsof +D "${i[(ws:;:)2]}" done fi - _message "::1 foundproc:: running processes found inside ::2 numtombs:: open tombs" \ - $found ${#mounted_tombs} return 0 }