js/environment: Always use Shell.util_spawn_async functions if possible

If no child setup is provided then all the shell extensions that use
GLib.spawn_async should actually use the shell spawning utils since we
are supposed to always restore the default nofile rlimit on launched
children.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3293>
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-03 18:13:37 +02:00 committed by Marge Bot
parent 494be30764
commit 64edd7940d

View File

@ -348,14 +348,17 @@ if (slowdownEnv) {
function wrapSpawnFunction(func) {
const originalFunc = GLib[func];
return function (workingDirectory, argv, envp, flags, childSetup, ...args) {
const commonArgs = [workingDirectory, argv, envp, flags];
if (childSetup) {
logError(new Error(`Using child GLib.${func} with a GLib.SpawnChildSetupFunc ` +
'is unsafe and may dead-lock, thus it should never be used from JavaScript. ' +
`Shell.${func} can be used to perform default actions or an ` +
'async-signal-safe alternative should be used instead'));
return originalFunc(...commonArgs, childSetup, ...args);
}
return originalFunc(workingDirectory, argv, envp, flags, childSetup, ...args);
const retValue = Shell[`util_${func}`](...commonArgs, ...args);
return [true, ...Array.isArray(retValue) ? retValue : [retValue]];
};
}
GLib.spawn_async = wrapSpawnFunction('spawn_async');