Skip to content

Commit

Permalink
add kill signal; show root user if uid 0
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Jan 6, 2024
1 parent 2c87b9a commit 9d28856
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/Managers/Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ public class Monitor.Process : GLib.Object {
var process_provider = ProcessProvider.get_default ();
string ? status = process_provider.pids_status.get (this.stat.pid);
var status_line = status.split ("\n");
return int.parse (status_line[8].split ("\t")[1]);

int uid = int.parse (status_line[8].split ("\t")[1]);

// @TODO parse users file instead
if (uid == 0) username = "root";
return uid;

}
GTop.ProcUid proc_uid;
Expand All @@ -123,6 +128,15 @@ public class Monitor.Process : GLib.Object {

// Kills the process
public bool kill () {
if (ProcessUtils.is_flatpak_env ()) {
try {
DBusWorkaroundClient.get_default ().interface.kill_process (this.stat.pid);
return true;
} catch (Error e) {
warning (e.message);
}
}

// Sends a kill signal that cannot be ignored
if (Posix.kill (stat.pid, Posix.Signal.KILL) == 0) {
return true;
Expand All @@ -135,6 +149,7 @@ public class Monitor.Process : GLib.Object {
if (ProcessUtils.is_flatpak_env ()) {
try {
DBusWorkaroundClient.get_default ().interface.end_process (this.stat.pid);
return true;
} catch (Error e) {
warning (e.message);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Services/DBusWorkaroundClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
public interface Monitor.DBusWorkaroundClientInterface : Object {
public abstract HashTable<string, string>[] get_processes (string empty) throws Error;
public abstract void end_process (int pid) throws Error;
public abstract void kill_process (int pid) throws Error;

}

Expand All @@ -13,9 +14,6 @@ public class Monitor.DBusWorkaroundClient : Object {
return instance.once (() => { return new DBusWorkaroundClient (); });
}

public signal void monitor_vanished ();
public signal void monitor_appeared ();

construct {
try {
interface = Bus.get_proxy_sync (
Expand All @@ -27,9 +25,7 @@ public class Monitor.DBusWorkaroundClient : Object {
Bus.watch_name (
BusType.SESSION,
"com.github.stsdc.monitor.workaround",
BusNameWatcherFlags.NONE,
() => monitor_appeared (),
() => monitor_vanished ()
BusNameWatcherFlags.NONE
);
} catch (IOError e) {
error ("Monitor Indicator DBus: %s\n", e.message);
Expand Down

0 comments on commit 9d28856

Please sign in to comment.