From 04a528370f6e237c08e26de5272e3ac418bb8057 Mon Sep 17 00:00:00 2001 From: Faiyaz Ahmed Date: Wed, 17 Oct 2007 17:30:39 +0000 Subject: [PATCH] Patched with nm-disk-lock.patch provided by dhozac. Closes (or attempts to) [ticket:7 chcontext bug]. Uses file based locks in place of thread mutexes. --- sliver_vs.py | 3 +-- tools.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sliver_vs.py b/sliver_vs.py index ca538c0..270f112 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -18,7 +18,6 @@ don't have to guess if there is a running process or not. import errno import os -import threading import time import vserver @@ -43,7 +42,7 @@ class Sliver_VS(accounts.Account, vserver.VServer): SHELL = '/bin/vsh' TYPE = 'sliver.VServer' - _init_disk_info_sem = threading.Semaphore(1) + _init_disk_info_sem = tools.NMLock("/var/run/nm-disk-info.lock") def __init__(self, rec): try: diff --git a/tools.py b/tools.py index f41f981..f4496e1 100644 --- a/tools.py +++ b/tools.py @@ -6,6 +6,7 @@ import os import pwd import tempfile import threading +import fcntl import logger @@ -88,3 +89,17 @@ def write_temp_file(do_write, mode=None, uidgid=None): try: do_write(f) finally: f.close() return temporary_filename + + +class NMLock: + def __init__(self, file): + self.fd = os.open(file, os.O_RDWR|os.O_CREAT, 0600) + flags = fcntl.fcntl(self.fd, fcntl.F_GETFD) + flags |= fcntl.FD_CLOEXEC + fcntl.fcntl(self.fd, fcntl.F_SETFD, flags) + def __del__(self): + os.close(self.fd) + def acquire(self): + fcntl.lockf(self.fd, fcntl.LOCK_EX) + def release(self): + fcntl.lockf(self.fd, fcntl.LOCK_UN) -- 2.43.0