X-Git-Url: https://git.phdru.name/?p=m_librarian.git;a=blobdiff_plain;f=m_librarian%2Fweb%2Futils.py;h=8804f3b327df81831fbd707af57def93e965a8e9;hp=12be81f47dc572482043dc922c42fea9db637495;hb=ced17ee7dd16622f1e5cf55f838301993f7ac3f7;hpb=ddeb31dfe19724f8899cc1d89cc22885c9f819c3 diff --git a/m_librarian/web/utils.py b/m_librarian/web/utils.py index 12be81f..8804f3b 100644 --- a/m_librarian/web/utils.py +++ b/m_librarian/web/utils.py @@ -1,11 +1,20 @@ from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB -from os import path, remove +from tempfile import gettempdir +import os import socket -lock_fname = path.join( - path.dirname(path.dirname(path.dirname(__file__))), - 'tmp', 'm_librarian.lock') +if os.access('/var/run/lock', os.W_OK): + lock_dir = '/var/run/lock' +else: + lock_dir = gettempdir() + +if hasattr(os, 'getuid'): + suffix = '-%d' % os.getuid() +else: + suffix = '' + +lock_fname = os.path.join(lock_dir, 'm_librarian%s.lock' % suffix) def get_lock(port): @@ -38,7 +47,7 @@ def close_lock(lock_file): lock_file = open(lock_fname, 'w') lock_file.write('') lock_file.close() - remove(lock_fname) + os.remove(lock_fname) def get_open_port():