Skip to content

Commit 9627acf

Browse files
committed
get kitty pid and sigterm instead of close-window
1 parent 70b4515 commit 9627acf

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pwnlib/util/misc.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import division
22

3+
import json
34
import base64
45
import errno
56
import os
@@ -468,15 +469,23 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
468469
'org.kde.konsole.Session.processId'), stdout=subprocess.PIPE) as proc:
469470
pid = int(proc.communicate()[0].decode())
470471
elif terminal in ('kitty', 'kitten'):
471-
pid = p.pid
472-
472+
pid = None
473473
out, _ = p.communicate()
474474
try:
475475
kittyid = int(out)
476476
except ValueError:
477477
kittyid = None
478478
if kittyid is None:
479479
log.error("Could not parse kitty window ID from output (%r)", out)
480+
else:
481+
lsout, _ = subprocess.Popen(["kitten", "@", "ls", "--match", "id:%d" % kittyid], stdin=stdin, stdout=stdout, stderr=stderr).communicate()
482+
try:
483+
lsj = json.loads(lsout)
484+
pid = int(lsj[0]["tabs"][0]["windows"][0]["pid"])
485+
except json.JSONDecodeError as e:
486+
pid = None
487+
log.error("Json decode failed while parsing 'kitten @ ls' output (%r) (error: %r)", lsout, e)
488+
480489
elif terminal == 'cmd.exe':
481490
# p.pid is cmd.exe's pid instead of the WSL process we want to start eventually.
482491
# I don't know how to trace the execution through Windows and back into the WSL2 VM.
@@ -501,8 +510,6 @@ def kill():
501510
try:
502511
if terminal == 'qdbus':
503512
os.kill(pid, signal.SIGHUP)
504-
elif terminal in ('kitty', 'kitten'):
505-
subprocess.Popen(["kitten", "@", "close-window", "--match", "id:{}".format(kittyid)], stderr=stderr)
506513
else:
507514
os.kill(pid, signal.SIGTERM)
508515
except OSError:

0 commit comments

Comments
 (0)