bombshell-client gains a lock that prevents it from hanging if two parallel requests happen too fast

This commit is contained in:
Manuel Amador (Rudd-O) 2015-12-15 00:06:56 +00:00
parent 8e38ed73bb
commit eebd457b03

View File

@ -1,6 +1,7 @@
#!/usr/bin/python -u
import cPickle
import contextlib
import fcntl
import os
import pipes
@ -13,6 +14,18 @@ import sys
import threading
@contextlib.contextmanager
def mutexfile(filepath):
oldumask = os.umask(0077)
try:
f = file(filepath, "a")
finally:
os.umask(oldumask)
fcntl.lockf(f.fileno(), fcntl.LOCK_EX)
yield
f.close()
debug_lock = threading.Lock()
debug_enabled = False
class LoggingEmu():
@ -250,26 +263,27 @@ def main_master():
saved_stderr = os.fdopen(os.dup(sys.stderr.fileno()), "a")
try:
p = subprocess.Popen(
["qrexec-client-vm", remote_vm, "qubes.VMShell"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True,
preexec_fn=os.setpgrp,
)
except OSError, e:
logging.error("cannot launch qrexec-client-vm: %s", e)
return 127
with mutexfile(os.path.expanduser("~/.bombshell-lock")):
try:
p = subprocess.Popen(
["qrexec-client-vm", remote_vm, "qubes.VMShell"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True,
preexec_fn=os.setpgrp,
)
except OSError, e:
logging.error("cannot launch qrexec-client-vm: %s", e)
return 127
p.stdin.write(remote_helper_text)
p.stdin.flush()
p.stdin.write(remote_helper_text)
p.stdin.flush()
send_command(p.stdin, remote_command)
confirmation, errmsg = recv_confirmation(p.stdout)
if confirmation != 0:
logging.error("remote: %s", errmsg)
return confirmation
send_command(p.stdin, remote_command)
confirmation, errmsg = recv_confirmation(p.stdout)
if confirmation != 0:
logging.error("remote: %s", errmsg)
return confirmation
handled_signals = (
signal.SIGINT,