loader: Port from xfree86 to dix API

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Adam Jackson 2014-06-16 11:30:18 -04:00
parent 778cfc5976
commit a6fcb15472
2 changed files with 81 additions and 103 deletions

View File

@ -50,21 +50,10 @@
#include <xorg-config.h> #include <xorg-config.h>
#endif #endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include "os.h" #include "os.h"
#include "loader.h" #include "loader.h"
#include "loaderProcs.h" #include "loaderProcs.h"
#include "xf86.h"
#include "xf86Priv.h"
#ifdef HAVE_DLFCN_H #ifdef HAVE_DLFCN_H
@ -80,18 +69,18 @@ extern void *xorg_symbols[];
void void
LoaderInit(void) LoaderInit(void)
{ {
xf86MsgVerb(X_INFO, 2, "Loader magic: %p\n", (void *) xorg_symbols); LogMessageVerb(X_INFO, 2, "Loader magic: %p\n", (void *) xorg_symbols);
xf86MsgVerb(X_INFO, 2, "Module ABI versions:\n"); LogMessageVerb(X_INFO, 2, "Module ABI versions:\n");
xf86ErrorFVerb(2, "\t%s: %d.%d\n", ABI_CLASS_ANSIC, LogWrite(2, "\t%s: %d.%d\n", ABI_CLASS_ANSIC,
GET_ABI_MAJOR(LoaderVersionInfo.ansicVersion), GET_ABI_MAJOR(LoaderVersionInfo.ansicVersion),
GET_ABI_MINOR(LoaderVersionInfo.ansicVersion)); GET_ABI_MINOR(LoaderVersionInfo.ansicVersion));
xf86ErrorFVerb(2, "\t%s: %d.%d\n", ABI_CLASS_VIDEODRV, LogWrite(2, "\t%s: %d.%d\n", ABI_CLASS_VIDEODRV,
GET_ABI_MAJOR(LoaderVersionInfo.videodrvVersion), GET_ABI_MAJOR(LoaderVersionInfo.videodrvVersion),
GET_ABI_MINOR(LoaderVersionInfo.videodrvVersion)); GET_ABI_MINOR(LoaderVersionInfo.videodrvVersion));
xf86ErrorFVerb(2, "\t%s : %d.%d\n", ABI_CLASS_XINPUT, LogWrite(2, "\t%s : %d.%d\n", ABI_CLASS_XINPUT,
GET_ABI_MAJOR(LoaderVersionInfo.xinputVersion), GET_ABI_MAJOR(LoaderVersionInfo.xinputVersion),
GET_ABI_MINOR(LoaderVersionInfo.xinputVersion)); GET_ABI_MINOR(LoaderVersionInfo.xinputVersion));
xf86ErrorFVerb(2, "\t%s : %d.%d\n", ABI_CLASS_EXTENSION, LogWrite(2, "\t%s : %d.%d\n", ABI_CLASS_EXTENSION,
GET_ABI_MAJOR(LoaderVersionInfo.extensionVersion), GET_ABI_MAJOR(LoaderVersionInfo.extensionVersion),
GET_ABI_MINOR(LoaderVersionInfo.extensionVersion)); GET_ABI_MINOR(LoaderVersionInfo.extensionVersion));
@ -108,10 +97,10 @@ LoaderOpen(const char *module, int *errmaj, int *errmin)
ErrorF("LoaderOpen(%s)\n", module); ErrorF("LoaderOpen(%s)\n", module);
#endif #endif
xf86Msg(X_INFO, "Loading %s\n", module); LogMessage(X_INFO, "Loading %s\n", module);
if (!(ret = dlopen(module, RTLD_LAZY | RTLD_GLOBAL))) { if (!(ret = dlopen(module, RTLD_LAZY | RTLD_GLOBAL))) {
xf86Msg(X_ERROR, "Failed to load %s: %s\n", module, dlerror()); LogMessage(X_ERROR, "Failed to load %s: %s\n", module, dlerror());
if (errmaj) if (errmaj)
*errmaj = LDR_NOLOAD; *errmaj = LDR_NOLOAD;
if (errmin) if (errmin)

View File

@ -51,18 +51,11 @@
#endif #endif
#include "os.h" #include "os.h"
/* For stat() and related stuff */
#define NO_OSLIB_PROTOTYPES
#include "xf86_OSlib.h"
#define LOADERDECLARATIONS
#include "loaderProcs.h" #include "loaderProcs.h"
#include "misc.h" #include "xf86Module.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86Xinput.h"
#include "loader.h" #include "loader.h"
#include "xf86Optrec.h"
#include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include <dirent.h> #include <dirent.h>
@ -307,7 +300,7 @@ InitSubdirs(const char **subdirlist)
*/ */
if (**s == '/' || **s == '\\' || strchr(*s, ':') || if (**s == '/' || **s == '\\' || strchr(*s, ':') ||
strstr(*s, "..")) { strstr(*s, "..")) {
xf86Msg(X_ERROR, "InitSubdirs: Bad subdir: \"%s\"\n", *s); LogMessage(X_ERROR, "InitSubdirs: Bad subdir \"%s\"\n", *s);
free(tmp_subdirlist); free(tmp_subdirlist);
return NULL; return NULL;
} }
@ -572,7 +565,7 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
long ver = data->xf86version; long ver = data->xf86version;
MessageType errtype; MessageType errtype;
xf86Msg(X_INFO, "Module %s: vendor=\"%s\"\n", LogMessage(X_INFO, "Module %s: vendor=\"%s\"\n",
data->modname ? data->modname : "UNKNOWN!", data->modname ? data->modname : "UNKNOWN!",
data->vendor ? data->vendor : "UNKNOWN!"); data->vendor ? data->vendor : "UNKNOWN!");
@ -580,14 +573,14 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
vercode[1] = (ver / 100000) % 100; vercode[1] = (ver / 100000) % 100;
vercode[2] = (ver / 1000) % 100; vercode[2] = (ver / 1000) % 100;
vercode[3] = ver % 1000; vercode[3] = ver % 1000;
xf86ErrorF("\tcompiled for %d.%d.%d", vercode[0], vercode[1], vercode[2]); LogWrite(1, "\tcompiled for %d.%d.%d", vercode[0], vercode[1], vercode[2]);
if (vercode[3] != 0) if (vercode[3] != 0)
xf86ErrorF(".%d", vercode[3]); LogWrite(1, ".%d", vercode[3]);
xf86ErrorF(", module version = %d.%d.%d\n", data->majorversion, LogWrite(1, ", module version = %d.%d.%d\n", data->majorversion,
data->minorversion, data->patchlevel); data->minorversion, data->patchlevel);
if (data->moduleclass) if (data->moduleclass)
xf86ErrorFVerb(2, "\tModule class: %s\n", data->moduleclass); LogWrite(2, "\tModule class: %s\n", data->moduleclass);
ver = -1; ver = -1;
if (data->abiclass) { if (data->abiclass) {
@ -605,7 +598,7 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
abimaj = GET_ABI_MAJOR(data->abiversion); abimaj = GET_ABI_MAJOR(data->abiversion);
abimin = GET_ABI_MINOR(data->abiversion); abimin = GET_ABI_MINOR(data->abiversion);
xf86ErrorFVerb(2, "\tABI class: %s, version %d.%d\n", LogWrite(2, "\tABI class: %s, version %d.%d\n",
data->abiclass, abimaj, abimin); data->abiclass, abimaj, abimin);
if (ver != -1) { if (ver != -1) {
vermaj = GET_ABI_MAJOR(ver); vermaj = GET_ABI_MAJOR(ver);
@ -615,9 +608,8 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
errtype = X_WARNING; errtype = X_WARNING;
else else
errtype = X_ERROR; errtype = X_ERROR;
xf86MsgVerb(errtype, 0, LogMessageVerb(errtype, 0, "%s: module ABI major version (%d) "
"%s: module ABI major version (%d) doesn't" "doesn't match the server's version (%d)\n",
" match the server's version (%d)\n",
module, abimaj, vermaj); module, abimaj, vermaj);
if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL)) if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL))
return FALSE; return FALSE;
@ -627,10 +619,9 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
errtype = X_WARNING; errtype = X_WARNING;
else else
errtype = X_ERROR; errtype = X_ERROR;
xf86MsgVerb(errtype, 0, LogMessageVerb(errtype, 0, "%s: module ABI minor version (%d) "
"%s: module ABI minor version (%d) is " "is newer than the server's version (%d)\n",
"newer than the server's version " module, abimin, vermin);
"(%d)\n", module, abimin, vermin);
if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL)) if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL))
return FALSE; return FALSE;
} }
@ -641,24 +632,26 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
if (req) { if (req) {
if (req->majorversion != MAJOR_UNSPEC) { if (req->majorversion != MAJOR_UNSPEC) {
if (data->majorversion != req->majorversion) { if (data->majorversion != req->majorversion) {
xf86MsgVerb(X_WARNING, 2, "%s: module major version (%d) " LogMessageVerb(X_WARNING, 2, "%s: module major version (%d) "
"doesn't match required major version (%d)\n", "doesn't match required major version (%d)\n",
module, data->majorversion, req->majorversion); module, data->majorversion, req->majorversion);
return FALSE; return FALSE;
} }
else if (req->minorversion != MINOR_UNSPEC) { else if (req->minorversion != MINOR_UNSPEC) {
if (data->minorversion < req->minorversion) { if (data->minorversion < req->minorversion) {
xf86MsgVerb(X_WARNING, 2, "%s: module minor version (%d) " LogMessageVerb(X_WARNING, 2, "%s: module minor version "
"is less than the required minor version (%d)\n", "(%d) is less than the required minor "
module, data->minorversion, req->minorversion); "version (%d)\n", module,
data->minorversion, req->minorversion);
return FALSE; return FALSE;
} }
else if (data->minorversion == req->minorversion && else if (data->minorversion == req->minorversion &&
req->patchlevel != PATCH_UNSPEC) { req->patchlevel != PATCH_UNSPEC) {
if (data->patchlevel < req->patchlevel) { if (data->patchlevel < req->patchlevel) {
xf86MsgVerb(X_WARNING, 2, "%s: module patch level (%d) " LogMessageVerb(X_WARNING, 2, "%sL module patch level "
"is less than the required patch level (%d)\n", "(%d) is less than the required patch "
module, data->patchlevel, req->patchlevel); "level (%d)\n", module, data->patchlevel,
req->patchlevel);
return FALSE; return FALSE;
} }
} }
@ -667,9 +660,8 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
if (req->moduleclass) { if (req->moduleclass) {
if (!data->moduleclass || if (!data->moduleclass ||
strcmp(req->moduleclass, data->moduleclass)) { strcmp(req->moduleclass, data->moduleclass)) {
xf86MsgVerb(X_WARNING, 2, "%s: Module class (%s) doesn't match " LogMessageVerb(X_WARNING, 2, "%s: Module class (%s) doesn't "
"the required class (%s)\n", "match the required class (%s)\n", module,
module,
data->moduleclass ? data->moduleclass : "<NONE>", data->moduleclass ? data->moduleclass : "<NONE>",
req->moduleclass); req->moduleclass);
return FALSE; return FALSE;
@ -677,9 +669,8 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
} }
else if (req->abiclass != ABI_CLASS_NONE) { else if (req->abiclass != ABI_CLASS_NONE) {
if (!data->abiclass || strcmp(req->abiclass, data->abiclass)) { if (!data->abiclass || strcmp(req->abiclass, data->abiclass)) {
xf86MsgVerb(X_WARNING, 2, "%s: ABI class (%s) doesn't match the " LogMessageVerb(X_WARNING, 2, "%s: ABI class (%s) doesn't match"
"required ABI class (%s)\n", " the required ABI class (%s)\n", module,
module,
data->abiclass ? data->abiclass : "<NONE>", data->abiclass ? data->abiclass : "<NONE>",
req->abiclass); req->abiclass);
return FALSE; return FALSE;
@ -694,15 +685,15 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
maj = GET_ABI_MAJOR(data->abiversion); maj = GET_ABI_MAJOR(data->abiversion);
min = GET_ABI_MINOR(data->abiversion); min = GET_ABI_MINOR(data->abiversion);
if (maj != reqmaj) { if (maj != reqmaj) {
xf86MsgVerb(X_WARNING, 2, "%s: ABI major version (%d) doesn't " LogMessageVerb(X_WARNING, 2, "%s: ABI major version (%d) "
"match the required ABI major version (%d)\n", "doesn't match the required ABI major version "
module, maj, reqmaj); "(%d)\n", module, maj, reqmaj);
return FALSE; return FALSE;
} }
/* XXX Maybe this should be the other way around? */ /* XXX Maybe this should be the other way around? */
if (min > reqmin) { if (min > reqmin) {
xf86MsgVerb(X_WARNING, 2, "%s: module ABI minor version (%d) " LogMessageVerb(X_WARNING, 2, "%s: module ABI minor version "
"is newer than that available (%d)\n", "(%d) is newer than that available (%d)\n",
module, min, reqmin); module, min, reqmin);
return FALSE; return FALSE;
} }
@ -727,12 +718,11 @@ LoadSubModule(void *_parent, const char *module,
ModuleDescPtr submod; ModuleDescPtr submod;
ModuleDescPtr parent = (ModuleDescPtr) _parent; ModuleDescPtr parent = (ModuleDescPtr) _parent;
xf86MsgVerb(X_INFO, 3, "Loading sub module \"%s\"\n", module); LogMessageVerb(X_INFO, 3, "Loading sub module \"%s\"\n", module);
if (PathIsAbsolute(module)) { if (PathIsAbsolute(module)) {
xf86Msg(X_ERROR, LogMessage(X_ERROR, "LoadSubModule: "
"LoadSubModule: Absolute module path not permitted: \"%s\"\n", "Absolute module path not permitted: \"%s\"\n", module);
module);
if (errmaj) if (errmaj)
*errmaj = LDR_BADUSAGE; *errmaj = LDR_BADUSAGE;
if (errmin) if (errmin)
@ -857,26 +847,26 @@ LoadModule(const char *module, const char **subdirlist,
char *m = NULL; char *m = NULL;
const char **cim; const char **cim;
xf86MsgVerb(X_INFO, 3, "LoadModule: \"%s\"", module); LogMessageVerb(X_INFO, 3, "LoadModule: \"%s\"", module);
patterns = InitPatterns(patternlist); patterns = InitPatterns(patternlist);
name = LoaderGetCanonicalName(module, patterns); name = LoaderGetCanonicalName(module, patterns);
noncanonical = (name && strcmp(module, name) != 0); noncanonical = (name && strcmp(module, name) != 0);
if (noncanonical) { if (noncanonical) {
xf86ErrorFVerb(3, " (%s)\n", name); LogWrite(3, " (%s)\n", name);
xf86MsgVerb(X_WARNING, 1, LogMessageVerb(X_WARNING, 1,
"LoadModule: given non-canonical module name \"%s\"\n", "LoadModule: given non-canonical module name \"%s\"\n",
module); module);
m = name; m = name;
} }
else { else {
xf86ErrorFVerb(3, "\n"); LogWrite(3, "\n");
m = (char *) module; m = (char *) module;
} }
for (cim = compiled_in_modules; *cim; cim++) for (cim = compiled_in_modules; *cim; cim++)
if (!strcmp(m, *cim)) { if (!strcmp(m, *cim)) {
xf86MsgVerb(X_INFO, 3, "Module \"%s\" already built-in\n", m); LogMessageVerb(X_INFO, 3, "Module \"%s\" already built-in\n", m);
ret = (ModuleDescPtr) 1; ret = (ModuleDescPtr) 1;
goto LoadModule_exit; goto LoadModule_exit;
} }
@ -931,7 +921,7 @@ LoadModule(const char *module, const char **subdirlist,
* did we find the module? * did we find the module?
*/ */
if (!found) { if (!found) {
xf86Msg(X_WARNING, "Warning, couldn't open module %s\n", module); LogMessage(X_WARNING, "Warning, couldn't open module %s\n", module);
if (errmaj) if (errmaj)
*errmaj = LDR_NOENT; *errmaj = LDR_NOENT;
if (errmin) if (errmin)
@ -980,8 +970,7 @@ LoadModule(const char *module, const char **subdirlist,
} }
} }
else { else {
xf86Msg(X_ERROR, LogMessage(X_ERROR, "LoadModule: Module %s does not supply"
"LoadModule: Module %s does not supply"
" version information\n", module); " version information\n", module);
if (errmaj) if (errmaj)
*errmaj = LDR_INVALID; *errmaj = LDR_INVALID;
@ -997,7 +986,7 @@ LoadModule(const char *module, const char **subdirlist,
} }
else { else {
/* no initdata, fail the load */ /* no initdata, fail the load */
xf86Msg(X_ERROR, "LoadModule: Module %s does not have a %s " LogMessage(X_ERROR, "LoadModule: Module %s does not have a %s "
"data object.\n", module, p); "data object.\n", module, p);
if (errmaj) if (errmaj)
*errmaj = LDR_INVALID; *errmaj = LDR_INVALID;
@ -1012,7 +1001,7 @@ LoadModule(const char *module, const char **subdirlist,
} }
} }
else if (options) { else if (options) {
xf86Msg(X_WARNING, "Module Options present, but no SetupProc " LogMessage(X_WARNING, "Module Options present, but no SetupProc "
"available for %s\n", module); "available for %s\n", module);
} }
goto LoadModule_exit; goto LoadModule_exit;
@ -1162,10 +1151,10 @@ LoaderErrorMsg(const char *name, const char *modname, int errmaj, int errmin)
msg = "unknown error"; msg = "unknown error";
} }
if (name) if (name)
xf86Msg(type, "%s: Failed to load module \"%s\" (%s, %d)\n", LogMessage(type, "%s: Failed to load module \"%s\" (%s, %d)\n",
name, modname, msg, errmin); name, modname, msg, errmin);
else else
xf86Msg(type, "Failed to load module \"%s\" (%s, %d)\n", LogMessage(type, "Failed to load module \"%s\" (%s, %d)\n",
modname, msg, errmin); modname, msg, errmin);
} }