python: specify python2 as .py interpreter
On some distro the default python interpreter is Python 3,
which results in such errors:
> Running zdtm/static/socket-tcp-closed.hook(--post-start)
> make[1]: Nothing to be done for default.
> ./socket-tcp-closed --pidfile=socket-tcp-closed.pid --outfile=socket-tcp-closed.out
> File "zdtm/static/socket-tcp-closed.hook", line 16
> except OSError, e:
> ^
> SyntaxError: invalid syntax
> ######### Test zdtm/static/socket-tcp-closed FAIL at hook --post-start #########
> Running zdtm/static/socket-tcp-closed.hook(--clean)
> File "zdtm/static/socket-tcp-closed.hook", line 16
> except OSError, e:
> ^
> SyntaxError: invalid syntax
> Traceback (most recent call last):
> File "zdtm.py", line 1921, in <module>
> do_run_test(tinfo[0], tinfo[1], tinfo[2], tinfo[3])
> File "zdtm.py", line 1388, in do_run_test
> try_run_hook(t, ["--clean"])
> File "zdtm.py", line 1053, in try_run_hook
> raise test_fail_exc("hook " + " ".join(args))
> __main__.test_fail_exc: <__main__.test_fail_exc instance at 0x76294468>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-04-10 22:41:52 +03:00
|
|
|
#!/usr/bin/env python2
|
2015-12-25 17:49:37 +03:00
|
|
|
import subprocess
|
2016-02-13 21:06:00 +03:00
|
|
|
import os, sys, time, signal, pty
|
2015-12-25 17:49:37 +03:00
|
|
|
|
|
|
|
master, slave = pty.openpty()
|
|
|
|
|
|
|
|
p = subprocess.Popen(["setsid", "--ctty", "sleep", "10000"],
|
2019-09-07 15:46:22 +03:00
|
|
|
stdin=slave,
|
|
|
|
stdout=slave,
|
|
|
|
stderr=slave,
|
|
|
|
close_fds=True)
|
2015-12-25 17:49:37 +03:00
|
|
|
st = os.stat("/proc/self/fd/%d" % slave)
|
|
|
|
ttyid = "tty[%x:%x]" % (st.st_rdev, st.st_dev)
|
|
|
|
os.close(slave)
|
|
|
|
time.sleep(1)
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
ret = subprocess.Popen([
|
|
|
|
"../../../criu/criu", "dump", "-t",
|
|
|
|
str(p.pid), "-v4", "--external", ttyid
|
|
|
|
]).wait()
|
2015-12-25 17:49:37 +03:00
|
|
|
if ret:
|
2019-09-07 15:46:22 +03:00
|
|
|
sys.exit(ret)
|
2015-12-25 17:49:37 +03:00
|
|
|
p.wait()
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
new_master, slave = pty.openpty() # get another pty pair
|
2015-12-25 17:49:37 +03:00
|
|
|
os.close(master)
|
|
|
|
|
|
|
|
ttyid = "fd[%d]:tty[%x:%x]" % (slave, st.st_rdev, st.st_dev)
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
ret = subprocess.Popen([
|
|
|
|
"../../../criu/criu", "restore", "-v4", "--inherit-fd", ttyid,
|
|
|
|
"--restore-sibling", "--restore-detach"
|
|
|
|
]).wait()
|
2015-12-25 17:49:37 +03:00
|
|
|
if ret:
|
2019-09-07 15:46:22 +03:00
|
|
|
sys.exit(ret)
|
2015-12-25 17:49:37 +03:00
|
|
|
os.close(slave)
|
2019-09-07 15:46:22 +03:00
|
|
|
os.waitpid(-1, os.WNOHANG) # is the process alive
|
2015-12-25 17:49:37 +03:00
|
|
|
|
|
|
|
os.close(new_master)
|
|
|
|
_, status = os.wait()
|
2016-02-13 21:06:00 +03:00
|
|
|
if not os.WIFSIGNALED(status) or os.WTERMSIG(status) != signal.SIGHUP:
|
2019-09-07 15:46:22 +03:00
|
|
|
print(status)
|
|
|
|
sys.exit(1)
|
2015-12-25 17:49:37 +03:00
|
|
|
|
2018-09-23 15:31:52 +01:00
|
|
|
print("PASS")
|