Skip to content

Commit 3425c07

Browse files
committed
Dealing with permission issues
1 parent cefee27 commit 3425c07

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

I2C_mutex.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ class Mutex(object):
88

99
def __init__(self, debug = False):
1010
self.mutex_debug = debug
11+
self.DexterLockI2C_handle_filename = '/run/lock/DexterLockI2C'
12+
13+
# putting the following file in /run/lock so any user can have access
14+
# putting it directly in /run requires sudo priviledges
15+
self.DexterOverallMutex_filename = '/run/lock/DexterOS_overall_mutex'
16+
17+
try:
18+
open(self.DexterLockI2C_handle_filename, 'w')
19+
if os.path.isfile(self.DexterLockI2C_handle_filename):
20+
os.chmod(self.DexterLockI2C_handle_filename, 0o777)
21+
except Exception as e:
22+
pass
1123

1224
def acquire(self):
1325
if self.mutex_debug:
@@ -16,7 +28,8 @@ def acquire(self):
1628
acquired = False
1729
while not acquired:
1830
try:
19-
self.DexterLockI2C_handle = open('/run/lock/DexterLockI2C', 'w')
31+
self.DexterLockI2C_handle = open(self.DexterLockI2C_handle_filename, 'w')
32+
os.chmod(self.DexterLockI2C_handle_filename, 0o777)
2033
# lock
2134
fcntl.lockf(self.DexterLockI2C_handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
2235
acquired = True
@@ -44,19 +57,24 @@ def disableDebug(self):
4457

4558
def set_overall_mutex(self):
4659
try:
47-
self.overall_mutex_handle = open('/run/DexterOS_overall_mutex', 'w')
48-
except:
49-
print("Must run with sudo")
60+
self.overall_mutex_handle = open(self.DexterOverallMutex_filename, 'w')
61+
# debating whether we want to open up control of this file to any other process,
62+
# or if control should be limited to the process that started it.
63+
# For now, open it up and let's see.
64+
os.chmod(self.DexterOverallMutex_filename, 0o777)
65+
except Exception as e:
66+
print(e)
67+
pass
5068

5169
def release_overall_mutex(self):
5270
try:
5371
self.overall_mutex_handle.close()
54-
os.remove('/run/DexterOS_overall_mutex')
72+
os.remove(self.DexterOverallMutex_filename)
5573
except:
5674
pass
5775

5876
def overall_mutex(self):
59-
if os.path.isfile("/run/DexterOS_overall_mutex"):
77+
if os.path.isfile(self.DexterOverallMutex_filename):
6078
return True
6179
else:
6280
return False

0 commit comments

Comments
 (0)