xpra icon
Bug tracker and wiki

Ticket #1105: run-cleanups-priority.patch

File run-cleanups-priority.patch, 3.1 KB (added by Antoine Martin, 17 months ago)

run cleanups with a priority value so we could run pam.close last, but this cannot be used because we are no longer root and dbus sends the uid..

  • xpra/scripts/server.py

     
    2626_cleanups = []
    2727def run_cleanups():
    2828    global _cleanups
    29     cleanups = _cleanups
     29    from operator import itemgetter
     30    items = sorted(_cleanups, key=itemgetter(1))
    3031    _cleanups = []
    31     for c in cleanups:
     32    for c, prio in items:
    3233        try:
    3334            c()
    3435        except:
    35             print("error running cleanup %s" % c)
     36            print("error running cleanup: %s, %s" % (c, prio))
    3637            traceback.print_exception(*sys.exc_info())
    3738
    3839_when_ready = []
    3940
    40 def add_when_ready(f):
    41     _when_ready.append(f)
     41def add_when_ready(f, prio=0):
     42    _when_ready.append((f, prio))
    4243
    43 def add_cleanup(f):
    44     _cleanups.append(f)
     44def add_cleanup(f, prio=0):
     45    _cleanups.append((f, prio))
    4546
     47def remove_cleanup(f):
     48    _cleanups = [(c,prio) for c,prio in _cleanups if c!=f]
     49   
    4650
    4751def deadly_signal(signum, frame):
    4852    info("got deadly signal %s, exiting\n" % SIGNAMES.get(signum, signum))
     
    471475                items["XAUTHDATA"] = xauth_data
    472476            pam.set_items(items)
    473477            if pam.open():
    474                 #we can't close it, because we're not going to be root any more,
    475                 #but since we're the process leader for the session,
    476                 #terminating will also close the session
    477                 #add_cleanup(pam.close)
     478                #run this last, as this will kill all processes left in this cgroup:
     479                add_cleanup(pam.close, 1000)
    478480                protected_env = pam.get_envlist()
    479481                os.environ.update(protected_env)
    480482        #closing the pam fd causes the session to be closed,
     
    861863    if e>0:
    862864        # Upgrading/exiting, so leave X and dbus servers running
    863865        if close_display:
    864             _cleanups.remove(close_display)
     866            remove_cleanup(close_display)
    865867        if kill_dbus:
    866             _cleanups.remove(kill_dbus)
     868            remove_cleanup(kill_dbus)
    867869        from xpra.server.server_core import ServerCore
    868870        if e==ServerCore.EXITING_CODE:
    869871            log.info("exiting: not cleaning up Xvfb")
  • xpra/server/server_core.py

     
    457457        signal.signal(signal.SIGINT, self.signal_quit)
    458458        signal.signal(signal.SIGTERM, self.signal_quit)
    459459        def start_ready_callbacks():
    460             for x in self._when_ready:
     460            from operator import itemgetter
     461            items = sorted(self._when_ready, key=itemgetter(1))
     462            for x, prio in items:
    461463                try:
    462464                    x()
    463465                except Exception as e:
    464                     log("start_ready_callbacks()", exc_info=True)
     466                    log("start_ready_callbacks() %s", (x, prio), exc_info=True)
    465467                    log.error("Error on server start ready callback '%s':", x)
    466468                    log.error(" %s", e)
    467469        self.idle_add(start_ready_callbacks)