Improve modules loading defaults

Provide default modules that may be overrided easily. Previously the
server would load a set of default modules, but only if none were
specified in the xorg.conf, or if you didn't have a xorg.conf at all. This
patch provides a default set and you can add only the "Load" instructions
to xorg.conf that you want without losing the defaults. Similarly, if you
don't want to load a module that's loaded by default, you can add "Disable
modulename" to your xorg.conf (see man xorg.conf in this release for
details). This allows for a minimal "Modules" section, where the user only
need specify what they want to be different. See bug #10541 for more.

The list of default modules is taken from the set loaded by default when
there was a xorg.conf containing no "Modules" section.

A potential problem for some users is that some users disable a module,
most notably DRI, by commenting out the "Load" line in their xorg.conf.
This needs to be changed to an uncommented "Disable" line, as DRI is
loaded by default.
This commit is contained in:
David Nusinow 2007-05-03 22:00:23 -04:00
parent d2f813f7db
commit e91b9ddc7a
6 changed files with 125 additions and 33 deletions

View File

@ -254,6 +254,7 @@ xf86ModulelistFromConfig(pointer **optlist)
char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", NULL };
pointer *optarray;
XF86LoadPtr modp;
Bool found;
/*
* make sure the config file has been parsed and that we have a
@ -266,35 +267,73 @@ xf86ModulelistFromConfig(pointer **optlist)
}
if (xf86configptr->conf_modules) {
/*
* Walk the list of modules in the "Module" section to determine how
* many we have.
*/
modp = xf86configptr->conf_modules->mod_load_lst;
while (modp) {
for (i = 0; ignore[i]; i++) {
if (strcmp(modp->load_name, ignore[i]) == 0)
modp->ignore = 1;
/* Walk the disable list and let people know what we've parsed to
* not be loaded
*/
modp = xf86configptr->conf_modules->mod_disable_lst;
while (modp) {
xf86Msg(X_WARNING, "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n", modp->load_name);
modp = (XF86LoadPtr) modp->list.next;
}
/*
* Walk the default settings table. For each module listed to be
* loaded, make sure it's in the mod_load_lst. If it's not, make
* sure it's not in the mod_no_load_lst. If it's not disabled,
* append it to mod_load_lst
*/
for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
if (ModuleDefaults[i].toLoad == FALSE) {
xf86Msg(X_WARNING, "\"%s\" is not to be loaded by default. Skipping.\n", ModuleDefaults[i].name);
continue;
}
if (!modp->ignore)
count++;
modp = (XF86LoadPtr) modp->list.next;
}
found = FALSE;
modp = xf86configptr->conf_modules->mod_load_lst;
while (modp) {
if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
found = TRUE;
break;
}
modp = (XF86LoadPtr) modp->list.next;
}
if (found == FALSE) {
modp = xf86configptr->conf_modules->mod_disable_lst;
while (modp) {
if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
found = TRUE;
break;
}
modp = (XF86LoadPtr) modp->list.next;
}
}
if (found == FALSE) {
XF86ConfModulePtr ptr = xf86configptr->conf_modules;
ptr = xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt);
}
}
} else {
xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec));
for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
if (ModuleDefaults[i].toLoad == TRUE) {
XF86ConfModulePtr ptr = xf86configptr->conf_modules;
ptr = xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt);
}
}
}
if (count == 0) {
XF86ConfModulePtr ptr = xf86configptr->conf_modules;
ptr = xf86addNewLoadDirective(ptr, "extmod", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "dbe", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "glx", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "freetype", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "type1", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "record", XF86_LOAD_MODULE, NULL);
ptr = xf86addNewLoadDirective(ptr, "dri", XF86_LOAD_MODULE, NULL);
count = 7;
}
/*
* Walk the list of modules in the "Module" section to determine how
* many we have.
*/
modp = xf86configptr->conf_modules->mod_load_lst;
while (modp) {
for (i = 0; ignore[i]; i++) {
if (strcmp(modp->load_name, ignore[i]) == 0)
modp->ignore = 1;
}
if (!modp->ignore)
count++;
modp = (XF86LoadPtr) modp->list.next;
}
/*
* allocate the memory and walk the list again to fill in the pointers
@ -303,22 +342,22 @@ xf86ModulelistFromConfig(pointer **optlist)
optarray = xnfalloc((count + 1) * sizeof(pointer));
count = 0;
if (xf86configptr->conf_modules) {
modp = xf86configptr->conf_modules->mod_load_lst;
while (modp) {
modp = xf86configptr->conf_modules->mod_load_lst;
while (modp) {
if (!modp->ignore) {
modulearray[count] = modp->load_name;
optarray[count] = modp->load_opt;
count++;
modulearray[count] = modp->load_name;
optarray[count] = modp->load_opt;
count++;
}
modp = (XF86LoadPtr) modp->list.next;
}
modp = (XF86LoadPtr) modp->list.next;
}
}
modulearray[count] = NULL;
optarray[count] = NULL;
if (optlist)
*optlist = optarray;
*optlist = optarray;
else
xfree(optarray);
xfree(optarray);
return modulearray;
}

View File

@ -33,6 +33,8 @@
#ifndef _xf86_config_h
#define _xf86_config_h
#include "xf86Optrec.h"
#ifdef HAVE_PARSER_DECLS
/*
* global structure that holds the result of parsing the config file
@ -46,6 +48,23 @@ typedef enum _ConfigStatus {
CONFIG_NOFILE
} ConfigStatus;
typedef struct _ModuleDefault {
char *name;
Bool toLoad;
XF86OptionPtr load_opt;
} ModuleDefault;
static ModuleDefault ModuleDefaults[] = {
{.name = "extmod", .toLoad = TRUE, .load_opt=NULL},
{.name = "dbe", .toLoad = TRUE, .load_opt=NULL},
{.name = "glx", .toLoad = TRUE, .load_opt=NULL},
{.name = "freetype", .toLoad = TRUE, .load_opt=NULL},
{.name = "type1", .toLoad = TRUE, .load_opt=NULL},
{.name = "record", .toLoad = TRUE, .load_opt=NULL},
{.name = "dri", .toLoad = TRUE, .load_opt=NULL},
{.name = NULL, .toLoad = FALSE, .load_opt=NULL}
};
/*
* prototypes
*/

