Eliminate the lock.

This commit is contained in:
Manuel Amador (Rudd-O) 2023-02-21 22:27:10 +00:00
parent 3a60f0ee4b
commit 8675eaa547

View File

@ -2,7 +2,6 @@
import base64 import base64
import pickle import pickle
import contextlib
import errno import errno
import fcntl import fcntl
import os import os
@ -43,18 +42,6 @@ def set_proc_name(newname):
libc.prctl(15, byref(buff), 0, 0, 0) libc.prctl(15, byref(buff), 0, 0, 0)
@contextlib.contextmanager
def mutexfile(filepath):
oldumask = os.umask(0o077)
try:
f = open(filepath, "a")
finally:
os.umask(oldumask)
fcntl.lockf(f.fileno(), fcntl.LOCK_EX)
yield
f.close()
def unset_cloexec(fd): def unset_cloexec(fd):
old = fcntl.fcntl(fd, fcntl.F_GETFD) old = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, old & ~fcntl.FD_CLOEXEC) fcntl.fcntl(fd, fcntl.F_SETFD, old & ~fcntl.FD_CLOEXEC)
@ -370,28 +357,27 @@ def main_master():
saved_stderr = openfdforappend(os.dup(sys.stderr.fileno())) saved_stderr = openfdforappend(os.dup(sys.stderr.fileno()))
with mutexfile(os.path.expanduser("~/.bombshell-lock")): try:
try: p = subprocess.Popen(
p = subprocess.Popen( ["qrexec-client-vm", remote_vm, "qubes.VMShell"],
["qrexec-client-vm", remote_vm, "qubes.VMShell"], stdin=subprocess.PIPE,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stdout=subprocess.PIPE, close_fds=True,
close_fds=True, preexec_fn=os.setpgrp,
preexec_fn=os.setpgrp, bufsize=0,
bufsize=0, )
) except OSError as e:
except OSError as e: logging.error("cannot launch qrexec-client-vm: %s", e)
logging.error("cannot launch qrexec-client-vm: %s", e) return 127
return 127
logging.debug("Writing the helper text into the other side") logging.debug("Writing the helper text into the other side")
p.stdin.write(remote_helper_text) p.stdin.write(remote_helper_text)
p.stdin.flush() p.stdin.flush()
confirmation, errmsg = recv_confirmation(p.stdout) confirmation, errmsg = recv_confirmation(p.stdout)
if confirmation != 0: if confirmation != 0:
logging.error("remote: %s", errmsg) logging.error("remote: %s", errmsg)
return confirmation return confirmation
handled_signals = ( handled_signals = (
signal.SIGINT, signal.SIGINT,