[PATCH xinit] xcb port of xinit. Unsure of correctness in removing error handling in shutdown

Demur Rumed gunkmute at gmail.com
Thu Mar 10 14:59:49 PST 2011


Signed-off-by: Demur Rumed <gunkmute at gmail.com>
---
 configure.ac |    6 ++--
 xinit.c      |   95 +++++++++++++++++++++++++++-------------------------------
 2 files changed, 47 insertions(+), 54 deletions(-)

diff --git a/configure.ac b/configure.ac
index 67214cb..2a9d5da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 dnl  Copyright 2005 Red Hat, Inc.
-dnl 
+dnl
 dnl  Permission to use, copy, modify, distribute, and sell this software and its
 dnl  documentation for any purpose is hereby granted without fee, provided that
 dnl  the above copyright notice appear in all copies and that both that
@@ -9,7 +9,7 @@ dnl  advertising or publicity pertaining to distribution of the software without
 dnl  specific, written prior permission.  Red Hat makes no
 dnl  representations about the suitability of this software for any purpose.  It
 dnl  is provided "as is" without express or implied warranty.
-dnl 
+dnl
 dnl  RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 dnl  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 dnl  EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
@@ -134,7 +134,7 @@ AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
 AM_CONDITIONAL(TIGER_LAUNCHD, [test "x$TIGER_LAUNCHD" = "xyes"])
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(XINIT, x11)
+PKG_CHECK_MODULES(XINIT, xcb)
 
 case $host_os in
     *bsd*)
diff --git a/xinit.c b/xinit.c
index 42ff008..8e50d78 100644
--- a/xinit.c
+++ b/xinit.c
@@ -28,9 +28,8 @@ in this Software without prior written authorization from The Open Group.
 # include "config.h"
 #endif
 
-#include <X11/Xlib.h>
+#include <xcb/xcb.h>
 #include <X11/Xos.h>
-#include <X11/Xatom.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdint.h>
@@ -38,7 +37,6 @@ in this Software without prior written authorization from The Open Group.
 #include <signal.h>
 #include <sys/wait.h>
 #include <errno.h>
-#include <setjmp.h>
 #include <stdarg.h>
 
 #ifdef __APPLE__
@@ -101,18 +99,17 @@ static char **server = serverargv + 2;        /* make sure room for sh .xserverr
 static char **client = clientargv + 2;        /* make sure room for sh .xinitrc args */
 static char *displayNum = NULL;
 static char *program = NULL;
-static Display *xd = NULL;            /* server connection */
+static xcb_connection_t *xd = NULL;            /* server connection */
 int status;
 int serverpid = -1;
 int clientpid = -1;
 volatile int gotSignal = 0;
 
 static void Execute(char **vec);
-static Bool waitforserver(void);
-static Bool processTimeout(int timeout, char *string);
+static int waitforserver(void);
+static int processTimeout(int timeout, char *string);
 static int startServer(char *server[]);
 static int startClient(char *client[]);
-static int ignorexio(Display *dpy);
 static void shutdown(void);
 static void set_environment(void);
 
@@ -134,13 +131,13 @@ sigIgnore(int sig)
 }
 
 static void
-Execute(char **vec)		/* has room from up above */
+Execute(char **vec)        /* has room from up above */
 {
     execvp(vec[0], vec);
     if (access(vec[0], R_OK) == 0) {
-	vec--;				/* back it up to stuff shell in */
-	vec[0] = SHELL;
-	execvp(vec[0], vec);
+    vec--;                /* back it up to stuff shell in */
+    vec[0] = SHELL;
+    execvp(vec[0], vec);
     }
     return;
 }
