diff options
Diffstat (limited to 'portato/__init__.py')
-rw-r--r-- | portato/__init__.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/portato/__init__.py b/portato/__init__.py index 653329c..7363429 100644 --- a/portato/__init__.py +++ b/portato/__init__.py @@ -18,7 +18,7 @@ import subprocess, threading import atexit from optparse import OptionParser, SUPPRESS_HELP -from . import log +from .log import start as logstart from .constants import LOCALE_DIR, APP, VERSION from .su import detect_su_command from .helper import debug, info, error @@ -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, @@ -54,6 +54,11 @@ def get_parser (use_ = False): return parser +def _sub_start (): + # set gettext stuff + locale.setlocale(locale.LC_ALL, '') + gettext.install(APP, LOCALE_DIR, unicode = True) + def start(): # set gettext stuff @@ -61,7 +66,7 @@ def start(): gettext.install(APP, LOCALE_DIR, unicode = True) # start logging - log.start(file=False) + logstart(file=False) # run parser (options, args) = get_parser().parse_args() @@ -70,15 +75,12 @@ def start(): atexit.register(get_listener().close) if options.nofork or os.getuid() == 0: # start GUI - log.start(file = True) # start logging to file + logstart(file = True) # start logging to file 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() @@ -87,14 +89,12 @@ def start(): else: # start us again in root modus and launch listener - import shm_wrapper as shm + from . import 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, create = True, exclusive = True) # 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() @@ -106,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) @@ -124,3 +124,9 @@ def start(): if lt.isAlive(): debug("Listener is still running. Close it.") get_listener().close() + lt.join() + + try: + mq.remove() + except ipc.MessageQueueRemovedError: + debug("MessageQueue already removed. Ignore.") |