[PATCH] Build required portions of registry.c automatically [v2]

Keith Packard keithp at keithp.com
Mon Sep 15 09:18:13 PDT 2014


Instead of making the inclusion of the registry code a global
conditional, split the registry into two pieces; the bits required by
the X-Resource extension (the resource names) and the bits required by
the XCSECURITY extension (the protocol names). Build each set of code
if the related extension is being built.

v2: Check for both XCSECURITY and XSELINUX.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 configure.ac       |  6 ----
 dix/extension.c    |  2 ++
 dix/registry.c     | 90 +++++++++++++++++++++++++++++++++---------------------
 dix/resource.c     |  2 ++
 include/registry.h | 39 +++++++++--------------
 5 files changed, 74 insertions(+), 65 deletions(-)

diff --git a/configure.ac b/configure.ac
index cba7d24..ce76baa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,7 +587,6 @@ AC_ARG_WITH(khronos-spec-dir, AS_HELP_STRING([--with-khronos-spec-dir=PATH], [Pa
 				[KHRONOS_SPEC_DIR=auto])
 
 dnl Extensions.
-AC_ARG_ENABLE(registry,       AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes])
 AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes])
 AC_ARG_ENABLE(mitshm,         AS_HELP_STRING([--disable-mitshm], [Build SHM extension (default: auto)]), [MITSHM=$enableval], [MITSHM=auto])
 AC_ARG_ENABLE(xres,           AS_HELP_STRING([--disable-xres], [Build XRes extension (default: enabled)]), [RES=$enableval], [RES=yes])
@@ -1038,11 +1037,6 @@ if test "x$XVMC" = xyes; then
 	AC_DEFINE(XvMCExtension, 1, [Build XvMC extension])
 fi
 
-AM_CONDITIONAL(XREGISTRY, [test "x$XREGISTRY" = xyes])
-if test "x$XREGISTRY" = xyes; then
-	AC_DEFINE(XREGISTRY, 1, [Build registry module])
-fi
-
 AM_CONDITIONAL(COMPOSITE, [test "x$COMPOSITE" = xyes])
 if test "x$COMPOSITE" = xyes; then
 	AC_DEFINE(COMPOSITE, 1, [Support Composite Extension])
diff --git a/dix/extension.c b/dix/extension.c
index ede4bf5..e43291e 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -139,7 +139,9 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
         ext->errorLast = 0;
     }
 
+#ifdef X_REGISTRY_REQUEST
     RegisterExtensionNames(ext);
+#endif
     return ext;
 }
 
diff --git a/dix/registry.c b/dix/registry.c
index 8b76d56..84d48b4 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -21,8 +21,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <dix-config.h>
 #endif
 
-#ifdef XREGISTRY
-
 #include <stdlib.h>
 #include <string.h>
 #include <X11/X.h>
@@ -31,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "registry.h"
 
 #define BASE_SIZE 16
+
+#ifdef X_REGISTRY_REQUEST
 #define CORE "X11"
 #define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
 
@@ -42,9 +42,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 static FILE *fh;
 
 static char ***requests, **events, **errors;
+static unsigned nmajor, *nminor, nevent, nerror;
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
 static const char **resources;
-static unsigned nmajor, *nminor, nevent, nerror, nresource;
+static unsigned nresource;
+#endif
 
+#if defined(X_REGISTRY_RESOURCE) || defined(X_REGISTRY_REQUEST)
 /*
  * File parsing routines
  */
@@ -72,7 +78,12 @@ double_size(void *p, unsigned n, unsigned size)
     memset(*ptr + s, 0, f - s);
     return TRUE;
 }
+#endif
 
+#ifdef X_REGISTRY_REQUEST
+/*
+ * Request/event/error registry functions
+ */
 static void
 RegisterRequestName(unsigned major, unsigned minor, char *name)
 {
@@ -197,28 +208,6 @@ RegisterExtensionNames(ExtensionEntry * extEntry)
     }
 }
 
-/*
- * Registration functions
- */
-
-void
-RegisterResourceName(RESTYPE resource, const char *name)
-{
-    resource &= TypeMask;
-
-    while (resource >= nresource) {
-        if (!double_size(&resources, nresource, sizeof(char *)))
-            return;
-        nresource = nresource ? nresource * 2 : BASE_SIZE;
-    }
-
-    resources[resource] = name;
-}
-
-/*
- * Lookup functions
- */
-
 const char *
 LookupRequestName(int major, int minor)
 {
@@ -269,6 +258,26 @@ LookupErrorName(int error)
 
     return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
 }
+#endif /* X_REGISTRY_REQUEST */
+
+#ifdef X_REGISTRY_RESOURCE
+/*
+ * Resource registry functions
+ */
+
+void
+RegisterResourceName(RESTYPE resource, const char *name)
+{
+    resource &= TypeMask;
+
+    while (resource >= nresource) {
+        if (!double_size(&resources, nresource, sizeof(char *)))
+            return;
+        nresource = nresource ? nresource * 2 : BASE_SIZE;
+    }
+
+    resources[resource] = name;
+}
 
 const char *
 LookupResourceName(RESTYPE resource)
