unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* patch to make emacs proceed if DISPLAY is unreachable
@ 2006-03-06 14:56 Vivek Dasmohapatra
  2006-03-07  7:31 ` Jan D.
  0 siblings, 1 reply; 5+ messages in thread
From: Vivek Dasmohapatra @ 2006-03-06 14:56 UTC (permalink / raw)


[-- Attachment #1: Type: TEXT/PLAIN, Size: 802 bytes --]

Hi: In the past, I've had to administer various machines with NFS mounted 
homedirs, and from time to time when su'ing I've been bitten by the fact
that altough DISPLAY was set, emacs couldn't read my .Xauthority
file (as it was on NHS). I've had a look at the code, and figure oud what's
going on, (I think), and put together this patch to make emacs proceed
as if -nw had been supplied if DISPLAY is unreachable for some reason.

This behaviour does not apply to displays explicitly provided by -d
on the command line, only to implicit DISPLAY settings.

I find I prefer this behaviour, so I'm submitting the patch,
hopefully the emacs team will consider either using this patch
or implementing similar behaviour themselves (I think the patch
is without side effect, but I could be wrong).

-- 
Vivek

[-- Attachment #2: Type: TEXT/PLAIN, Size: 2195 bytes --]

diff -urbB emacs21-21.4a/src/emacs.c emacs21-21.4a.displaylenience/src/emacs.c
--- emacs21-21.4a/src/emacs.c	2002-08-29 20:27:07.000000000 +0100
+++ emacs21-21.4a.displaylenience/src/emacs.c	2006-03-06 00:05:23.000000000 +0000
@@ -45,6 +45,10 @@
 #include "intervals.h"
 #include "buffer.h"
 
+#ifdef HAVE_X_WINDOWS
+#include "xterm.h"
+#endif
+
 #include "systty.h"
 #include "blockinput.h"
 #include "syssignal.h"
@@ -1268,6 +1272,14 @@
 
     /* Don't actually discard this arg.  */
     skip_args = count_before;
+    
+    /* Do NOT be lenient if the user explicitly asked for a named display */
+    if( display_arg != 1 )
+      if( x_display_ok(displayname) == 0 ) {
+        inhibit_window_system = 1;
+        fprintf( stderr,
+                 "DISPLAY unavailable, simulating -nw\n", displayname );
+      }
   }
 #endif
 
diff -urbB emacs21-21.4a/src/xterm.c emacs21-21.4a.displaylenience/src/xterm.c
--- emacs21-21.4a/src/xterm.c	2002-10-15 15:21:45.000000000 +0100
+++ emacs21-21.4a.displaylenience/src/xterm.c	2006-03-06 00:07:40.000000000 +0000
@@ -14156,6 +14156,24 @@
 }
 #endif
 
+int
+x_display_ok (display)
+    const char * display;
+{
+    int dpy_ok = 1;
+    Display *dpy;
+    char *display_name = display || getenv("DISPLAY");
+
+    if( !display_name ) 
+      return 0;
+
+    if( dpy = XOpenDisplay (display) )
+      XCloseDisplay( dpy );
+    else
+      dpy_ok = 0;
+    return dpy_ok;
+}
+
 struct x_display_info *
 x_term_init (display_name, xrm_option, resource_name)
      Lisp_Object display_name;
diff -urbB emacs21-21.4a/src/xterm.h emacs21-21.4a.displaylenience/src/xterm.h
--- emacs21-21.4a/src/xterm.h	2002-02-22 10:41:44.000000000 +0000
+++ emacs21-21.4a.displaylenience/src/xterm.h	2006-03-06 00:07:40.000000000 +0000
@@ -378,6 +378,7 @@
 extern struct x_display_info *x_display_info_for_name P_ ((Lisp_Object));
 
 extern struct x_display_info *x_term_init P_ ((Lisp_Object, char *, char *));
+extern int x_display_ok  P_ ((const char *));
 
 extern Lisp_Object x_list_fonts P_ ((struct frame *, Lisp_Object, int, int));
 extern void select_visual P_ ((struct x_display_info *));

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-03-07 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-06 14:56 patch to make emacs proceed if DISPLAY is unreachable Vivek Dasmohapatra
2006-03-07  7:31 ` Jan D.
2006-03-07 16:15   ` Giorgos Keramidas
2006-03-07 16:30     ` Vivek Dasmohapatra
2006-03-07 16:44       ` Giorgos Keramidas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).