View File

@ -639,6 +639,20 @@ Example: the Type 1 font rasteriser can be loaded with the following entry:
.B "Load \*qtype1\*q"
.RE
.RE
.TP 7
.BI "Disable \*q" modulename \*q
This instructs the server to not load the module called
.IR modulename .
Some modules are loaded by default in the server, and this overrides that
default. If a
.B Load
instruction is given for the same module, it overrides the
.B Disable
instruction and the module is loaded. The module name given should be the
module's standard name, not the module file name. As with the
.B Load
instruction, the standard name is case-sensitive, and does not include the
"lib" prefix, or the ".a", ".o", or ".so" suffixes.
.PP
The second form of entry is a
.BR SubSection,

View File

@ -76,6 +76,7 @@ static xf86ConfigSymTabRec ModuleTab[] =
{
{ENDSECTION, "endsection"},
{LOAD, "load"},
{DISABLE, "disable"},
{LOAD_DRIVER, "loaddriver"},
{SUBSECTION, "subsection"},
{-1, ""},
@ -141,6 +142,13 @@ xf86parseModuleSection (void)
xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
XF86_LOAD_MODULE, NULL);
break;
case DISABLE:
if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
Error (QUOTE_MSG, "Disable");
ptr->mod_disable_lst =
xf86addNewLoadDirective (ptr->mod_disable_lst, val.str,
XF86_DISABLE_MODULE, NULL);
break;
case LOAD_DRIVER:
if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
Error (QUOTE_MSG, "LoadDriver");
@ -257,6 +265,15 @@ xf86freeModules (XF86ConfModulePtr ptr)
lptr = lptr->list.next;
xf86conffree (prev);
}
lptr = ptr->mod_disable_lst;
while (lptr)
{
TestFree (lptr->load_name);
TestFree (lptr->load_comment);
prev = lptr;
lptr = lptr->list.next;
xf86conffree (prev);
}
TestFree (ptr->mod_comment);
xf86conffree (ptr);
}

View File

@ -82,6 +82,7 @@ XF86ConfFilesRec, *XF86ConfFilesPtr;
/* Values for load_type */
#define XF86_LOAD_MODULE 0
#define XF86_LOAD_DRIVER 1
#define XF86_DISABLE_MODULE 2
typedef struct
{
@ -97,6 +98,7 @@ XF86LoadRec, *XF86LoadPtr;
typedef struct
{
XF86LoadPtr mod_load_lst;
XF86LoadPtr mod_disable_lst;
char *mod_comment;
}
XF86ConfModuleRec, *XF86ConfModulePtr;

View File

@ -170,6 +170,7 @@ typedef enum {
/* Module tokens */
LOAD,
LOAD_DRIVER,
DISABLE,
/* Device tokens */
DRIVER,