diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-23 13:52:37 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-24 15:37:02 +0200 |
commit | 10e98e827e71c7a415e46b633381d56dbb1cc97c (patch) | |
tree | 7be8aebb3bf777be35e4a7a402840327852a97bb /service.py | |
parent | 81e570931adc37054460e3f05d0325888050e386 (diff) | |
download | RWA.Support.SessionService-10e98e827e71c7a415e46b633381d56dbb1cc97c.tar.gz RWA.Support.SessionService-10e98e827e71c7a415e46b633381d56dbb1cc97c.tar.bz2 RWA.Support.SessionService-10e98e827e71c7a415e46b633381d56dbb1cc97c.zip |
Prevent crashing when asking for status with invalid pid & mockup-mode: make sessionid's positive
Diffstat (limited to 'service.py')
-rwxr-xr-x | service.py | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -47,14 +47,21 @@ class RWAService(dbus.service.Object): self._update_session(pid) return self._get_status(pid) - @dbus.service.method("org.ArcticaProject.RWA", in_signature="i") + @dbus.service.method("org.ArcticaProject.RWA", in_signature="i", out_signature="s") def stop(self, pid: int): """Stop a remote session.""" - session = self.sessions[pid] + try: + session = self.sessions[pid] + except KeyError: + return json.dumps({"pid": pid, "status": "stopped"}, sort_keys=True) session.stop() + return json.dumps({"id": pid, "status": "stopped"}, sort_keys=True) def _get_status(self, pid: int) -> str: - session = self.sessions[pid] + try: + session = self.sessions[pid] + except KeyError: + return json.dumps({"id": pid, "status": "dead"}, sort_keys=True) return json.dumps(session.status) def _ensure_update_service(self): @@ -65,7 +72,13 @@ class RWAService(dbus.service.Object): def _update_session(self, pid: int): """Update the status of a session.""" - session = self.sessions[pid] + try: + session = self.sessions[pid] + except KeyError: + print(f"Session #{pid}") + print("Session is dead.") + return + print(f"Session #{session.pid}") # Check if VNC process is still running |