unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vivek Dasmohapatra <vivek@etla.org>
Subject: patch to make emacs proceed if DISPLAY is unreachable
Date: Mon, 6 Mar 2006 14:56:34 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.62.0603061451160.4724@pike.pepperfish.net> (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

             reply	other threads:[~2006-03-06 14:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-06 14:56 Vivek Dasmohapatra [this message]
2006-03-07  7:31 ` patch to make emacs proceed if DISPLAY is unreachable Jan D.
2006-03-07 16:15   ` Giorgos Keramidas
2006-03-07 16:30     ` Vivek Dasmohapatra
2006-03-07 16:44       ` Giorgos Keramidas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.62.0603061451160.4724@pike.pepperfish.net \
    --to=vivek@etla.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).