Mageia Bugzilla – Attachment 4573 Details for
Bug 11184
MCC doesn't start from launchers in several light DE but does from cli (polkit)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Patch to fix git master caja (aka mate-file-manager)
0001-Avoid-double-forking-when-launching-.desktop-files-a.patch (text/plain), 9.34 KB, created by
Colin Guthrie
on 2013-12-04 00:44:29 CET
(
hide
)
Description:
Patch to fix git master caja (aka mate-file-manager)
Filename:
MIME Type:
Creator:
Colin Guthrie
Created:
2013-12-04 00:44:29 CET
Size:
9.34 KB
patch
obsolete
>From 61621e64af9043fbb96592a6ae19e88ac0ab0650 Mon Sep 17 00:00:00 2001 >From: Colin Guthrie <colin@mageia.org> >Date: Tue, 3 Dec 2013 23:36:22 +0000 >Subject: [PATCH] Avoid double forking when launching .desktop files and other > binaries. > >This is a known incompatibility with certain tools which detect double forking >and refuse to operate (e.g. polkit). > >This was discovered will converting Mageia tools to polkit which >uses pkexec which is one of these tools. > >See https://bugs.mageia.org/show_bug.cgi?id=11184#c69 >--- > >Please Note: > > I've NOT tested the GTK3 bits. I have complied and tested the GTK2 bits > under a previous verison (i.e. not git master) but they applied fairly > cleanly so should be OK. The GTK3 bits look right to me but I cannot > confirm for sure. > > You may want to add better error reporting. > > > libcaja-private/caja-program-choosing.c | 176 ++++++++++++++++++++++++-------- > 1 file changed, 132 insertions(+), 44 deletions(-) > >diff --git a/libcaja-private/caja-program-choosing.c b/libcaja-private/caja-program-choosing.c >index 6971d2d..0f5d665 100644 >--- a/libcaja-private/caja-program-choosing.c >+++ b/libcaja-private/caja-program-choosing.c >@@ -168,6 +168,34 @@ caja_launch_application (GAppInfo *application, > g_list_free_full (uris, g_free); > } > >+/* >+ * Set the DISPLAY variable, to be use by g_spawn_async. >+ */ >+static void >+set_environment (gpointer display) >+{ >+ g_setenv("DISPLAY", display, TRUE); >+} >+ >+static void >+dummy_child_watch (GPid pid, >+ gint status, >+ gpointer user_data) >+{ >+ /* Nothing, this is just to ensure we don't double fork >+ * and break pkexec: >+ * https://bugzilla.gnome.org/show_bug.cgi?id=675789 >+ */ >+} >+ >+static void >+gather_pid_callback (GDesktopAppInfo *appinfo, >+ GPid pid, >+ gpointer data) >+{ >+ g_child_watch_add(pid, dummy_child_watch, NULL); >+} >+ > void > caja_launch_application_by_uri (GAppInfo *application, > GList *uris, >@@ -218,27 +246,13 @@ caja_launch_application_by_uri (GAppInfo *application, > } > > error = NULL; >- >- if (count == total) >- { >- /* All files are local, so we can use g_app_info_launch () with >- * the file list we constructed before. >- */ >- result = g_app_info_launch (application, >- locations, >- G_APP_LAUNCH_CONTEXT (launch_context), >- &error); >- } >- else >- { >- /* Some files are non local, better use g_app_info_launch_uris (). >- */ >- result = g_app_info_launch_uris (application, >- uris, >- G_APP_LAUNCH_CONTEXT (launch_context), >- &error); >- } >- >+ result = g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (application), >+ uris, >+ G_APP_LAUNCH_CONTEXT (launch_context), >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ NULL, NULL, >+ gather_pid_callback, application, >+ &error); > g_object_unref (launch_context); > > if (!result) >@@ -322,6 +336,7 @@ caja_launch_application_from_command (GdkScreen *screen, > } > else > { >+ GError *error = NULL; > #if GTK_CHECK_VERSION (3, 0, 0) > GdkAppLaunchContext *launch_context; > GAppInfo *app_info = NULL; >@@ -333,12 +348,54 @@ caja_launch_application_from_command (GdkScreen *screen, > { > launch_context = gdk_app_launch_context_new (); > gdk_app_launch_context_set_screen (launch_context, screen); >- g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), NULL); >+ g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (app_info), >+ NULL, >+ G_APP_LAUNCH_CONTEXT (launch_context), >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ NULL, NULL, >+ gather_pid_callback, app_info, >+ &error); >+ if (error) >+ { >+ g_error_free (error); >+ } > g_object_unref (launch_context); > g_object_unref (app_info); > } > #else >- gdk_spawn_command_line_on_screen (screen, full_command, NULL); >+ gchar **argv = NULL; >+ char* display; >+ GPid pid; >+ >+ if (!g_shell_parse_argv (full_command, NULL, &argv, &error)) >+ { >+ g_error_free (error); >+ g_free (full_command); >+ return; >+ } >+ >+ display = gdk_screen_make_display_name (screen); >+ >+ g_spawn_async ( >+ NULL, /* working directory */ >+ argv, >+ NULL, /* envp */ >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ set_environment, >+ display, >+ &pid, >+ &error); >+ >+ if (error) >+ { >+ g_error_free (error); >+ } >+ else >+ { >+ g_child_watch_add(pid, dummy_child_watch, NULL); >+ } >+ >+ g_free(display); > #endif > } > >@@ -387,6 +444,7 @@ caja_launch_application_from_command_array (GdkScreen *screen, > } > else > { >+ GError *error = NULL; > #if GTK_CHECK_VERSION (3, 0, 0) > GdkAppLaunchContext *launch_context; > GAppInfo *app_info = NULL; >@@ -398,12 +456,54 @@ caja_launch_application_from_command_array (GdkScreen *screen, > { > launch_context = gdk_app_launch_context_new (); > gdk_app_launch_context_set_screen (launch_context, screen); >- g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), NULL); >+ g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (app_info), >+ NULL, >+ G_APP_LAUNCH_CONTEXT (launch_context), >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ NULL, NULL, >+ gather_pid_callback, app_info, >+ &error); >+ if (error) >+ { >+ g_error_free (error); >+ } > g_object_unref (launch_context); > g_object_unref (app_info); > } > #else >- gdk_spawn_command_line_on_screen (screen, full_command, NULL); >+ gchar **argv = NULL; >+ char* display; >+ GPid pid; >+ >+ if (!g_shell_parse_argv (full_command, NULL, &argv, &error)) >+ { >+ g_error_free (error); >+ g_free (full_command); >+ return; >+ } >+ >+ display = gdk_screen_make_display_name (screen); >+ >+ g_spawn_async ( >+ NULL, /* working directory */ >+ argv, >+ NULL, /* envp */ >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ set_environment, >+ display, >+ &pid, >+ &error); >+ >+ if (error) >+ { >+ g_error_free (error); >+ } >+ else >+ { >+ g_child_watch_add(pid, dummy_child_watch, NULL); >+ } >+ >+ g_free(display); > #endif > } > >@@ -505,25 +605,13 @@ caja_launch_desktop_file (GdkScreen *screen, > gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME); > gdk_app_launch_context_set_screen (context, > gtk_window_get_screen (parent_window)); >- if (count == total) >- { >- /* All files are local, so we can use g_app_info_launch () with >- * the file list we constructed before. >- */ >- g_app_info_launch (G_APP_INFO (app_info), >- files, >- G_APP_LAUNCH_CONTEXT (context), >- &error); >- } >- else >- { >- /* Some files are non local, better use g_app_info_launch_uris (). >- */ >- g_app_info_launch_uris (G_APP_INFO (app_info), >- (GList *) parameter_uris, >- G_APP_LAUNCH_CONTEXT (context), >- &error); >- } >+ g_desktop_app_info_launch_uris_as_manager (app_info, >+ (GList *) parameter_uris, >+ G_APP_LAUNCH_CONTEXT (context), >+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, >+ NULL, NULL, >+ gather_pid_callback, app_info, >+ &error); > if (error != NULL) > { > message = g_strconcat (_("Details: "), error->message, NULL); >-- >1.8.4.4 >
From 61621e64af9043fbb96592a6ae19e88ac0ab0650 Mon Sep 17 00:00:00 2001 From: Colin Guthrie <colin@mageia.org> Date: Tue, 3 Dec 2013 23:36:22 +0000 Subject: [PATCH] Avoid double forking when launching .desktop files and other binaries. This is a known incompatibility with certain tools which detect double forking and refuse to operate (e.g. polkit). This was discovered will converting Mageia tools to polkit which uses pkexec which is one of these tools. See https://bugs.mageia.org/show_bug.cgi?id=11184#c69 --- Please Note: I've NOT tested the GTK3 bits. I have complied and tested the GTK2 bits under a previous verison (i.e. not git master) but they applied fairly cleanly so should be OK. The GTK3 bits look right to me but I cannot confirm for sure. You may want to add better error reporting. libcaja-private/caja-program-choosing.c | 176 ++++++++++++++++++++++++-------- 1 file changed, 132 insertions(+), 44 deletions(-) diff --git a/libcaja-private/caja-program-choosing.c b/libcaja-private/caja-program-choosing.c index 6971d2d..0f5d665 100644 --- a/libcaja-private/caja-program-choosing.c +++ b/libcaja-private/caja-program-choosing.c @@ -168,6 +168,34 @@ caja_launch_application (GAppInfo *application, g_list_free_full (uris, g_free); } +/* + * Set the DISPLAY variable, to be use by g_spawn_async. + */ +static void +set_environment (gpointer display) +{ + g_setenv("DISPLAY", display, TRUE); +} + +static void +dummy_child_watch (GPid pid, + gint status, + gpointer user_data) +{ + /* Nothing, this is just to ensure we don't double fork + * and break pkexec: + * https://bugzilla.gnome.org/show_bug.cgi?id=675789 + */ +} + +static void +gather_pid_callback (GDesktopAppInfo *appinfo, + GPid pid, + gpointer data) +{ + g_child_watch_add(pid, dummy_child_watch, NULL); +} + void caja_launch_application_by_uri (GAppInfo *application, GList *uris, @@ -218,27 +246,13 @@ caja_launch_application_by_uri (GAppInfo *application, } error = NULL; - - if (count == total) - { - /* All files are local, so we can use g_app_info_launch () with - * the file list we constructed before. - */ - result = g_app_info_launch (application, - locations, - G_APP_LAUNCH_CONTEXT (launch_context), - &error); - } - else - { - /* Some files are non local, better use g_app_info_launch_uris (). - */ - result = g_app_info_launch_uris (application, - uris, - G_APP_LAUNCH_CONTEXT (launch_context), - &error); - } - + result = g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (application), + uris, + G_APP_LAUNCH_CONTEXT (launch_context), + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, + gather_pid_callback, application, + &error); g_object_unref (launch_context); if (!result) @@ -322,6 +336,7 @@ caja_launch_application_from_command (GdkScreen *screen, } else { + GError *error = NULL; #if GTK_CHECK_VERSION (3, 0, 0) GdkAppLaunchContext *launch_context; GAppInfo *app_info = NULL; @@ -333,12 +348,54 @@ caja_launch_application_from_command (GdkScreen *screen, { launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, screen); - g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), NULL); + g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (app_info), + NULL, + G_APP_LAUNCH_CONTEXT (launch_context), + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, + gather_pid_callback, app_info, + &error); + if (error) + { + g_error_free (error); + } g_object_unref (launch_context); g_object_unref (app_info); } #else - gdk_spawn_command_line_on_screen (screen, full_command, NULL); + gchar **argv = NULL; + char* display; + GPid pid; + + if (!g_shell_parse_argv (full_command, NULL, &argv, &error)) + { + g_error_free (error); + g_free (full_command); + return; + } + + display = gdk_screen_make_display_name (screen); + + g_spawn_async ( + NULL, /* working directory */ + argv, + NULL, /* envp */ + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + set_environment, + display, + &pid, + &error); + + if (error) + { + g_error_free (error); + } + else + { + g_child_watch_add(pid, dummy_child_watch, NULL); + } + + g_free(display); #endif } @@ -387,6 +444,7 @@ caja_launch_application_from_command_array (GdkScreen *screen, } else { + GError *error = NULL; #if GTK_CHECK_VERSION (3, 0, 0) GdkAppLaunchContext *launch_context; GAppInfo *app_info = NULL; @@ -398,12 +456,54 @@ caja_launch_application_from_command_array (GdkScreen *screen, { launch_context = gdk_app_launch_context_new (); gdk_app_launch_context_set_screen (launch_context, screen); - g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), NULL); + g_desktop_app_info_launch_uris_as_manager (G_DESKTOP_APP_INFO (app_info), + NULL, + G_APP_LAUNCH_CONTEXT (launch_context), + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, + gather_pid_callback, app_info, + &error); + if (error) + { + g_error_free (error); + } g_object_unref (launch_context); g_object_unref (app_info); } #else - gdk_spawn_command_line_on_screen (screen, full_command, NULL); + gchar **argv = NULL; + char* display; + GPid pid; + + if (!g_shell_parse_argv (full_command, NULL, &argv, &error)) + { + g_error_free (error); + g_free (full_command); + return; + } + + display = gdk_screen_make_display_name (screen); + + g_spawn_async ( + NULL, /* working directory */ + argv, + NULL, /* envp */ + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + set_environment, + display, + &pid, + &error); + + if (error) + { + g_error_free (error); + } + else + { + g_child_watch_add(pid, dummy_child_watch, NULL); + } + + g_free(display); #endif } @@ -505,25 +605,13 @@ caja_launch_desktop_file (GdkScreen *screen, gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME); gdk_app_launch_context_set_screen (context, gtk_window_get_screen (parent_window)); - if (count == total) - { - /* All files are local, so we can use g_app_info_launch () with - * the file list we constructed before. - */ - g_app_info_launch (G_APP_INFO (app_info), - files, - G_APP_LAUNCH_CONTEXT (context), - &error); - } - else - { - /* Some files are non local, better use g_app_info_launch_uris (). - */ - g_app_info_launch_uris (G_APP_INFO (app_info), - (GList *) parameter_uris, - G_APP_LAUNCH_CONTEXT (context), - &error); - } + g_desktop_app_info_launch_uris_as_manager (app_info, + (GList *) parameter_uris, + G_APP_LAUNCH_CONTEXT (context), + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, + gather_pid_callback, app_info, + &error); if (error != NULL) { message = g_strconcat (_("Details: "), error->message, NULL); -- 1.8.4.4
View Attachment As Raw
Actions:
View
Attachments on
bug 11184
:
4401
| 4573 |
5849