diff options
author | rbuj <[email protected]> | 2021-01-04 13:57:25 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2021-01-28 21:16:27 +0100 |
commit | e84fa6a065138aa930bfbcc8ea54de6ed1b40de1 (patch) | |
tree | 86f3b2380a7e7363d64b8529a451599eda80fb93 | |
parent | 86d43b190d57402a7e531a8079f90b52bc83567f (diff) | |
download | caja-extensions-e84fa6a065138aa930bfbcc8ea54de6ed1b40de1.tar.bz2 caja-extensions-e84fa6a065138aa930bfbcc8ea54de6ed1b40de1.tar.xz |
gksu: do not run the command on a new thread
-rw-r--r-- | gksu/libcaja-gksu.c | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/gksu/libcaja-gksu.c b/gksu/libcaja-gksu.c index 177acf3..768035a 100644 --- a/gksu/libcaja-gksu.c +++ b/gksu/libcaja-gksu.c @@ -6,10 +6,7 @@ #include <stdlib.h> #include <unistd.h> -#include <sys/types.h> -#include <sys/wait.h> #include <string.h> -#include <pthread.h> #include <glib.h> #include <gtk/gtk.h> #include <gio/gio.h> @@ -143,41 +140,11 @@ gksu_context_menu_get_file_items (CajaMenuProvider *provider, return items; } -gboolean -is_gksu_dead (gpointer data) -{ - GPid pid = GPOINTER_TO_INT(data); - if (waitpid (pid, NULL, WNOHANG) > 0) - return FALSE; - return TRUE; -} - -static void* -start_gksu_thread (void *data) -{ - GPid pid; - gchar **argv = (gchar**) g_malloc (sizeof (gchar*) * 3); - gchar *full_cmd = (gchar*) data; - - argv[0] = g_strdup ("gksu"); - argv[1] = full_cmd; - argv[2] = NULL; - - g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, - &pid, NULL); - g_timeout_add (5000, is_gksu_dead, GINT_TO_POINTER(pid)); - - g_free (argv[0]); - g_free (full_cmd); - g_free (argv); - - return NULL; -} - static void gksu_context_menu_activate (CajaMenuItem *item, CajaFileInfo *file) { + gchar *exec_path; gchar *uri = NULL; gchar *mime_type = NULL; gchar *cmd = NULL; @@ -247,12 +214,55 @@ gksu_context_menu_activate (CajaMenuItem *item, g_free (cmd); } - { - pthread_t new_thread; - pthread_create (&new_thread, NULL, start_gksu_thread, (void*)full_cmd); - } + if ((exec_path = g_find_program_in_path ("gksu")) == NULL) + { + if ((exec_path = g_find_program_in_path ("beesu")) == NULL) + { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new_with_markup (NULL, 0, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("<big><b>" + "Unable to determine the graphical wrapper for su" + "</b></big>\n\n" + "The item you selected cannot be open with " + "administrator powers because the graphical wrapper " + "for su cannot be determined, such as gtksu or beesu.")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + } + + if (exec_path != NULL) + { + GError *error = NULL; + gchar **argv = (gchar**) g_malloc (sizeof (gchar*) * 3); + + argv[0] = exec_path; + argv[1] = full_cmd; + argv[2] = NULL; + + if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error)) + { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (NULL, 0, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("Error: %s"), + error->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + g_error_free (error); + } + g_strfreev (argv); + } + else + { + g_free (full_cmd); + } - /* full_cmd is freed by start_gksu_thread */ g_free (uri); g_free (mime_type); } |