From ae2596ab55a05763d4bdc25c871bc6eec8833733 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 10 May 2016 04:21:02 +0200 Subject: Add config options for socket path and umask 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. --- debian/changelog | 6 ++++++ debian/copyright | 4 ++-- socket_notify.py | 31 +++++++++++++++++++++---------- 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 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 + Copyright (C) 2014-2016 Alexander Sulfrian 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 +Copyright 2013-2016, Alexander Sulfrian 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) -- cgit v1.2.3-1-g7c22