Skip to content

Commit 3babb0d

Browse files
authored
Always send dbus method reply (#56)
Some method handlers were never sending a reply. Even if the method returns no data, the service should acknowledge that the method call has been processed and reply to the sender. This was previously triggering the dbus invocation timeout (25s by default), and synchronous calls would block for a long time.
1 parent da932ed commit 3babb0d

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PKG_CHECK_MODULES([CPDB],[cpdb >= 2])
1717
PKG_CHECK_MODULES([LIBCUPSFILTERS], [libcupsfilters >= 2])
1818
PKG_CHECK_MODULES([GIO],[gio-2.0])
1919
PKG_CHECK_MODULES([GIOUNIX],[gio-unix-2.0])
20-
PKG_CHECK_MODULES([GLIB],[glib-2.0])
20+
PKG_CHECK_MODULES([GLIB],[glib-2.0 >= 2.74])
2121

2222
# Checks for header files.
2323
AC_CHECK_HEADERS([stdlib.h string.h cups/cups.h cupsfilters/catalog.h])

src/print_backend_cups.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int send_printer_added(void *_dialog_name, unsigned flags, cups_dest_t *dest);
2323
void connect_to_signals();
2424

2525
BackendObj *b;
26+
GMainLoop *loop;
2627

2728
void update_printer_lists()
2829
{
@@ -130,7 +131,7 @@ int main()
130131
G_CALLBACK(on_printer_added), NULL);
131132
}
132133

133-
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
134+
loop = g_main_loop_new(NULL, FALSE);
134135
g_main_loop_run(loop);
135136

136137
/* Main loop exited */
@@ -342,7 +343,7 @@ int send_printer_added(void *_dialog_name, unsigned flags, cups_dest_t *dest)
342343
return 1; //continue enumeration
343344
}
344345

345-
static void on_handle_do_listing(PrintBackend *interface,
346+
static gboolean on_handle_do_listing(PrintBackend *interface,
346347
GDBusMethodInvocation *invocation,
347348
gboolean is_listed,
348349
gpointer not_used)
@@ -352,19 +353,24 @@ static void on_handle_do_listing(PrintBackend *interface,
352353
const char *dialog_name = g_dbus_method_invocation_get_sender(invocation);
353354
Dialog *d = find_dialog(b, dialog_name);
354355
if (d && d->keep_alive)
355-
return;
356+
goto out;
356357

357358
set_dialog_cancel(b, dialog_name);
358359
remove_frontend(b, dialog_name);
359360
if (no_frontends(b))
360361
{
362+
// FIXME: this is racy against method calls already in-flight from dbus
361363
g_message("No frontends connected .. exiting backend.\n");
362-
exit(EXIT_SUCCESS);
364+
g_idle_add_once((GSourceOnceFunc)g_main_loop_quit, loop);
363365
}
364366
}
367+
368+
out:
369+
print_backend_complete_do_listing(interface, invocation);
370+
return TRUE;
365371
}
366372

367-
static void on_handle_show_remote_printers(PrintBackend *interface,
373+
static gboolean on_handle_show_remote_printers(PrintBackend *interface,
368374
GDBusMethodInvocation *invocation,
369375
gboolean is_visible,
370376
gpointer not_used)
@@ -386,10 +392,12 @@ static void on_handle_show_remote_printers(PrintBackend *interface,
386392
refresh_printer_list(b, dialog_name);
387393
}
388394
}
395+
print_backend_complete_show_remote_printers(interface, invocation);
396+
return TRUE;
389397
}
390398

391399

392-
static void on_handle_show_temporary_printers(PrintBackend *interface,
400+
static gboolean on_handle_show_temporary_printers(PrintBackend *interface,
393401
GDBusMethodInvocation *invocation,
394402
gboolean is_visible,
395403
gpointer not_used)
@@ -411,6 +419,8 @@ static void on_handle_show_temporary_printers(PrintBackend *interface,
411419
refresh_printer_list(b, dialog_name);
412420
}
413421
}
422+
print_backend_complete_show_temporary_printers(interface, invocation);
423+
return TRUE;
414424
}
415425

416426
static gboolean on_handle_is_accepting_jobs(PrintBackend *interface,

0 commit comments

Comments
 (0)