summaryrefslogtreecommitdiffstats
path: root/socket_notify.py
diff options
context:
space:
mode:
Diffstat (limited to 'socket_notify.py')
-rw-r--r--socket_notify.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/socket_notify.py b/socket_notify.py
index 0ab5dd6..df6d815 100644
--- a/socket_notify.py
+++ b/socket_notify.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
socket_notify.py - Phenny Socket Notification
-Copyright 2013, Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
+Copyright 2013-2016, Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
@@ -9,13 +9,23 @@ http://inamidst.com/phenny/
import asyncore, socket, stat, os
-SOCKET_PATH = '/var/run/phenny/socket'
+
+DEFAULT_CONFIG = {
+ 'path': '/var/run/phenny/socket',
+ 'umask': 0o000,
+}
+
def setup(phenny):
- dir = os.path.dirname(SOCKET_PATH)
+ config = dict()
+ config.update(DEFAULT_CONFIG)
+ config.update(getattr(phenny.config, 'socket_notify', dict()))
+
+ dir = os.path.dirname(config['path'])
if not os.path.exists(dir):
os.makedirs(dir)
- Monitor(SOCKET_PATH, phenny)
+ Monitor(config, phenny)
+
class Sender(asyncore.dispatcher):
def __init__(self, sock, phenny):
@@ -31,8 +41,9 @@ class Sender(asyncore.dispatcher):
else:
self.close()
+
class Monitor(asyncore.dispatcher):
- def __init__(self, path, phenny):
+ def __init__(self, config, phenny):
asyncore.dispatcher.__init__(self)
self.phenny = phenny
self.phenny._orig_close = self.phenny.close
@@ -40,17 +51,17 @@ class Monitor(asyncore.dispatcher):
self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
- mode = os.stat(path).st_mode
+ mode = os.stat(config['path']).st_mode
if stat.S_ISSOCK(mode):
- os.unlink(path)
+ os.unlink(config['path'])
else:
- print("Path '%s' exists and is not a socket!" % path)
+ print("Path '%s' exists and is not a socket!" % config['path'])
sys.exit(1)
except OSError:
pass
- old_mask = os.umask(0o000)
- self.bind(path)
+ old_mask = os.umask(config['umask'])
+ self.bind(config['path'])
os.umask(old_mask)
self.listen(5)