Skip to content

Commit

Permalink
Make the combo lock differentiate between users
Browse files Browse the repository at this point in the history
On the Mark-1 the locking would fail since the first time the lock is
accessed the process is run under root (script checking the enclosure
version). This caused the locking to fail since the normal mycroft
processes got an access error (lock-file owned by root)

This change creates lock-files with a user extension and thus working
around this issue. This leaves a possibility for collisions when
multiple users are running a mycroft process but this VERY rare.
  • Loading branch information
forslund committed Oct 1, 2018
1 parent 2efe3eb commit 5a6f32e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mycroft/util/combo_lock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from threading import Lock
from fasteners.process_lock import InterProcessLock
from getpass import getuser


class ComboLock():
""" A combined process and thread lock. """
""" A combined process and thread lock.
Arguments:
path (str): path to the lockfile for the lock
"""
def __init__(self, path):
self.plock = InterProcessLock(path)
# Append the current username to the path to get separate lock files
# for separate users
self.plock = InterProcessLock('{}.{}'.format(path, getuser()))
self.tlock = Lock()

def acquire(self, blocking=True):
Expand Down

0 comments on commit 5a6f32e

Please sign in to comment.