@@ -279,10 +288,12 @@ LookupResourceName(RESTYPE resource)
 
     return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
 }
+#endif /* X_REGISTRY_RESOURCE */
 
 void
 dixFreeRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     /* Free all memory */
     while (nmajor--) {
         while (nminor[nmajor])
@@ -299,25 +310,30 @@ dixFreeRegistry(void)
     while (nerror--)
         free(errors[nerror]);
     free(errors);
-
-    free(resources);
-
     requests = NULL;
     nminor = NULL;
     events = NULL;
     errors = NULL;
-    resources = NULL;
+    nmajor = nevent = nerror = 0;
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
+    free(resources);
 
-    nmajor = nevent = nerror = nresource = 0;
+    resources = NULL;
+    nresource = 0;
+#endif
 }
 
 void
 dixCloseRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     if (fh) {
 	fclose(fh);
         fh = NULL;
     }
+#endif
 }
 
 /*
@@ -326,16 +342,24 @@ dixCloseRegistry(void)
 void
 dixResetRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     ExtensionEntry extEntry = { .name = CORE };
+#endif
 
     dixFreeRegistry();
 
+#ifdef X_REGISTRY_REQUEST
     /* Open the protocol file */
     fh = fopen(FILENAME, "r");
     if (!fh)
         LogMessage(X_WARNING,
                    "Failed to open protocol names file " FILENAME "\n");
 
+    /* Add the core protocol */
+    RegisterExtensionNames(&extEntry);
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
     /* Add built-in resources */
     RegisterResourceName(RT_NONE, "NONE");
     RegisterResourceName(RT_WINDOW, "WINDOW");
@@ -347,9 +371,5 @@ dixResetRegistry(void)
     RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
     RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
-
-    /* Add the core protocol */
-    RegisterExtensionNames(&extEntry);
+#endif
 }
-
-#endif                          /* XREGISTRY */
diff --git a/dix/resource.c b/dix/resource.c
index 623d862..c254244 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -524,8 +524,10 @@ CreateNewResourceType(DeleteType deleteFunc, const char *name)
     resourceTypes[next].findSubResFunc = DefaultFindSubRes;
     resourceTypes[next].errorValue = BadValue;
 
+#if X_REGISTRY_RESOURCE
     /* Called even if name is NULL, to remove any previous entry */
     RegisterResourceName(next, name);
+#endif
 
     return next;
 }
diff --git a/include/registry.h b/include/registry.h
index 4e54bf6..43c3db3 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -17,18 +17,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #define XREGISTRY_UNKNOWN "<unknown>"
 
-#ifdef XREGISTRY
-
 #include "resource.h"
 #include "extnsionst.h"
 
+#if defined(XSELINUX) || defined(RES)
+#define X_REGISTRY_RESOURCE       1
+#endif
+
+#if defined(XSELINUX) || defined(XCSECURITY)
+#define X_REGISTRY_REQUEST        1
+#endif
+
 /* Internal string registry - for auditing, debugging, security, etc. */
 
-/*
- * Registration functions.  The name string is not copied, so it must
- * not be a stack variable.
- */
+#ifdef X_REGISTRY_RESOURCE
+/* Functions used by the X-Resource extension */
 extern _X_EXPORT void RegisterResourceName(RESTYPE type, const char *name);
+extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
+
+#ifdef X_REGISTRY_REQUEST
 extern _X_EXPORT void RegisterExtensionNames(ExtensionEntry * ext);
 
 /*
@@ -38,7 +46,7 @@ extern _X_EXPORT const char *LookupMajorName(int major);
 extern _X_EXPORT const char *LookupRequestName(int major, int minor);
 extern _X_EXPORT const char *LookupEventName(int event);
 extern _X_EXPORT const char *LookupErrorName(int error);
-extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
 
 /*
  * Setup and teardown
@@ -47,21 +55,4 @@ extern _X_EXPORT void dixResetRegistry(void);
 extern _X_EXPORT void dixFreeRegistry(void);
 extern _X_EXPORT void dixCloseRegistry(void);
 
-#else                           /* XREGISTRY */
-
-/* Define calls away when the registry is not being built. */
-
-#define RegisterResourceName(a, b) { ; }
-#define RegisterExtensionNames(a) { ; }
-
-#define LookupMajorName(a) XREGISTRY_UNKNOWN
-#define LookupRequestName(a, b) XREGISTRY_UNKNOWN
-#define LookupEventName(a) XREGISTRY_UNKNOWN
-#define LookupErrorName(a) XREGISTRY_UNKNOWN
-#define LookupResourceName(a) XREGISTRY_UNKNOWN
-
-#define dixResetRegistry() { ; }
-#define dixFreeRegistry() { ; }
-
-#endif                          /* XREGISTRY */
 #endif                          /* DIX_REGISTRY_H */
-- 
2.1.0



More information about the xorg-devel mailing list