+#ifdef HAVE_SN
+static int error_trap_depth = 0;
+
+static void
+error_trap_push (SnDisplay *display,
+ Display *xdisplay)
+{
+ ++error_trap_depth;
+}
+
+static void
+error_trap_pop (SnDisplay *display,
+ Display *xdisplay)
+{
+ if (error_trap_depth == 0)
+ {
+ fprintf(stderr, "Error trap underflow!\n");
+ return;
+ }
+
+ XSync(xdisplay, False); /* get all errors out of the queue */
+ --error_trap_depth;
+}
+
+static void sigchld_handler(int sig) {
+ // Wait for all dead processes
+ pid_t pid;
+ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
+ SnLauncherContext *ctx;
+ ctx = (SnLauncherContext *) g_tree_lookup (server.pids, GINT_TO_POINTER (pid));
+ if (ctx == NULL) {
+ fprintf(stderr, "Unknown child %d terminated!\n", pid);
+ }
+ else {
+ g_tree_remove (server.pids, GINT_TO_POINTER (pid));
+ sn_launcher_context_complete (ctx);
+ sn_launcher_context_unref (ctx);
+ }
+ }
+}
+
+static gint cmp_ptr(gconstpointer a, gconstpointer b) {
+ if (a < b)
+ return -1;
+ else if (a == b)
+ return 0;
+ else
+ return 1;
+}
+
+#endif // HAVE_SN
+