summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-09-10 15:21:32 -0700
committerKeith Packard <keithp@keithp.com>2014-09-15 09:16:56 -0700
commitf28a8a09f612e95bda18d7e267f13f18b37b60bf (patch)
tree4489c9a40ae7b3344179e76c281cccb03f54e2a4
parent92278752cb9ffe7fef44a500d36ad146dc2d2f9f (diff)
Build required portions of registry.c automatically [v2]registry-fixes
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@keithp.com>
-rw-r--r--configure.ac6
-rw-r--r--dix/extension.c2
-rw-r--r--dix/registry.c90
-rw-r--r--dix/resource.c2
-rw-r--r--include/registry.h39
5 files changed, 74 insertions, 65 deletions
diff --git a/configure.ac b/configure.ac
index cba7d24ea..ce76baa5f 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 ede4bf5bd..e43291eec 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 8b76d56ad..84d48b4e3 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 623d862d6..c254244a3 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 4e54bf636..43c3db339 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 */