Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes, reliability improvements. #410

Merged
merged 10 commits into from
Jul 14, 2022
37 changes: 19 additions & 18 deletions backup-locker/cs-backup-locker.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <gdk/gdkx.h>

#include <libcscreensaver/cs-gdk-event-filter.h>
#include "event-grabber.h"
#include <libcscreensaver/cs-event-grabber.h>

static gboolean debug = FALSE;
static guint term_tty = 0;
Expand All @@ -30,7 +30,7 @@ struct _BackupWindow
GtkWidget *info_box;

CsGdkEventFilter *event_filter;
EventGrabber *grabber;
CsEventGrabber *grabber;

gulong pretty_xid;
gboolean should_grab;
Expand All @@ -45,7 +45,6 @@ position_info_box (BackupWindow *window)
GdkMonitor *monitor = gdk_display_get_primary_monitor (display);
GdkRectangle rect;
GtkRequisition natural_size;
gint baseline;

gtk_widget_get_preferred_size (window->info_box, NULL, &natural_size);

Expand Down Expand Up @@ -119,12 +118,12 @@ backup_window_show (GtkWidget *widget)
cs_gdk_event_filter_start (BACKUP_WINDOW (widget)->event_filter);
}

static gboolean window_grab_broken (gpointer data);
static void window_grab_broken (gpointer data);

static void
activate_backup_window (BackupWindow *window)
{
event_grabber_move_to_window (window->grabber,
cs_event_grabber_move_to_window (window->grabber,
gtk_widget_get_window (GTK_WIDGET (window)),
gtk_widget_get_screen (GTK_WIDGET (window)),
FALSE);
Expand All @@ -140,12 +139,12 @@ activate_backup_window (BackupWindow *window)
static void
backup_window_ungrab (BackupWindow *window)
{
event_grabber_release (window->grabber);
cs_event_grabber_release (window->grabber);

window->should_grab = FALSE;
}

static gboolean
static void
window_grab_broken (gpointer data)
{
BackupWindow *window = BACKUP_WINDOW (data);
Expand All @@ -156,7 +155,6 @@ window_grab_broken (gpointer data)
{
activate_backup_window (window);
}
return GDK_EVENT_PROPAGATE;
}

static void
Expand Down Expand Up @@ -285,7 +283,7 @@ backup_window_init (BackupWindow *window)
gtk_fixed_put (GTK_FIXED (window->fixed), window->info_box, 0, 0);
gtk_widget_show (window->fixed);

window->grabber = event_grabber_new ();
window->grabber = cs_event_grabber_new (debug);
}

static void
Expand Down Expand Up @@ -317,7 +315,7 @@ backup_window_class_init (BackupWindowClass *klass)
widget_class->realize = backup_window_realize;
}

