summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--portato/__init__.py20
-rw-r--r--portato/listener.py57
2 files changed, 26 insertions, 51 deletions
diff --git a/portato/__init__.py b/portato/__init__.py
index 60aeec4..ae50929 100644
--- a/portato/__init__.py
+++ b/portato/__init__.py
@@ -46,7 +46,7 @@ def get_parser (use_ = False):
parser = OptionParser(version = vers, prog = "portato", description = desc, usage = usage)
- parser.add_option("--shm", action = "store", nargs = 3, type="long", dest = "shm",
+ parser.add_option("--mq", action = "store", nargs = 1, type="long", dest = "mq", default = None,
help = SUPPRESS_HELP)
parser.add_option("-F", "--no-fork", action = "store_true", dest = "nofork", default = False,
@@ -80,10 +80,7 @@ def start():
from .gui import run
info("%s v. %s", _("Starting Portato"), VERSION)
- if options.shm:
- get_listener().set_send(*options.shm)
- else:
- get_listener().set_send()
+ get_listener().set_send(options.mq)
try:
run()
@@ -92,14 +89,12 @@ def start():
else: # start us again in root modus and launch listener
- import shm_wrapper as shm
+ from . import sysv_ipc as ipc
- mem = shm.create_memory(1024, permissions=0600)
- sig = shm.create_semaphore(InitialValue = 0, permissions = 0600)
- rw = shm.create_semaphore(InitialValue = 1, permissions = 0600)
+ mq = ipc.MessageQueue(None, ipc.IPC_CREX)
# start listener
- lt = threading.Thread(target=get_listener().set_recv, args = (mem, sig, rw))
+ lt = threading.Thread(target=get_listener().set_recv, args = (mq,))
lt.setDaemon(False)
lt.start()
@@ -111,7 +106,7 @@ def start():
su = detect_su_command()
if su:
debug("Using '%s' as su command.", su.bin)
- cmd = su.cmd("%s --no-fork --shm %ld %ld %ld" % (sys.argv[0], mem.key, sig.key, rw.key))
+ cmd = su.cmd("%s --no-fork --mq %ld" % (sys.argv[0], mq.key))
sp = subprocess.Popen(cmd, env = env)
@@ -129,3 +124,6 @@ def start():
if lt.isAlive():
debug("Listener is still running. Close it.")
get_listener().close()
+ lt.join()
+
+ mq.remove()
diff --git a/portato/listener.py b/portato/listener.py
index 3d2dd53..1c12b00 100644
--- a/portato/listener.py
+++ b/portato/listener.py
@@ -32,22 +32,15 @@ class Listener (object):
@ivar _send: sender socket
@type _send: int"""
- def set_recv (self, mem, sig, rw):
- self._mem = mem
- self._sig = sig
- self._rw = rw
+ def set_recv (self, mq):
+
+ self._mq = mq
while True:
try:
- try:
- self._sig.P()
- self._rw.P()
- len = self._mem.read(NumberOfBytes = 4)
- string = self._mem.read(NumberOfBytes = int(len), offset = 4)
- finally:
- self._rw.V()
-
- data = string.split("\0")
+ msg, type = self._mq.receive(block = True)
+
+ data = msg.split("\0")
debug("Listener received: %s", data)
if data[0] == "notify":
@@ -60,14 +53,8 @@ class Listener (object):
debug("Got KeyboardInterrupt. Aborting.")
break
- self._mem.remove()
- self._sig.remove()
- self._rw.remove()
-
- self._mem = None
- self._sig = None
- self._rw = None
-
+ self._mq = None
+
def do_cmd (self, cmdlist):
"""Starts a command as the user.
@@ -89,30 +76,20 @@ class Listener (object):
n.set_urgency(int(urgency))
n.show()
- def set_send (self, mem = None, sig = None, rw = None):
- if mem is None or sig is None or rw is None:
+ def set_send (self, mq = None):
+ if mq is None:
warning(_("Listener has not been started."))
- self._mem = None
- self._sig = None
- self._rw = None
+ self._mq = None
else:
- import shm_wrapper as shm
+ from . import sysv_ipc as ipc
- self._mem = shm.SharedMemoryHandle(mem)
- self._sig = shm.SemaphoreHandle(sig)
- self._rw = shm.SemaphoreHandle(rw)
+ self._mq = ipc.MessageQueue(mq)
def __send (self, string):
- self._rw.P()
- self._sig.Z()
- try:
- self._mem.write("%4d%s" % (len(string), string))
- self._sig.V()
- finally:
- self._rw.V()
+ self._mq.send(string, block = True)
def send_notify (self, base = "", descr = "", icon = "", urgency = None):
- if self._sig is None:
+ if self._mq is None:
self.do_notify(base, descr, icon, urgency)
else:
string = "\0".join(["notify", base, descr, icon])
@@ -125,11 +102,11 @@ class Listener (object):
self.__send(string)
def send_cmd (self, cmdlist):
- if self._sig is None:
+ if self._mq is None:
self.do_cmd(cmdlist)
else:
self.__send("\0".join(["cmd"] +cmdlist))
def close (self):
- if self._sig is not None:
+ if self._mq is not None:
self.__send("close")