Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Utility/OSDNotify.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public class OSDNotify : GLib.Object {

string s = "notify-send -t %d -u %s -i %s \"%s\" \"%s\" -h %s".printf(
durationMillis, urgency, "gtk-dialog-" + dialog_type, title, message, hint);
retVal = exec_sync (s, null, null);

retVal = TeeJee.ProcessHelper.exec_user_async(s);

dt_last_notification = new DateTime.now_local();
}
Expand Down
20 changes: 20 additions & 0 deletions src/Utility/TeeJee.Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@
}
}

/**
executes a command as the "normal" unprivileged user async
may execute the command as root if the user could not be determined or the name could not be resolved
*/
public static int exec_user_async(string command) {
// find correct user
int uid = TeeJee.System.get_user_id();
string cmd = command;
if(uid > 0) {
// non root
string? user = TeeJee.System.get_username_from_uid(uid);
if(user != null) {
cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ".printf(user) + cmd;
}
}

log_debug(cmd);
return TeeJee.ProcessHelper.exec_script_async(cmd);
}

public string? save_bash_script_temp (string commands, string? script_path = null,
bool force_locale = true, bool supress_errors = false){

Expand Down Expand Up @@ -286,7 +306,7 @@
string path = "/proc/%s/stat".printf(pidStr);
string stats = file_read(path);
string details = stats.split(")", 2)[1];
string[] splitted = details.split(" ", 3);

Check failure on line 309 in src/Utility/TeeJee.Process.vala

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

splitted ==> split
if(splitted.length == 3) {
return int.parse(splitted[2]);
}
Expand Down
20 changes: 6 additions & 14 deletions src/Utility/TeeJee.System.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ namespace TeeJee.System{

public string? get_username_from_uid(int user_id){
unowned Posix.Passwd? pw = Posix.getpwuid(user_id);
return pw?.pw_name;
string? outvalue = pw?.pw_name;
if(null == outvalue) {
log_error("Could not get username for uid %d".printf(user_id));
}
return outvalue;
}

// system ------------------------------------
Expand All @@ -90,19 +94,7 @@ namespace TeeJee.System{

string cmd = "xdg-open '%s'".printf(escape_single_quote(file));

// find correct user
int uid = get_user_id();
if(uid > 0) {
// non root
string? user = get_username_from_uid(uid);
if(user != null) {
cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ".printf(user) + cmd;
}
}

log_debug(cmd);
int status = exec_script_async(cmd);
return (status == 0);
return exec_user_async(cmd) == 0;
}

public bool exo_open_folder (string dir_path, bool xdg_open_try_first = true){
Expand Down
Loading