Skip to content

Commit

Permalink
Properly close spawned kitty window (#2471)
Browse files Browse the repository at this point in the history
* properly close spawned kitty window

* python2 support

* changelog
  • Loading branch information
k4lizen authored Sep 27, 2024
1 parent cdfd64f commit 785ed9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ The table below shows which release corresponds to each branch, and what date th

## 4.15.0 (`dev`)

- [#2471][2471] Properly close spawned kitty window
- [#2358][2358] Cache output of `asm()`
- [#2457][2457] Catch exception of non-ELF files in checksec.
- [#2444][2444] Add `ELF.close()` to release resources

[2471]: https://github.com/Gallopsled/pwntools/pull/2471
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
[2457]: https://github.com/Gallopsled/pwntools/pull/2457
[2444]: https://github.com/Gallopsled/pwntools/pull/2444
Expand Down
16 changes: 15 additions & 1 deletion pwnlib/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
log.debug("Launching a new terminal: %r" % argv)

stdin = stdout = stderr = open(os.devnull, 'r+b')
if terminal == 'tmux':
if terminal == 'tmux' or terminal == 'kitty':
stdout = subprocess.PIPE

p = subprocess.Popen(argv, stdin=stdin, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn)

kittyid = None

if terminal == 'tmux':
out, _ = p.communicate()
try:
Expand All @@ -460,6 +462,16 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
with subprocess.Popen((qdbus, konsole_dbus_service, '/Sessions/{}'.format(last_konsole_session),
'org.kde.konsole.Session.processId'), stdout=subprocess.PIPE) as proc:
pid = int(proc.communicate()[0].decode())
elif terminal == 'kitty':
pid = p.pid

out, _ = p.communicate()
try:
kittyid = int(out)
except ValueError:
kittyid = None
if kittyid is None:
log.error("Could not parse kitty window ID from output (%r)", out)
else:
pid = p.pid

Expand All @@ -468,6 +480,8 @@ def kill():
try:
if terminal == 'qdbus':
os.kill(pid, signal.SIGHUP)
elif terminal == 'kitty':
subprocess.Popen(["kitten", "@", "close-window", "--match", "id:{}".format(kittyid)])
else:
os.kill(pid, signal.SIGTERM)
except OSError:
Expand Down

0 comments on commit 785ed9f

Please sign in to comment.