[PATCH xf86-video-nested v2 2/5] Add support for option "Xauthority" in xorg.conf

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Thu Nov 6 09:18:11 PST 2014


With this patch, one can set explicitely an authorization file for
"nested" video driver in xorg.conf section "Device". Example:

Section "Device"
    Identifier "nested_device"
    Driver "nested"
    Option "Display" ":0"
    Option "Xauthority" "/var/run/Xauthority/:0"
EndSection

If no such an option is defined in xorg.conf, the value defined
in environment variable XAUTHORITY will be used, as before.

Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
---
 README           |  7 +++----
 src/client.h     | 27 +++++++++++++++------------
 src/driver.c     | 40 +++++++++++++++++++++++++++-------------
 src/xlibclient.c | 25 +++++++++++++++++++------
 4 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/README b/README
index 12a2fc6..5b2fc97 100644
--- a/README
+++ b/README
@@ -13,20 +13,20 @@ My xorg.conf:
 Section "ServerFlags"
     Option "AutoEnableDevices" "false"
     Option "AutoAddDevices" "false"
-    Option "AllowEmptyInput" "true"
 EndSection
 
 Section "Device"
     Identifier "device1"
     Driver "nested"
-    Option "Display" ":0"     # you can omit this
+    Option "Display" ":0"                          # you can omit this
+    Option "Xauthority" "/var/run/Xauthority/:0"   # you can omit this
 EndSection
 
 Section "Screen"
     Identifier "screen1"
     Device "device1"
     DefaultDepth 24
-    Option "Origin" "100 100" # you can omit this
+    Option "Origin" "100 100"                      # you can omit this
     SubSection "Display"
         Depth 24
         Modes "640x480"
@@ -49,7 +49,6 @@ xorg.conf with 2 screens and a mouse:
 Section "ServerFlags"
     Option "AutoEnableDevices" "false"
     Option "AutoAddDevices" "false"
-    Option "AllowEmptyInput" "true"
 EndSection
 
 Section "Device"
diff --git a/src/client.h b/src/client.h
index c6f88af..ea2c8de 100644
--- a/src/client.h
+++ b/src/client.h
@@ -39,21 +39,24 @@
 struct NestedClientPrivate;
 typedef struct NestedClientPrivate *NestedClientPrivatePtr;
 
-Bool NestedClientCheckDisplay(char *displayName);
+Bool NestedClientCheckDisplay(int         scrnIndex,
+                              const char *displayName,
+                              const char *xauthFile);
 
 Bool NestedClientValidDepth(int depth);
 
-NestedClientPrivatePtr NestedClientCreateScreen(int    scrnIndex,
-                                                char  *displayName,
-                                                int    width,
-                                                int    height,
-                                                int    originX,
-                                                int    originY,
-                                                int    depth,
-                                                int    bitsPerPixel,
-                                                Pixel *retRedMask,
-                                                Pixel *retGreenMask,
-                                                Pixel *retBlueMask);
+NestedClientPrivatePtr NestedClientCreateScreen(int          scrnIndex,
+                                                const char  *displayName,
+                                                const char  *xauthFile,
+                                                unsigned int width,
+                                                unsigned int height,
+                                                int          originX,
+                                                int          originY,
+                                                unsigned int depth,
+                                                unsigned int bitsPerPixel,
+                                                Pixel       *retRedMask,
+                                                Pixel       *retGreenMask,
+                                                Pixel       *retBlueMask);
 
 char *NestedClientGetFrameBuffer(NestedClientPrivatePtr pPriv);
 
diff --git a/src/driver.c b/src/driver.c
index b573a97..d6208cc 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -100,6 +100,7 @@ void NestedPrintMode(ScrnInfoPtr p, DisplayModePtr m);
 
 typedef enum {
     OPTION_DISPLAY,
+    OPTION_XAUTHORITY,
     OPTION_ORIGIN
 } NestedOpts;
 
