Skip to content

Commit

Permalink
list_processes: use lsof to list processes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Narrat authored and jaromil committed Jan 25, 2024
1 parent 13eeef7 commit dee2b0f
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions tomb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit dee2b0f

Please sign in to comment.