gdesktopappinfo: Use sh rather than gio-launch-desktop

There were some problems about where to install `gio-launch-desktop` to
support multiarch systems without circular dependencies. Simon McVittie
suggested that, actually, given the current set of platforms supported
by `GDesktopAppInfo` (they’re all POSIX), we could just use `sh`.

That simplifies things nicely. `gio-launch-desktop` can always be
resurrected (and the multiarch debate continued and resolved) if needed
in future.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1633
This commit is contained in:
Philip Withnall
2020-02-13 10:26:14 +00:00
parent 4a153abebe
commit 2b533ca99a
4 changed files with 25 additions and 77 deletions

View File

@@ -160,7 +160,6 @@ static const gchar *desktop_file_dirs_config_dir = NULL;
static DesktopFileDir *desktop_file_dir_user_config = NULL; /* (owned) */
static DesktopFileDir *desktop_file_dir_user_data = NULL; /* (owned) */
static GMutex desktop_file_dir_lock;
static const gchar *gio_launch_desktop_path = NULL;
/* Monitor 'changed' signal handler {{{2 */
static void desktop_file_dir_reset (DesktopFileDir *dir);
@@ -2737,6 +2736,14 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
char *sn_id = NULL;
char **wrapped_argv;
int i;
const gchar * const wrapper_argv[] =
{
"/bin/sh",
"-e",
"-u",
"-c", "export GIO_LAUNCHED_DESKTOP_FILE_PID=$$; exec \"$@\"",
"sh", /* argv[0] for sh */
};
old_uris = dup_uris;
if (!expand_application_parameters (info, exec_line, &dup_uris, &argc, &argv, error))
@@ -2778,26 +2785,26 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
g_list_free_full (launched_files, g_object_unref);
}
if (g_once_init_enter (&gio_launch_desktop_path))
{
const gchar *tmp;
/* Allow test suite to specify path to gio-launch-desktop */
tmp = g_getenv ("GIO_LAUNCH_DESKTOP");
/* Fall back on usual searching in $PATH */
if (tmp == NULL)
tmp = "gio-launch-desktop";
g_once_init_leave (&gio_launch_desktop_path, tmp);
}
wrapped_argv = g_new (char *, argc + 2);
wrapped_argv[0] = g_strdup (gio_launch_desktop_path);
/* Wrap the @argv in a command which will set the
* `GIO_LAUNCHED_DESKTOP_FILE_PID` environment variable. We cant set this
* in @envp along with `GIO_LAUNCHED_DESKTOP_FILE` because we need to know
* the PID of the new forked process. We cant use setenv() between fork()
* and exec() because wed rather use posix_spawn() for speed.
*
* `sh` should be available on all the platforms that `GDesktopAppInfo`
* currently supports (since they are all POSIX). If additional platforms
* need to be supported in future, it will probably have to be replaced
* with a wrapper program (grep the GLib git history for
* `gio-launch-desktop` for an example of this which could be
* resurrected). */
wrapped_argv = g_new (char *, argc + G_N_ELEMENTS (wrapper_argv) + 1);
for (i = 0; i < G_N_ELEMENTS (wrapper_argv); i++)
wrapped_argv[i] = g_strdup (wrapper_argv[i]);
for (i = 0; i < argc; i++)
wrapped_argv[i + 1] = g_steal_pointer (&argv[i]);
wrapped_argv[i + G_N_ELEMENTS (wrapper_argv)] = g_steal_pointer (&argv[i]);
wrapped_argv[i + 1] = NULL;
wrapped_argv[i + G_N_ELEMENTS (wrapper_argv)] = NULL;
g_free (argv);
argv = NULL;