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")
ed2imap-go.git/commit/pkg/rfc822/writer_test.go?h=v1.4.0&id=3a854c3bc47e75491b836c7fc12b617da5d68288&follow=1'>Issue #46: Fix semantics of `n` resultRené 'Necoro' Neumann2-9/+15 2021-02-16Issue #46: Move and rename writer; add commentsRené 'Necoro' Neumann3-12/+21 2021-02-15Issue #46: Improvements; add testsRené 'Necoro' Neumann2-1/+48 2021-02-15Bump github.com/google/uuid from 1.1.4 to 1.2.0dependabot[bot]2-3/+3 2021-02-15Issue #46: Make the resulting email body not to include single \r or \n. This...René 'Necoro' Neumann2-2/+66 2021-01-20Bump github.com/PuerkitoBio/goquery from 1.6.0 to 1.6.1dependabot[bot]2-3/+3 2021-01-09Bump github.com/google/uuid from 1.1.2 to 1.1.4dependabot[bot]2-3/+3 2021-01-09Bump github.com/emersion/go-message from 0.14.0 to 0.14.1 (#42)dependabot[bot]2-3/+3 2020-11-28Bump github.com/emersion/go-message from 0.13.0 to 0.14.0 (#38)dependabot[bot]2-3/+9 2020-11-28Bump github.com/google/go-cmp from 0.5.2 to 0.5.4 (#37)dependabot[bot]2-3/+3 2020-11-23Fix release.ymlv0.5.2René 'Necoro' Neumann1-3/+10 2020-11-23Prepare v0.5.2René 'Necoro' Neumann3-3/+8 2020-11-20Bump github.com/gabriel-vasile/mimetype from 1.1.1 to 1.1.2dependabot[bot]2-3/+3 2020-11-04Clean dependabot.ymlRené 'Necoro' Neumann1-4/+0