@@ -116,9 +117,10 @@ static SymTabRec NestedChipsets[] = {
  * port NestedClient to something that's not Xlib/Xcb we might need to add some
  * custom options */
 static OptionInfoRec NestedOptions[] = {
-    { OPTION_DISPLAY, "Display", OPTV_STRING, {0}, FALSE },
-    { OPTION_ORIGIN,  "Origin",  OPTV_STRING, {0}, FALSE },
-    { -1,             NULL,      OPTV_NONE,   {0}, FALSE }
+    { OPTION_DISPLAY,    "Display",    OPTV_STRING, {0}, FALSE },
+    { OPTION_XAUTHORITY, "Xauthority", OPTV_STRING, {0}, FALSE },
+    { OPTION_ORIGIN,     "Origin",     OPTV_STRING, {0}, FALSE },
+    { -1,                NULL,         OPTV_NONE,   {0}, FALSE }
 };
 
 _X_EXPORT DriverRec NESTED = {
@@ -169,7 +171,8 @@ _X_EXPORT XF86ModuleData nestedModuleData = {
 
 /* These stuff should be valid to all server generations */
 typedef struct NestedPrivate {
-    char                        *displayName;
+    const char                  *displayName;
+    const char                  *xauthFile;
     int                          originX;
     int                          originY;
     NestedClientPrivatePtr       clientData;
@@ -238,6 +241,7 @@ NestedProbe(DriverPtr drv, int flags) {
             pScrn = NULL;
             entityIndex = xf86ClaimNoSlot(drv, NESTED_CHIP, devSections[i],
                                           TRUE);
+            free(devSections);
             pScrn = xf86AllocateScreen(drv, 0);
             if (pScrn) {
                 xf86AddEntityToScreen(pScrn, entityIndex);
@@ -312,7 +316,7 @@ static void NestedFreePrivate(ScrnInfoPtr pScrn) {
 /* Data from here is valid to all server generations */
 static Bool NestedPreInit(ScrnInfoPtr pScrn, int flags) {
     NestedPrivatePtr pNested;
-    char *originString = NULL;
+    const char *originString = NULL;
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NestedPreInit\n");
 
@@ -325,6 +329,10 @@ static Bool NestedPreInit(ScrnInfoPtr pScrn, int flags) {
     }
 
     pNested = PNESTED(pScrn);
+    pNested->displayName = NULL;
+    pNested->xauthFile = NULL;
+    pNested->originX = 0;
+    pNested->originY = 0;
 
     if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb | Support32bppFb))
         return FALSE;
@@ -351,8 +359,13 @@ static Bool NestedPreInit(ScrnInfoPtr pScrn, int flags) {
                                                    OPTION_DISPLAY);
         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using display \"%s\"\n",
                    pNested->displayName);
-    } else {
-        pNested->displayName = NULL;
+    }
+
+    if (xf86IsOptionSet(NestedOptions, OPTION_XAUTHORITY)) {
+        pNested->xauthFile = xf86GetOptValString(NestedOptions,
+                                                 OPTION_XAUTHORITY);
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using authorization file \"%s\"\n",
+                   pNested->xauthFile);
     }
 
     if (xf86IsOptionSet(NestedOptions, OPTION_ORIGIN)) {
@@ -365,16 +378,15 @@ static Bool NestedPreInit(ScrnInfoPtr pScrn, int flags) {
         }
         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using origin x:%d y:%d\n",
                    pNested->originX, pNested->originY);
-    } else {
-        pNested->originX = 0;
-        pNested->originY = 0;
     }
 
     xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-    if (!NestedClientCheckDisplay(pNested->displayName)) {
+    if (!NestedClientCheckDisplay(pScrn->scrnIndex,
+                                  pNested->displayName,
+                                  pNested->xauthFile)) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Can't open display: %s\n",
-                   pNested->displayName);
+                   pNested->displayName ? pNested->displayName : getenv("DISPLAY"));
         return FALSE;
     }
 
@@ -513,7 +525,7 @@ NestedAddMode(ScrnInfoPtr pScrn, int width, int height) {
 
     len = strlen(nameBuf);
     mode->name = XNFalloc(len+1);
-    strcpy(mode->name, nameBuf);
+    strcpy((char *)mode->name, nameBuf);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Adding mode %s\n", mode->name);
 
@@ -573,6 +585,7 @@ static Bool NestedScreenInit(SCREEN_INIT_ARGS_DECL)
 
     pNested->clientData = NestedClientCreateScreen(pScrn->scrnIndex,
                                                    pNested->displayName,
+                                                   pNested->xauthFile,
                                                    pScrn->virtualX,
                                                    pScrn->virtualY,
                                                    pNested->originX,
@@ -706,6 +719,7 @@ static void NestedLeaveVT(VT_FUNC_ARGS_DECL) {
 static void NestedFreeScreen(FREE_SCREEN_ARGS_DECL) {
     SCRN_INFO_PTR(arg);
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NestedFreeScreen\n");
+    NestedFreePrivate(pScrn);
 }
 
 static ModeStatus NestedValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
diff --git a/src/xlibclient.c b/src/xlibclient.c
index 0f1034a..e8f3281 100644
--- a/src/xlibclient.c
+++ b/src/xlibclient.c
@@ -85,9 +85,16 @@ struct NestedClientPrivate {
 
 /* Checks if a display is open */
 Bool
-NestedClientCheckDisplay(char *displayName) {
+NestedClientCheckDisplay(int scrnIndex,
+                         const char *displayName,
+                         const char *xauthFile) {
     Display *d;
 
+    /* Needed until we can pass authorization file
+     * directly to XOpenDisplay() */
+    if (xauthFile != NULL)
+        setenv("XAUTHORITY", xauthFile, 1);
+
     d = XOpenDisplay(displayName);
     if (!d) {
         return FALSE;
@@ -166,13 +173,14 @@ NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int
 
 NestedClientPrivatePtr
 NestedClientCreateScreen(int scrnIndex,
-                         char *displayName,
-                         int width,
-                         int height,
+                         const char *displayName,
+                         const char *xauthFile,
+                         unsigned int width,
+                         unsigned int height,
                          int originX,
                          int originY,
-                         int depth,
-                         int bitsPerPixel,
+                         unsigned int depth,
+                         unsigned int bitsPerPixel,
                          Pixel *retRedMask,
                          Pixel *retGreenMask,
                          Pixel *retBlueMask) {
@@ -184,6 +192,11 @@ NestedClientCreateScreen(int scrnIndex,
     pPriv = malloc(sizeof(struct NestedClientPrivate));
     pPriv->scrnIndex = scrnIndex;
 
+    /* Needed until we can pass authorization file
+     * directly to XOpenDisplay() */
+    if (xauthFile != NULL)
+        setenv("XAUTHORITY", xauthFile, 1);
+
     pPriv->display = XOpenDisplay(displayName);
     if (!pPriv->display)
         return NULL;
-- 
2.1.2



More information about the xorg-devel mailing list