Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Make swallowing more robust
Browse files Browse the repository at this point in the history
Changed the flags for the pstree command so it is a single line with all
ancestors.
Removed usage of sed, grep and tr so the iopopen call should be faster.
Find and match of parent pid in the ancestors string is done in lua so
should be faster.
  • Loading branch information
eylles committed Nov 9, 2021
1 parent 3c8b3b8 commit 32a528a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions module/window_swallowing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ local function manage_clientspawn(c)
end

-- io.popen is normally discouraged. Should probably be changed
local handle = io.popen(
[[pstree -T -p -a -s ]]
.. tostring(c.pid)
.. [[ | sed '2q;d' | grep -o '[0-9]*$' | tr -d '\n']]
)
-- returns "init(1)---ancestorA(pidA)---ancestorB(pidB)...---process(pid)"
local handle = io.popen("pstree -A -p -s " .. tostring(c.pid))
local parent_pid = handle:read("*a")
handle:close()

if
(tostring(parent_pid) == tostring(parent_client.pid))
-- will search for "(parent_client.pid)" inside the parent_pid string
( tostring(parent_pid):find("("..tostring(parent_client.pid)..")") )
and check_if_swallow(c)
then
c:connect_signal("unmanage", function()
Expand Down

0 comments on commit 32a528a

Please sign in to comment.