From 6b33e6fe6d7c729448397d4fde8734117d7959c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 1 May 2024 01:14:43 +0200 Subject: [PATCH] js: Use Shell.util_spawn_async functions to launch external processes As explained in previous commits, it's not safe to use JS code in child function callbacks, so let's use the safer version of it. Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6698 Part-of: (cherry picked from commit 26e8fb90fb595510240c57b0862013dbf4739770) --- js/misc/ibusManager.js | 11 ++--------- js/misc/util.js | 13 +++---------- js/ui/components/networkAgent.js | 12 +++--------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js index 510561b4d..6d7582cb9 100644 --- a/js/misc/ibusManager.js +++ b/js/misc/ibusManager.js @@ -120,16 +120,9 @@ class IBusManager extends Signals.EventEmitter { const env = launchContext.get_environment(); // Use DO_NOT_REAP_CHILD to avoid adouble-fork internally // since ibus-daemon refuses to start with init as its parent. - const [success_, pid] = GLib.spawn_async( + const pid = Shell.util_spawn_async( null, cmdLine, env, - GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, - () => { - try { - global.context.restore_rlimit_nofile(); - } catch (err) { - } - } - ); + GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD); GLib.child_watch_add( GLib.PRIORITY_DEFAULT, pid, diff --git a/js/misc/util.js b/js/misc/util.js index de5e6d861..ea27f2125 100644 --- a/js/misc/util.js +++ b/js/misc/util.js @@ -118,19 +118,12 @@ export function spawnApp(argv) { * this will throw an error. */ export function trySpawn(argv) { - let success_, pid; + let pid; try { const launchContext = global.create_app_launch_context(0, -1); - [success_, pid] = GLib.spawn_async( + pid = Shell.util_spawn_async( null, argv, launchContext.get_environment(), - GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, - () => { - try { - global.context.restore_rlimit_nofile(); - } catch (err) { - } - } - ); + GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD); } catch (err) { /* Rewrite the error in case of ENOENT */ if (err.matches(GLib.SpawnError, GLib.SpawnError.NOENT)) { diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js index 3d187a878..d5d947024 100644 --- a/js/ui/components/networkAgent.js +++ b/js/ui/components/networkAgent.js @@ -456,18 +456,12 @@ class VPNRequestHandler extends Signals.EventEmitter { try { const launchContext = global.create_app_launch_context(0, -1); - let [success_, pid, stdin, stdout, stderr] = - GLib.spawn_async_with_pipes( + let [pid, stdin, stdout, stderr] = + Shell.util_spawn_async_with_pipes( null, /* pwd */ argv, launchContext.get_environment(), - GLib.SpawnFlags.DO_NOT_REAP_CHILD, - () => { - try { - global.context.restore_rlimit_nofile(); - } catch (err) { - } - }); + GLib.SpawnFlags.DO_NOT_REAP_CHILD); this._childPid = pid; this._stdin = new Gio.UnixOutputStream({fd: stdin, close_fd: true});