signals and clean exit

Joël Riou joel.riou at greement.salle-s.org
Wed Feb 2 23:31:21 CET 2005


Le mercredi  2 février 2005,  Marc A. Lehmann  a écrit :
> It shouldn't handle SIGQUIT (which is a debugging help), but it should
> indeed treat SIGINT similarly to SIGTERM (and probably will do so in the
> next release).

Thanks for implementing its so quickly!

> > server), the Xlib launches some IOErrorhandler which seems to call exit()
> 
> I don't think it's really worth it (and am too lazy to implement it), but
> I woudn'T suppose a clean patch that implements that.

Actually, many people I know (including myself) log out by
Control-Meta-Backspace... Here is a tiny patch that implements it, I hope 
that it is clean enough:

Index: src/main.C
===================================================================
RCS file: /schmorpforge/rxvt-unicode/src/main.C,v
retrieving revision 1.131
diff -u -r1.131 main.C
--- src/main.C	2 Feb 2005 08:09:23 -0000	1.131
+++ src/main.C	2 Feb 2005 22:21:41 -0000
@@ -435,7 +435,7 @@
 
   old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
   // TODO: handle this with exceptions and tolerate the memory loss
-  //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
+  XSetIOErrorHandler (rxvt_xioerror_handler);
 }
 
 /* ------------------------------------------------------------------------- *
@@ -502,6 +502,24 @@
   return 0;
 }
 
+/*
+ * This function is called by the Xlib when a fatal I/O error occurs.
+ * If we do not exit(), the Xlib will do it anyway, so that we need
+ * to clean up utmp entries before.
+ */
+/* INTPROTO */
+int
+rxvt_xioerror_handler (Display *display)
+{
+#ifdef UTMP_SUPPORT
+  for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
+    (*t)->privileged_utmp (RESTORE);
+#endif
+  rxvt_fatal ("The connection to the X Server %s was lost. "
+          "Exiting.\n", DisplayString(display));
+  exit(EXIT_FAILURE);
+}
+
 /* ------------------------------------------------------------------------- *
  *                         MEMORY ALLOCATION WRAPPERS                        *
  * ------------------------------------------------------------------------- */





More information about the rxvt-unicode mailing list