"Fossies" - the Fresh Open Source Software Archive

Member "reptyr-reptyr-0.8.0/test/tty-steal.py" (29 Sep 2020, 1129 Bytes) of package /linux/privat/reptyr-reptyr-0.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "tty-steal.py": 0.7.0_vs_0.8.0.

    1 import pexpect
    2 import os
    3 import sys
    4 
    5 from util import expect_eof
    6 
    7 if os.getenv("NO_TEST_STEAL") is not None:
    8     print("Skipping tty-stealing tests because $NO_TEST_STEAL is set.")
    9     sys.exit(0)
   10 
   11 logfile = sys.stdout
   12 if sys.version_info[0] >= 3:
   13     logfile = logfile.buffer
   14 
   15 did_prctl = False
   16 try:
   17     import prctl
   18     PR_SET_PTRACER_ANY = 0xffffffff
   19     if hasattr(prctl, 'set_ptracer'):
   20         did_prctl = True
   21         prctl.set_ptracer(PR_SET_PTRACER_ANY)
   22 except ImportError:
   23     pass
   24 
   25 if not did_prctl:
   26   print("Unable to find `prctl.set_ptracer`, skipping `PR_SET_PTRACER`.")
   27 
   28 child = pexpect.spawn("test/victim")
   29 child.setecho(False)
   30 child.sendline("hello")
   31 child.expect("ECHO: hello")
   32 
   33 reptyr = pexpect.spawn("./reptyr -V -T %d" % (child.pid,))
   34 print("spawned children: me={} victim={} reptyr={}".format(os.getpid(), child.pid, reptyr.pid))
   35 reptyr.logfile = logfile
   36 
   37 reptyr.sendline("world")
   38 reptyr.expect("ECHO: world")
   39 
   40 child.sendline("final")
   41 expect_eof(child.child_fd)
   42 assert os.stat("/dev/null").st_rdev == os.fstat(child.fileno()).st_rdev
   43 
   44 reptyr.sendeof()
   45 reptyr.expect(pexpect.EOF)
   46 assert not reptyr.isalive()