Skip to content

Commit 3d5ca37

Browse files
authored
No more failing UI tests! (#1857)
* Better debug for UI tests * No more failing UI tests!
1 parent faba135 commit 3d5ca37

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pwnlib/term/term.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import division
33

44
import atexit
5+
import errno
56
import os
67
import re
78
import signal
@@ -110,7 +111,12 @@ def init():
110111
fd.flush()
111112
s = ''
112113
while True:
113-
c = os.read(fd.fileno(), 1)
114+
try:
115+
c = os.read(fd.fileno(), 1)
116+
except OSError as e:
117+
if e.errno != errno.EINTR:
118+
raise
119+
continue
114120
if not isinstance(c, six.string_types):
115121
c = c.decode('utf-8')
116122
s += c

pwnlib/ui.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ def handleusr1(sig, frame):
2828
s = p.stderr.read()
2929
log.error("child process failed:\n%s", s.decode())
3030
signal.signal(signal.SIGUSR1, handleusr1)
31-
cmd = """
32-
from pwn import *
31+
cmd = """\
32+
import os
3333
import signal
34-
atexception.register(lambda:os.kill(os.getppid(), signal.SIGUSR1))
34+
import sys
35+
_ehook = sys.excepthook
36+
def ehook(*args):
37+
_ehook(*args)
38+
os.kill(os.getppid(), signal.SIGUSR1)
39+
sys.excepthook = ehook
40+
from pwn import *
3541
""" + cmd
3642
if "coverage" in sys.modules:
3743
cmd = "import coverage; coverage.process_startup()\n" + cmd
@@ -41,6 +47,7 @@ def handleusr1(sig, frame):
4147
p.recvuntil(b"\33[6n")
4248
except EOFError:
4349
raise EOFError("process terminated with code: %r (%r)" % (p.poll(True), p.stderr.read()))
50+
# late initialization can lead to EINTR in many places
4451
fcntl.ioctl(p.stdout.fileno(), termios.TIOCSWINSZ, struct.pack("hh", 80, 80))
4552
p.stdout.write(b"\x1b[1;1R")
4653
time.sleep(0.5)

0 commit comments

Comments
 (0)