summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-05-10 04:21:02 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2016-05-10 04:23:40 +0200
commitae2596ab55a05763d4bdc25c871bc6eec8833733 (patch)
treeca1e4e21e3150b652ec2e2ad13d5368a26433c8a
parentd1248b4ed3cdb24244ecd64a6756a180384c6c28 (diff)
downloadsocket-notify-master.tar.gz
socket-notify-master.tar.bz2
socket-notify-master.zip
Add config options for socket path and umaskHEADmaster
You can now set something like: socket_notify = { 'path': '/tmp/phenny.sock', 'umask': 0o077, } in your phenny config and specify the path and umask for the socket.
-rw-r--r--debian/changelog6
-rw-r--r--debian/copyright4
-rw-r--r--socket_notify.py31
3 files changed, 29 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index 6f85ca0..61a3e3f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+phenny-module-socket-notify (0.2) UNRELEASED; urgency=low
+
+ * Add config options for socket path and umask
+
+ -- Alexander Sulfrian <alex@spline.inf.fu-berlin.de> Tue, 10 May 2016 04:22:54 +0200
+
phenny-module-socket-notify (0.1) UNRELEASED; urgency=low
* Initial release.
diff --git a/debian/copyright b/debian/copyright
index 24f1c7a..81aaa00 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -12,7 +12,7 @@ Upstream Author(s):
Copyright:
- Copyright (C) 2014 Alexander Sulfrian
+ Copyright (C) 2014-2016 Alexander Sulfrian
License:
@@ -20,7 +20,7 @@ License:
The Debian packaging is:
- Copyright (C) 2014 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
+ Copyright (C) 2014-2016 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
and is licensed under the GPL version 3,
see "/usr/share/common-licenses/GPL-3".
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)