From fdf050f2672eb8bcab5d392a97ef8fba75c38267 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 22 Mar 2018 13:00:33 -0400 Subject: [PATCH] jsauthority: use InterruptCallback api instead of OperationCallback seems like it got renamed. Signed-off-by: Ray Strode https://bugs.freedesktop.org/show_bug.cgi?id=105865 --- src/polkitbackend/polkitbackendjsauthority.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 2e26af9..830f5cd 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -923,109 +923,111 @@ runaway_killer_thread_func (gpointer user_data) g_main_loop_run (authority->priv->rkt_loop); g_main_context_pop_thread_default (authority->priv->rkt_context); return NULL; } /* ---------------------------------------------------------------------------------------------------- */ static bool js_operation_callback (JSContext *cx) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); JSString *val_str; JS::Value val; /* This callback can be called by the runtime at any time without us causing * it by JS_TriggerOperationCallback(). */ g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); if (!authority->priv->rkt_timeout_pending) { g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); return true; } authority->priv->rkt_timeout_pending = FALSE; g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); /* Log that we are terminating the script */ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Terminating runaway script"); /* Throw an exception - this way the JS code can ignore the runaway script handling */ - JS_SetOperationCallback (authority->priv->cx, NULL); + JS_ResetInterruptCallback (authority->priv->cx, TRUE); val_str = JS_NewStringCopyZ (cx, "Terminating runaway script"); val = JS::StringValue (val_str); JS_SetPendingException (authority->priv->cx, val); - JS_SetOperationCallback (authority->priv->cx, js_operation_callback); + JS_ResetInterruptCallback (authority->priv->cx, FALSE); return false; } static gboolean rkt_on_timeout (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); authority->priv->rkt_timeout_pending = TRUE; g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); /* Supposedly this is thread-safe... */ - JS_TriggerOperationCallback (authority->priv->rt); + JS_RequestInterruptCallback (authority->priv->cx); /* keep source around so we keep trying to kill even if the JS bit catches the exception * thrown in js_operation_callback() */ return TRUE; } static void runaway_killer_setup (PolkitBackendJsAuthority *authority) { g_assert (authority->priv->rkt_source == NULL); /* set-up timer for runaway scripts, will be executed in runaway_killer_thread */ g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); authority->priv->rkt_timeout_pending = FALSE; g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); authority->priv->rkt_source = g_timeout_source_new_seconds (15); g_source_set_callback (authority->priv->rkt_source, rkt_on_timeout, authority, NULL); g_source_attach (authority->priv->rkt_source, authority->priv->rkt_context); /* ... rkt_on_timeout() will then poke the JSContext so js_operation_callback() is * called... and from there we throw an exception */ - JS_SetOperationCallback (authority->priv->cx, js_operation_callback); + JS_AddInterruptCallback (authority->priv->cx, js_operation_callback); + JS_ResetInterruptCallback (authority->priv->cx, FALSE); } static void runaway_killer_teardown (PolkitBackendJsAuthority *authority) { - JS_SetOperationCallback (authority->priv->cx, NULL); + JS_ResetInterruptCallback (authority->priv->cx, TRUE); + g_source_destroy (authority->priv->rkt_source); g_source_unref (authority->priv->rkt_source); authority->priv->rkt_source = NULL; } static gboolean runaway_killer_call_g_main_quit (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); g_main_loop_quit (authority->priv->rkt_loop); return G_SOURCE_REMOVE; } static void runaway_killer_terminate (PolkitBackendJsAuthority *authority) { GSource *source; /* Use a g_idle_source_new () to ensure g_main_loop_quit () is called from * inside a running rkt_loop. This prevents a possible race condition, where * we could be calling g_main_loop_quit () on the main thread before * runaway_killer_thread_func () starts its g_main_loop_run () call; * g_main_loop_quit () before g_main_loop_run () does nothing, so in such * a case we would not terminate the thread and become blocked in * g_thread_join () below. */ g_assert (authority->priv->rkt_loop != NULL); source = g_idle_source_new (); g_source_set_callback (source, runaway_killer_call_g_main_quit, authority, -- 2.16.2