@@ -215,12 +212,12 @@ main(int argc, char *argv[])
      */
     if (!client_given) {
         char *cp;
-        Bool required = False;
+        int required = FALSE;
 
         xinitrcbuf[0] = '\0';
         if ((cp = getenv("XINITRC")) != NULL) {
             snprintf(xinitrcbuf, sizeof(xinitrcbuf), "%s", cp);
-            required = True;
+            required = TRUE;
         } else if ((cp = getenv("HOME")) != NULL) {
             snprintf(xinitrcbuf, sizeof(xinitrcbuf),
                      "%s/%s", cp, XINITRC);
@@ -241,12 +238,12 @@ main(int argc, char *argv[])
      */
     if (!server_given) {
         char *cp;
-        Bool required = False;
+        int required = FALSE;
 
         xserverrcbuf[0] = '\0';
         if ((cp = getenv("XSERVERRC")) != NULL) {
             snprintf(xserverrcbuf, sizeof(xserverrcbuf), "%s", cp);
-            required = True;
+            required = TRUE;
         } else if ((cp = getenv("HOME")) != NULL) {
             snprintf(xserverrcbuf, sizeof(xserverrcbuf),
                      "%s/%s", cp, XSERVERRC);
@@ -331,7 +328,7 @@ main(int argc, char *argv[])
 /*
  *    waitforserver - wait for X server to start up
  */
-static Bool
+static int
 waitforserver(void)
 {
     int    ncycles     = 120;        /* # of cycles to wait */
@@ -348,7 +345,7 @@ waitforserver(void)
 #endif
 
     for (cycles = 0; cycles < ncycles; cycles++) {
-        if ((xd = XOpenDisplay(displayNum))) {
+        if ((xd = xcb_connect(displayNum, 0))) {
             return(TRUE);
         }
         else {
@@ -365,7 +362,7 @@ waitforserver(void)
 /*
  * return TRUE if we timeout waiting for pid to exit, FALSE otherwise.
  */
-static Bool
+static int
 processTimeout(int timeout, char *string)
 {
     int    i = 0, pidfound = -1;
@@ -479,60 +476,68 @@ static void
 setWindowPath(void)
 {
     /* setting WINDOWPATH for clients */
-    Atom prop;
-    Atom actualtype;
+    xcb_get_property_reply_t *proprep;
+    xcb_intern_atom_reply_t *atomrep;
+    xcb_atom_t prop;
+    xcb_atom_t actualtype;
     int actualformat;
     unsigned long nitems;
     unsigned long bytes_after;
-    unsigned char *buf;
+    void *buf;
     const char *windowpath;
     char *newwindowpath;
     unsigned long num;
     char nums[10];
     int numn;
     size_t len;
-    prop = XInternAtom(xd, "XFree86_VT", False);
-    if (prop == None) {
+    atomrep = xcb_intern_atom_reply(xd, xcb_intern_atom_unchecked(xd, FALSE, 10, "XFree86_VT"), NULL);
+    if (!atomrep) {
         Errorx("Unable to intern XFree86_VT atom");
         return;
     }
-    if (XGetWindowProperty(xd, DefaultRootWindow(xd), prop, 0, 1,
-        False, AnyPropertyType, &actualtype, &actualformat,
-        &nitems, &bytes_after, &buf)) {
+    prop = atomrep->atom;
+    free(atomrep);
+    proprep=xcb_get_property_reply(xd, xcb_get_property_unchecked(xd, FALSE, xcb_setup_roots_iterator(xcb_get_setup(xd)).data->root, prop, XCB_ATOM_ANY, 0, -1), NULL);
+    if (!proprep) {
         Errorx("No XFree86_VT property detected on X server, WINDOWPATH won't be set");
         return;
     }
-    if (nitems != 1) {
-        Errorx("XFree86_VT property unexpectedly has %lu items instead of 1", nitems);
-        XFree(buf);
+    actualformat = proprep->format;
+    actualtype = proprep->type;
+    bytes_after = proprep->bytes_after;
+    nitems = xcb_get_property_value_length(proprep);
+    if (nitems != actualformat/8) {
+        Errorx("XFree86_VT property unexpectedly has %lu items instead of 1", nitems / (actualformat/8));
+        free(proprep);
         return;
     }
+    buf = xcb_get_property_value(proprep);
     switch (actualtype) {
-    case XA_CARDINAL:
-    case XA_INTEGER:
-    case XA_WINDOW:
+    case XCB_ATOM_CARDINAL:
+    case XCB_ATOM_INTEGER:
+    case XCB_ATOM_WINDOW:
         switch (actualformat) {
         case  8:
-            num = (*(uint8_t  *)(void *)buf);
+            num = (*(uint8_t  *)buf);
             break;
         case 16:
-            num = (*(uint16_t *)(void *)buf);
+            num = (*(uint16_t *)buf);
             break;
         case 32:
-            num = (*(uint32_t *)(void *)buf);
+            num = (*(uint32_t *)buf);
             break;
         default:
             Errorx("XFree86_VT property has unexpected format %d", actualformat);
-            XFree(buf);
+            free(proprep);
             return;
         }
         break;
     default:
         Errorx("XFree86_VT property has unexpected type %lx", actualtype);
-        XFree(buf);
+        free(proprep);
         return;
     }
-    XFree(buf);
+    free(proprep);
     windowpath = getenv("WINDOWPATH");
     numn = snprintf(nums, sizeof(nums), "%lu", num);
     if (!windowpath) {
@@ -583,24 +588,12 @@ startClient(char *client[])
 
 static jmp_buf close_env;
 
-static int
-ignorexio(Display *dpy)
-{
-    Errorx("connection to X server lost");
-    longjmp(close_env, 1);
-    /*NOTREACHED*/
-    return 0;
-}
-
 static void
 shutdown(void)
 {
     /* have kept display opened, so close it now */
     if (clientpid > 0) {
-        XSetIOErrorHandler(ignorexio);
-        if (! setjmp(close_env)) {
-            XCloseDisplay(xd);
-        }
+        xcb_disconnect(xd);
 
         /* HUP all local clients to allow them to clean up */
         if (killpg(clientpid, SIGHUP) < 0 && errno != ESRCH)
-- 
1.7.4.1



More information about the xorg-devel mailing list