Skip to content

Commit db08988

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 db08988

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

src/Utility/TeeJee.Process.vala

Lines changed: 68 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,75 @@ 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+
try {
233+
string[] cmd_parts;
234+
Shell.parse_argv(command, out cmd_parts);
235+
foreach (string part in cmd_parts) {
236+
args += part;
237+
}
238+
} catch (ShellError e) {
239+
log_error("Failed to parse command: " + e.message);
240+
return 1;
241+
}
242+
} else {
243+
try {
244+
Shell.parse_argv(command, out args);
245+
} catch (ShellError e) {
246+
log_error("Failed to parse command: " + e.message);
247+
return 1;
248+
}
249+
}
250+
} else {
251+
try {
252+
Shell.parse_argv(command, out args);
253+
} catch (ShellError e) {
254+
log_error("Failed to parse command: " + e.message);
255+
return 1;
218256
}
219257
}
220258

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

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

0 commit comments

Comments
 (0)