"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/tty-steal.py" between
reptyr-reptyr-0.7.0.tar.gz and reptyr-reptyr-0.8.0.tar.gz

About: reptyr is a utility for taking an existing running program and attaching it to a new terminal.

tty-steal.py  (reptyr-reptyr-0.7.0):tty-steal.py  (reptyr-reptyr-0.8.0)
import pexpect import pexpect
import os import os
import sys import sys
from util import expect_eof
if os.getenv("NO_TEST_STEAL") is not None: if os.getenv("NO_TEST_STEAL") is not None:
print("Skipping tty-stealing tests because $NO_TEST_STEAL is set.") print("Skipping tty-stealing tests because $NO_TEST_STEAL is set.")
sys.exit(0) sys.exit(0)
logfile = sys.stdout
if sys.version_info[0] >= 3:
logfile = logfile.buffer
did_prctl = False did_prctl = False
try: try:
import prctl import prctl
PR_SET_PTRACER_ANY = 0xffffffff PR_SET_PTRACER_ANY = 0xffffffff
if hasattr(prctl, 'set_ptracer'): if hasattr(prctl, 'set_ptracer'):
did_prctl = True did_prctl = True
prctl.set_ptracer(PR_SET_PTRACER_ANY) prctl.set_ptracer(PR_SET_PTRACER_ANY)
except ImportError: except ImportError:
pass pass
if not did_prctl: if not did_prctl:
print("Unable to find `prctl.set_ptracer`, skipping `PR_SET_PTRACER`.") print("Unable to find `prctl.set_ptracer`, skipping `PR_SET_PTRACER`.")
child = pexpect.spawn("test/victim") child = pexpect.spawn("test/victim")
child.setecho(False) child.setecho(False)
child.sendline("hello") child.sendline("hello")
child.expect("ECHO: hello") child.expect("ECHO: hello")
reptyr = pexpect.spawn("./reptyr -V -T %d" % (child.pid,)) reptyr = pexpect.spawn("./reptyr -V -T %d" % (child.pid,))
print("spawned children: me={} victim={} reptyr={}".format(os.getpid(), child.pi d, reptyr.pid)) print("spawned children: me={} victim={} reptyr={}".format(os.getpid(), child.pi d, reptyr.pid))
reptyr.logfile = sys.stdout reptyr.logfile = logfile
reptyr.sendline("world") reptyr.sendline("world")
reptyr.expect("ECHO: world") reptyr.expect("ECHO: world")
child.sendline("final") child.sendline("final")
child.expect(pexpect.EOF) expect_eof(child.child_fd)
assert os.stat("/dev/null").st_rdev == os.fstat(child.fileno()).st_rdev assert os.stat("/dev/null").st_rdev == os.fstat(child.fileno()).st_rdev
reptyr.sendeof() reptyr.sendeof()
reptyr.expect(pexpect.EOF) reptyr.expect(pexpect.EOF)
assert not reptyr.isalive() assert not reptyr.isalive()
 End of changes. 4 change blocks. 
2 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)