mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-16 09:37:12 +00:00
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
This commit is contained in:
parent
13eeef7c6c
commit
dee2b0f8c4
18
tomb
18
tomb
@ -3192,10 +3192,8 @@ umount_tomb() {
|
|||||||
|
|
||||||
list_processes() {
|
list_processes() {
|
||||||
# $1 = (optional) name of tomb
|
# $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 mounted_tombs i
|
||||||
local pnum puid pcmd powner found
|
|
||||||
found=0
|
|
||||||
mounted_tombs=(`list_tomb_mounts $1`)
|
mounted_tombs=(`list_tomb_mounts $1`)
|
||||||
if [[ "${#mounted_tombs}" -gt 0 ]]; then
|
if [[ "${#mounted_tombs}" -gt 0 ]]; then
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
@ -3207,21 +3205,9 @@ list_processes() {
|
|||||||
for i in ${mounted_tombs}; do
|
for i in ${mounted_tombs}; do
|
||||||
_verbose "scanning tomb: ::1 tombmount::" $i
|
_verbose "scanning tomb: ::1 tombmount::" $i
|
||||||
tombmount="${i[(ws:;:)2]}"
|
tombmount="${i[(ws:;:)2]}"
|
||||||
tombname=${i[(ws:;:)5]}
|
_sudo lsof +D "${i[(ws:;:)2]}"
|
||||||
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
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
_message "::1 foundproc:: running processes found inside ::2 numtombs:: open tombs" \
|
|
||||||
$found ${#mounted_tombs}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user