[PATCH 4/6] Factor out AddSelection and export it

Daniel Stone daniel at fooishbar.org
Tue Nov 6 22:58:21 PST 2012


From: Kristian Høgsberg <krh at redhat.com>

Useful for XWayland and other hosted compositors.

Signed-off-by: Kristian Høgsberg <krh at redhat.com>
---
 dix/selection.c     |   44 ++++++++++++++++++++++++++++----------------
 include/selection.h |    3 +++
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/dix/selection.c b/dix/selection.c
index e905b1e..fca89ee 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -86,6 +86,33 @@ dixLookupSelection(Selection ** result, Atom selectionName,
     return rc;
 }
 
+int
+AddSelection(Selection ** result, Atom name, ClientPtr client)
+{
+    Selection *pSel;
+    int rc;
+
+    pSel = dixAllocateObjectWithPrivates(Selection, PRIVATE_SELECTION);
+    if (!pSel)
+        return BadAlloc;
+
+    pSel->selection = name;
+
+    /* security creation/labeling check */
+    rc = XaceHookSelectionAccess(client, &pSel,
+                                 DixCreateAccess | DixSetAttrAccess);
+    if (rc != Success) {
+        dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION);
+        return rc;
+    }
+
+    pSel->next = CurrentSelections;
+    CurrentSelections = pSel;
+    *result = pSel;
+
+    return Success;
+}
+
 void
 InitSelections(void)
 {
@@ -194,22 +221,7 @@ ProcSetSelectionOwner(ClientPtr client)
         /*
          * It doesn't exist, so add it...
          */
-        pSel = dixAllocateObjectWithPrivates(Selection, PRIVATE_SELECTION);
-        if (!pSel)
-            return BadAlloc;
-
-        pSel->selection = stuff->selection;
-
-        /* security creation/labeling check */
-        rc = XaceHookSelectionAccess(client, &pSel,
-                                     DixCreateAccess | DixSetAttrAccess);
-        if (rc != Success) {
-            free(pSel);
-            return rc;
-        }
-
-        pSel->next = CurrentSelections;
-        CurrentSelections = pSel;
+        rc = AddSelection(&pSel, stuff->selection, client);
     }
     else
         return rc;
diff --git a/include/selection.h b/include/selection.h
index 37e4f5e..2e11c4f 100644
--- a/include/selection.h
+++ b/include/selection.h
@@ -71,6 +71,9 @@ typedef struct _Selection {
 extern _X_EXPORT int dixLookupSelection(Selection ** result, Atom name,
                                         ClientPtr client, Mask access_mode);
 
+extern _X_EXPORT int AddSelection(Selection ** result,
+                                  Atom name, ClientPtr client);
+
 extern _X_EXPORT Selection *CurrentSelections;
 
 extern _X_EXPORT CallbackListPtr SelectionCallback;
-- 
1.7.10.4



More information about the xorg-devel mailing list