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

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Fri Oct 31 06:12:08 PDT 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     |  5 ++++-
 src/driver.c     | 32 ++++++++++++++++++++++----------
 src/xlibclient.c | 15 ++++++++++++++-
 4 files changed, 43 insertions(+), 16 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..46f372b 100644
--- a/src/client.h
+++ b/src/client.h
@@ -39,12 +39,15 @@
 struct NestedClientPrivate;
 typedef struct NestedClientPrivate *NestedClientPrivatePtr;
 
-Bool NestedClientCheckDisplay(char *displayName);
+Bool NestedClientCheckDisplay(int   scrnIndex,
+                              char *displayName,
+                              char *xauthFile);
 
 Bool NestedClientValidDepth(int depth);
 
 NestedClientPrivatePtr NestedClientCreateScreen(int    scrnIndex,
                                                 char  *displayName,
+                                                char  *xauthFile,
                                                 int    width,
                                                 int    height,
                                                 int    originX,
diff --git a/src/driver.c b/src/driver.c
index b573a97..a91954f 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 = {
@@ -170,6 +172,7 @@ _X_EXPORT XF86ModuleData nestedModuleData = {
 /* These stuff should be valid to all server generations */
 typedef struct NestedPrivate {
     char                        *displayName;
+    char                        *xauthFile;
     int                          originX;
     int                          originY;
     NestedClientPrivatePtr       clientData;
@@ -325,6 +328,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 +358,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 +377,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;
     }
 
@@ -573,6 +584,7 @@ static Bool NestedScreenInit(SCREEN_INIT_ARGS_DECL)
 
     pNested->clientData = NestedClientCreateScreen(pScrn->scrnIndex,
                                                    pNested->displayName,
+                                                   pNested->xauthFile,
                                                    pScrn->virtualX,
                                                    pScrn->virtualY,
                                                    pNested->originX,
diff --git a/src/xlibclient.c b/src/xlibclient.c
index 0f1034a..3a87c96 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,
+                         char *displayName,
+                         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;
@@ -167,6 +174,7 @@ NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int
 NestedClientPrivatePtr
 NestedClientCreateScreen(int scrnIndex,
                          char *displayName,
+                         char *xauthFile,
                          int width,
                          int height,
                          int originX,
@@ -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;
-- 
1.8.4.5



More information about the xorg-devel mailing list