diff --git a/flatpak/workaround/com.github.stsdc.monitor-workaround.py b/flatpak/workaround/com.github.stsdc.monitor-workaround.py index fd1b6adf..73ef24a8 100755 --- a/flatpak/workaround/com.github.stsdc.monitor-workaround.py +++ b/flatpak/workaround/com.github.stsdc.monitor-workaround.py @@ -3,7 +3,7 @@ """The workaround script should run only in Flatpak environment.""" import os - +import subprocess import dbus import dbus.service import dbus.mainloop.glib @@ -36,7 +36,7 @@ def __init__(self, conn=None, object_path=None, bus_name=None): @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="s", out_signature="aa{ss}", sender_keyword="sender", connection_keyword="conn") def GetProcesses(self, name, sender=None, conn=None): - print("GetProcesses") + print("WorkaroundServer: GetProcesses") processes = [] for pid in get_pids(): process = { @@ -77,6 +77,22 @@ def GetProcesses(self, name, sender=None, conn=None): processes.append(process) return processes + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="i", sender_keyword="sender", connection_keyword="conn") + def EndProcess(self, pid, sender=None, conn=None): + print(f"WorkaroundServer: EndProcess: kill -15 {pid}") + try: + (subprocess.check_output(["kill", "-15", str(pid)], stderr=subprocess.STDOUT, shell=False)).decode() + except subprocess.CalledProcessError as err: + print(err) + + @dbus.service.method(dbus_interface="com.github.stsdc.monitor.workaround.GetProcesses", in_signature="i", sender_keyword="sender", connection_keyword="conn") + def KillProcess(self, pid, sender=None, conn=None): + print(f"WorkaroundServer: KillProcess: kill -9 {pid}") + try: + (subprocess.check_output(["kill", "-9", str(pid)], stderr=subprocess.STDOUT, shell=False)).decode() + except subprocess.CalledProcessError as err: + print(err) + if __name__ == "__main__": dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index bafbb189..200ca009 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -132,6 +132,14 @@ public class Monitor.Process : GLib.Object { // Ends the process public bool end () { + if (ProcessUtils.is_flatpak_env ()) { + try { + DBusWorkaroundClient.get_default ().interface.end_process (this.stat.pid); + } catch (Error e) { + warning (e.message); + } + } + // Sends a terminate signal if (Posix.kill (stat.pid, Posix.Signal.TERM) == 0) { return true; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index b714659a..5fc5a737 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -19,7 +19,7 @@ namespace Monitor { construct { this.is_flatpak = ProcessUtils.is_flatpak_env (); if (this.is_flatpak) { - this.spawn_workaround (); + // this.spawn_workaround (); dbus_workaround_client = DBusWorkaroundClient.get_default (); } } @@ -47,7 +47,7 @@ namespace Monitor { try { HashTable[] procs = dbus_workaround_client.interface.get_processes (""); pids = new int[procs.length]; - debug ("Workaround: retrieved pids: %d", procs.length); + debug ("Workaround client: retrieved pids: %d", procs.length); for (int i = 0; i < procs.length; i++) { // debug (procs[i]["pid"]); pids[i] = int.parse (procs[i]["pid"]); @@ -70,5 +70,9 @@ namespace Monitor { return pids; } + + public void end_process (int pid) { + DBusWorkaroundClient.get_default (); + } } } diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala index dc425bfd..e2e6e276 100644 --- a/src/Services/DBusWorkaroundClient.vala +++ b/src/Services/DBusWorkaroundClient.vala @@ -1,6 +1,7 @@ [DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")] public interface Monitor.DBusWorkaroundClientInterface : Object { public abstract HashTable[] get_processes (string empty) throws Error; + public abstract void end_process (int pid) throws Error; }