GtkWidget *
static GtkWidget *
backup_window_new (gulong pretty_xid)
{
BackupWindow *window;
Expand Down Expand Up @@ -366,13 +364,16 @@ window_monitor_thread (GTask *task,
if (xprop_proc == NULL)
{
g_critical ("unable to monitor screensaver window: %s", error->message);
g_clear_error (&error);
}
else
{
g_subprocess_wait (xprop_proc, cancellable, NULL);
g_subprocess_wait (xprop_proc, cancellable, &error);
if (error != NULL && error->code != G_IO_ERROR_CANCELLED)
{
g_critical ("problem with screensaver window monitor: %s", error->message);
}
}

g_clear_error (&error);
g_task_return_boolean (task, TRUE);
}

Expand Down Expand Up @@ -414,10 +415,14 @@ setup_window_monitor (BackupWindow *window, gulong xid)
static gboolean
sigterm_received (gpointer data)
{
GtkWidget *window = GTK_WIDGET (data);

g_clear_handle_id (&sigterm_src_id, g_source_remove);
g_cancellable_cancel (window_monitor_cancellable);

gtk_widget_destroy (window);
gtk_main_quit ();

sigterm_src_id = 0;
return G_SOURCE_REMOVE;
}

Expand Down Expand Up @@ -501,10 +506,6 @@ main (int argc,

gtk_main ();

g_clear_handle_id (&sigterm_src_id, g_source_remove);
g_cancellable_cancel (window_monitor_cancellable);
gtk_widget_destroy (window);

g_debug ("cs-backup-locker finished");

return 0;
Expand Down
79 changes: 0 additions & 79 deletions backup-locker/event-grabber.h

This file was deleted.

2 changes: 0 additions & 2 deletions backup-locker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ bl_config = configure_file(output : 'config.h',

bl_sources = [
'cs-backup-locker.c',
'event-grabber.c',
'event-grabber.h'
]

backup_locker = executable('cs-backup-locker',
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Build-Depends:
libgtk-3-dev (>= 3.22),
libpam0g-dev,
librsvg2-bin,
libxdo-dev,
libxext-dev,
meson (>= 0.40.0),
python3,
Expand All @@ -32,6 +33,7 @@ Depends:
gir1.2-xapp-1.0,
iso-flag-png,
libcscreensaver0 (= ${binary:Version}),
libxdo3,
python3,
python3-gi,
python3-gi-cairo,
Expand Down
28 changes: 15 additions & 13 deletions libcscreensaver/cs-auth-pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>

#include "cs-auth.h"

Expand Down Expand Up @@ -76,6 +75,7 @@
# define PAM_STRERROR(pamh, status) pam_strerror((status))
#endif /* !PAM_STRERROR_TWO_ARGS */

static GMainLoop *auth_loop = NULL;
static gboolean verbose_enabled = FALSE;
static pam_handle_t *pam_handle = NULL;
static gboolean did_we_ask_for_password = FALSE;
Expand Down Expand Up @@ -234,7 +234,7 @@ cs_auth_run_message_handler (struct pam_closure *c,
g_idle_add ((GSourceFunc) cs_auth_queued_message_handler, &data);

if (cs_auth_get_verbose ()) {
DEBUG ("Waiting for respose to message style %d: '%s'\n", style, msg);
DEBUG ("cs-auth-pam (pid %i): Waiting for respose to message style %d: '%s'\n", getpid (), style, msg);
}

/* Wait for the response
Expand All @@ -244,7 +244,7 @@ cs_auth_run_message_handler (struct pam_closure *c,
g_mutex_unlock (message_handler_mutex);

if (cs_auth_get_verbose ()) {
DEBUG ("Got respose to message style %d: interrupt:%d\n", style, data.should_interrupt_stack);
DEBUG ("cs-auth-pam (pid %i): Got respose to message style %d: interrupt:%d\n", getpid (), style, data.should_interrupt_stack);
}

return data.should_interrupt_stack == FALSE;
Expand Down Expand Up @@ -410,7 +410,8 @@ create_pam_handle (const char *username,
}

if (cs_auth_get_verbose ()) {
DEBUG ("pam_start (\"%s\", \"%s\", ...) ==> %d (%s)\n",
DEBUG ("cs-auth-pam (pid %i): pam_start (\"%s\", \"%s\", ...) ==> %d (%s)\n",
getpid (),
service,
username,
status,
Expand Down Expand Up @@ -482,15 +483,16 @@ set_pam_error (GError **error,

}

static int
cs_auth_thread_func (int auth_operation_fd)
static gpointer
cs_auth_thread_func (gpointer auth_operation_fd_ptr)
{
static const int flags = 0;
int status;
int status2;
struct timespec timeout;
sigset_t set;
const void *p;
int auth_operation_fd = GPOINTER_TO_INT(auth_operation_fd_ptr);

timeout.tv_sec = 0;
timeout.tv_nsec = 1;
Expand Down Expand Up @@ -569,7 +571,7 @@ cs_auth_thread_func (int auth_operation_fd)
*/
close (auth_operation_fd);

return status;
return GINT_TO_POINTER(status);
}

static gboolean
Expand All @@ -578,7 +580,7 @@ cs_auth_loop_quit (GIOChannel *source,
gboolean *thread_done)
{
*thread_done = TRUE;
gtk_main_quit ();
g_main_loop_quit (auth_loop);
return FALSE;
}

Expand Down Expand Up @@ -627,16 +629,16 @@ cs_auth_pam_verify_user (pam_handle_t *handle,
watch_id = g_io_add_watch (channel, G_IO_ERR | G_IO_HUP,
(GIOFunc) cs_auth_loop_quit, &thread_done);

auth_thread = g_thread_create ((GThreadFunc) cs_auth_thread_func,
GINT_TO_POINTER (auth_operation_fds[1]),
TRUE, NULL);
auth_thread = g_thread_new ("cs-auth-verify-user",
(GThreadFunc) cs_auth_thread_func,
GINT_TO_POINTER (auth_operation_fds[1]));

if (auth_thread == NULL) {
goto out;
}

gtk_main ();

auth_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (auth_loop);
/* if the event loop was quit before the thread is done then we can't
* reap the thread without blocking on it finishing. The
* thread may not ever finish though if the pam module is blocking.
Expand Down
Loading