diff options
Diffstat (limited to 'portato.py')
-rwxr-xr-x | portato.py | 35 |
1 files changed, 32 insertions, 3 deletions
@@ -12,9 +12,11 @@ # # Written by René 'Necoro' Neumann <necoro@necoro.net> -from portato.constants import VERSION, FRONTENDS, STD_FRONTEND, XSD_LOCATION, LOCALE_DIR, APP +from portato import listener +from portato.constants import VERSION, FRONTENDS, STD_FRONTEND, XSD_LOCATION, LOCALE_DIR, APP, SU_COMMAND from optparse import OptionParser -import sys, os +from subprocess import call +import sys, os, socket import gettext, locale def get_frontend_list (): @@ -46,6 +48,9 @@ def main (): parser.add_option("-x", "--validate", action = "store", dest = "validate", metavar="PLUGIN", help = _("validates the given plugin xml instead of launching Portato")) + parser.add_option("-L", "--no-listener", action = "store_true", dest = "nolistener", default = False, + help = _("do not start listener")) + # run parser (options, args) = parser.parse_args() @@ -83,8 +88,32 @@ def main (): else: print _("Validation succeeded.") return - else: + elif options.nolistener: + try: + # move this process into a new process group + # this is to be able to kill emerge et al w/o killing ourselves :) + os.setsid() + except OSError: + pass + listener.set_send() run() + else: # start listener and start us again in root modus + if os.fork() == 0: + listener.set_recv() + else: + additional = [] + if options.check: + additional.append("-c") + if options.frontend: + additional.extend(["-f", options.frontend]) + + try: + if os.getuid() == 0: + call([SU_COMMAND, "%s --no-listener %s" % (sys.argv[0], " ".join(additional))], env = os.environ) + else: + call([sys.argv[0], "--no-listener"]+additional, env = os.environ) + except KeyboardInterrupt: + pass if __name__ == "__main__": main() |