int XCloseDisplay ( register Display *dpy) { register _XExtension *ext; register int i; if (!(dpy->flags & XlibDisplayClosing)) { dpy->flags |= XlibDisplayClosing; for (i = 0; i < dpy->nscreens; i++) { register Screen *sp = &dpy->screens[i]; XFreeGC (dpy, sp->default_gc); } if (dpy->cursor_font != None) { XUnloadFont (dpy, dpy->cursor_font); } XSync(dpy, 1); /* throw away pending events, catch errors */ /* call out to any extensions interested */ for (ext = dpy->ext_procs; ext; ext = ext->next) { if (ext->close_display) (*ext->close_display)(dpy, &ext->codes); } /* if the closes generated more protocol, sync them up */ if (dpy->request != dpy->last_request_read) XSync(dpy, 1); } _XDisconnectDisplay(dpy->trans_conn); _XFreeDisplayStructure (dpy); return 0; }
static Boolean display_exists_p (int number) { char buf[64]; void *conn; char *fullname = NULL; int idisplay, iscreen; char *conn_auth_name, *conn_auth_data; int conn_auth_namelen, conn_auth_datalen; #ifdef USE_XTRANS_INTERNALS extern void *_X11TransConnectDisplay (); extern void _XDisconnectDisplay (); #endif /* Since connecting to the display waits for a few seconds if the display doesn't exist, check for trivial non-existence - if the socket in /tmp exists or not.. (note: if the socket exists, the server may still not, so we need to try to connect in that case..) */ sprintf (buf, "/tmp/.X11-unix/X%d", number); if (access (buf, F_OK) != 0) return FALSE; #ifdef USE_XTRANS_INTERNALS /* This is a private function that we shouldn't really be calling, but it's the best way to see if the server exists (without needing to hold the necessary authentication to use it) */ sprintf (buf, ":%d", number); conn = _X11TransConnectDisplay (buf, &fullname, &idisplay, &iscreen, &conn_auth_name, &conn_auth_namelen, &conn_auth_data, &conn_auth_datalen); if (conn == NULL) return FALSE; _XDisconnectDisplay (conn); #endif return TRUE; }