Correctly detect if DISPLAY env var is set but specified display is not existing or xserver not running, and start in text mode
This commit is contained in:
parent
163eaea672
commit
36f1285303
11
src/main.c
11
src/main.c
|
|
@ -71,6 +71,7 @@ static void child_handler(int signum)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
Display *display;
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGSEGV, sig_handler);
|
||||
signal(SIGILL, sig_handler);
|
||||
|
|
@ -82,6 +83,16 @@ int main(int argc, char **argv)
|
|||
/* 20181013 check for empty or non existing DISPLAY *before* calling Tk_Main or Tcl_Main */
|
||||
#ifdef __unix__
|
||||
if(!getenv("DISPLAY") || !getenv("DISPLAY")[0]) has_x=0;
|
||||
else {
|
||||
display = XOpenDisplay(NULL);
|
||||
if(!display) {
|
||||
has_x=0;
|
||||
fprintf(errfp, "\n X server connection failed, although DISPLAY shell variable is set.\n"
|
||||
" A possible reason is that the X server is not running or DISPLAY shell variable\n"
|
||||
" is incorrectly set.\n"
|
||||
" Starting Xschem in text only mode.\n\n");
|
||||
} else XCloseDisplay(display);
|
||||
}
|
||||
#endif
|
||||
argc = process_options(argc, argv);
|
||||
my_strdup(_ALLOC_ID_, &xschem_executable, argv[0]);
|
||||
|
|
|
|||
|
|
@ -2151,10 +2151,10 @@ int Tcl_AppInit(Tcl_Interp *inter)
|
|||
my_strncpy(home_dir, home_buff, S(home_dir));
|
||||
#endif
|
||||
/* set error and exit handlers */
|
||||
XSetErrorHandler(err);
|
||||
if(!interp) interp=inter;
|
||||
Tcl_Init(interp);
|
||||
if(has_x) {
|
||||
XSetErrorHandler(err);
|
||||
Tk_Init(interp);
|
||||
tclsetvar("has_x","1");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue