Skip to content

Commit dacee98

Browse files
committed
Fixed error in status file writing via notify-send after TEMP_DIR deletion.
Even after TEMP_DIR has been deleted, notify-send may still be executed. In such cases, writing to the status file becomes impossible. Since the inability to obtain notify-send's exit code does not cause any critical issues, the behaviour will be changed to refrain from creating the status file.
1 parent 8be5172 commit dacee98

1 file changed

Lines changed: 63 additions & 5 deletions

File tree

src/Utility/TeeJee.Process.vala

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ namespace TeeJee.ProcessHelper{
178178

179179
try {
180180

181-
string scriptfile = save_bash_script_temp (script);
181+
string? scriptfile = save_bash_script_temp (script);
182+
183+
if (scriptfile == null) {
184+
log_error("Failed to create temporary script");
185+
return 1;
186+
}
182187

183188
string[] argv = new string[1];
184189
argv[0] = scriptfile;
@@ -209,17 +214,70 @@ namespace TeeJee.ProcessHelper{
209214
public static int exec_user_async(string command) {
210215
// find correct user
211216
int uid = TeeJee.System.get_user_id();
212-
string cmd = command;
217+
string[] args;
218+
213219
if(uid > 0) {
214220
// non root
215221
string? user = TeeJee.System.get_username_from_uid(uid);
216222
if(user != null) {
217-
cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ".printf(user) + cmd;
223+
args = new string[] {
224+
"pkexec",
225+
"--user", user,
226+
"env",
227+
"DISPLAY=" + Environment.get_variable("DISPLAY"),
228+
"XAUTHORITY=" + Environment.get_variable("XAUTHORITY"),
229+
"DBUS_SESSION_BUS_ADDRESS=" + Environment.get_variable("DBUS_SESSION_BUS_ADDRESS")
230+
};
231+
232+
string[] cmd_parts = parse_command(command);
233+
foreach (string part in cmd_parts) {
234+
args += part;
235+
}
236+
} else {
237+
args = parse_command(command);
218238
}
239+
} else {
240+
args = parse_command(command);
241+
}
242+
243+
log_debug(string.joinv(" ", args));
244+
return TeeJee.ProcessHelper.exec_async_with_args(args);
245+
}
246+
247+
private static string[] parse_command(string command) {
248+
try {
249+
string[] args;
250+
Shell.parse_argv(command, out args);
251+
return args;
252+
} catch (Error e) {
253+
log_error("Failed to parse command: " + e.message);
254+
return new string[] { command };
219255
}
256+
}
220257

221-
log_debug(cmd);
222-
return TeeJee.ProcessHelper.exec_script_async(cmd);
258+
public int exec_async_with_args(string[] argv) {
259+
/**
260+
* Executes commands asynchronously with proper argument array.
261+
*/
262+
263+
try {
264+
string[] env = Environ.get();
265+
Pid child_pid;
266+
267+
Process.spawn_async_with_pipes(
268+
TEMP_DIR, //working dir
269+
argv, //argv (properly parsed)
270+
env, //environment
271+
SpawnFlags.SEARCH_PATH,
272+
null,
273+
out child_pid);
274+
275+
return 0;
276+
}
277+
catch (Error e){
278+
log_error (e.message);
279+
return 1;
280+
}
223281
}
224282

225283
public string? save_bash_script_temp (string commands, string? script_path = null,

0 commit comments

Comments
 (0)