loader: Turn LoaderListDirs into LoaderListDir
Callers only ever use this for a single directory anyway. While we're at it, also move xf86DriverListFromCompile near its only user in the X -configure code (and inline it out of existence), and remove LoaderFreeDirList as it's unused (since X -configure is just going to exit anyway, none of that code cares about cleanup). Reviewed-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
parent
c54a9ca152
commit
ba726ba6a7
|
@ -518,82 +518,6 @@ xf86InputDriverlistFromConfig(void)
|
|||
return modulearray;
|
||||
}
|
||||
|
||||
static int
|
||||
is_fallback(const char *s)
|
||||
{
|
||||
/* later entries are less preferred */
|
||||
const char *fallback[5] = { "modesetting", "fbdev", "vesa", "wsfb", NULL };
|
||||
int i;
|
||||
|
||||
for (i = 0; fallback[i]; i++)
|
||||
if (strstr(s, fallback[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
driver_sort(const void *_l, const void *_r)
|
||||
{
|
||||
const char *l = *(const char **)_l;
|
||||
const char *r = *(const char **)_r;
|
||||
int left = is_fallback(l);
|
||||
int right = is_fallback(r);
|
||||
|
||||
/* neither is a fallback, asciibetize */
|
||||
if (left == -1 && right == -1)
|
||||
return strcmp(l, r);
|
||||
|
||||
/* left is a fallback */
|
||||
if (left >= 0)
|
||||
return 1;
|
||||
|
||||
/* right is a fallback */
|
||||
if (right >= 0)
|
||||
return -1;
|
||||
|
||||
/* both are fallbacks, which is worse */
|
||||
return left - right;
|
||||
}
|
||||
|
||||
static void
|
||||
fixup_video_driver_list(const char **drivers)
|
||||
{
|
||||
const char **end;
|
||||
|
||||
/* walk to the end of the list */
|
||||
for (end = drivers; *end && **end; end++);
|
||||
end--;
|
||||
|
||||
qsort(drivers, end - drivers, sizeof(const char *), driver_sort);
|
||||
}
|
||||
|
||||
static const char **
|
||||
GenerateDriverlist(const char *dirname)
|
||||
{
|
||||
const char **ret;
|
||||
const char *subdirs[] = { dirname, NULL };
|
||||
static const char *patlist[] = { "(.*)_drv\\.so", NULL };
|
||||
ret = LoaderListDirs(subdirs, patlist);
|
||||
|
||||
/* fix up the probe order for video drivers */
|
||||
if (strstr(dirname, "drivers") && ret != NULL)
|
||||
fixup_video_driver_list(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char **
|
||||
xf86DriverlistFromCompile(void)
|
||||
{
|
||||
static const char **driverlist = NULL;
|
||||
|
||||
if (!driverlist)
|
||||
driverlist = GenerateDriverlist("drivers");
|
||||
|
||||
return driverlist;
|
||||
}
|
||||
|
||||
static void
|
||||
configFiles(XF86ConfFilesPtr fileconf)
|
||||
{
|
||||
|
|
|
@ -61,7 +61,6 @@ typedef struct _ModuleDefault {
|
|||
*/
|
||||
const char **xf86ModulelistFromConfig(void ***);
|
||||
const char **xf86DriverlistFromConfig(void);
|
||||
const char **xf86DriverlistFromCompile(void);
|
||||
const char **xf86InputDriverlistFromConfig(void);
|
||||
Bool xf86BuiltinInputDriver(const char *);
|
||||
ConfigStatus xf86HandleConfigFile(Bool);
|
||||
|
|
|
@ -400,14 +400,9 @@ configureModuleSection(void)
|
|||
{
|
||||
const char **elist, **el;
|
||||
|
||||
/* Find the list of extension modules. */
|
||||
const char *esubdirs[] = {
|
||||
"extensions",
|
||||
NULL
|
||||
};
|
||||
parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec);
|
||||
|
||||
elist = LoaderListDirs(esubdirs, NULL);
|
||||
elist = LoaderListDir("extensions", NULL);
|
||||
if (elist) {
|
||||
for (el = elist; *el; el++) {
|
||||
XF86LoadPtr module;
|
||||
|
@ -534,6 +529,70 @@ configureDDCMonitorSection(int screennum)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
static int
|
||||
is_fallback(const char *s)
|
||||
{
|
||||
/* later entries are less preferred */
|
||||
const char *fallback[5] = { "modesetting", "fbdev", "vesa", "wsfb", NULL };
|
||||
int i;
|
||||
|
||||
for (i = 0; fallback[i]; i++)
|
||||
if (strstr(s, fallback[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
driver_sort(const void *_l, const void *_r)
|
||||
{
|
||||
const char *l = *(const char **)_l;
|
||||
const char *r = *(const char **)_r;
|
||||
int left = is_fallback(l);
|
||||
int right = is_fallback(r);
|
||||
|
||||
/* neither is a fallback, asciibetize */
|
||||
if (left == -1 && right == -1)
|
||||
return strcmp(l, r);
|
||||
|
||||
/* left is a fallback */
|
||||
if (left >= 0)
|
||||
return 1;
|
||||
|
||||
/* right is a fallback */
|
||||
if (right >= 0)
|
||||
return -1;
|
||||
|
||||
/* both are fallbacks, which is worse */
|
||||
return left - right;
|
||||
}
|
||||
|
||||
static void
|
||||
fixup_video_driver_list(const char **drivers)
|
||||
{
|
||||
const char **end;
|
||||
|
||||
/* walk to the end of the list */
|
||||
for (end = drivers; *end && **end; end++);
|
||||
end--;
|
||||
|
||||
qsort(drivers, end - drivers, sizeof(const char *), driver_sort);
|
||||
}
|
||||
|
||||
static const char **
|
||||
GenerateDriverList(void)
|
||||
{
|
||||
const char **ret;
|
||||
static const char *patlist[] = { "(.*)_drv\\.so", NULL };
|
||||
ret = LoaderListDir("drivers", patlist);
|
||||
|
||||
/* fix up the probe order for video drivers */
|
||||
if (ret != NULL)
|
||||
fixup_video_driver_list(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
DoConfigure(void)
|
||||
{
|
||||
|
@ -545,7 +604,7 @@ DoConfigure(void)
|
|||
const char **vlist, **vl;
|
||||
int *dev2screen;
|
||||
|
||||
vlist = xf86DriverlistFromCompile();
|
||||
vlist = GenerateDriverList();
|
||||
|
||||
if (!vlist) {
|
||||
ErrorF("Missing output drivers. Configuration failed.\n");
|
||||
|
@ -784,7 +843,7 @@ DoShowOptions(void)
|
|||
char *pSymbol = 0;
|
||||
XF86ModuleData *initData = 0;
|
||||
|
||||
if (!(vlist = xf86DriverlistFromCompile())) {
|
||||
if (!(vlist = GenerateDriverList())) {
|
||||
ErrorF("Missing output drivers\n");
|
||||
goto bail;
|
||||
}
|
||||
|
|
|
@ -85,8 +85,7 @@ unsigned long LoaderGetModuleVersion(ModuleDescPtr mod);
|
|||
void LoaderResetOptions(void);
|
||||
void LoaderSetOptions(unsigned long);
|
||||
|
||||
const char **LoaderListDirs(const char **, const char **);
|
||||
void LoaderFreeDirList(char **);
|
||||
const char **LoaderListDir(const char *, const char **);
|
||||
|
||||
/* Options for LoaderSetOptions */
|
||||
#define LDR_OPT_ABI_MISMATCH_NONFATAL 0x0001
|
||||
|
|
|
@ -448,13 +448,11 @@ FindModule(const char *module, const char *dirname, const char **subdirlist,
|
|||
}
|
||||
|
||||
const char **
|
||||
LoaderListDirs(const char **subdirlist, const char **patternlist)
|
||||
LoaderListDir(const char *subdir, const char **patternlist)
|
||||
{
|
||||
char buf[PATH_MAX + 1];
|
||||
char **pathlist;
|
||||
char **elem;
|
||||
const char **subdirs;
|
||||
const char **s;
|
||||
PatternPtr patterns = NULL;
|
||||
PatternPtr p;
|
||||
DIR *d;
|
||||
|
@ -470,62 +468,56 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
|
|||
|
||||
if (!(pathlist = defaultPathList))
|
||||
return NULL;
|
||||
if (!(subdirs = InitSubdirs(subdirlist)))
|
||||
goto bail;
|
||||
if (!(patterns = InitPatterns(patternlist)))
|
||||
goto bail;
|
||||
|
||||
for (elem = pathlist; *elem; elem++) {
|
||||
for (s = subdirs; *s; s++) {
|
||||
if ((dirlen = strlen(*elem) + strlen(*s)) > PATH_MAX)
|
||||
continue;
|
||||
strcpy(buf, *elem);
|
||||
strcat(buf, *s);
|
||||
fp = buf + dirlen;
|
||||
if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) &&
|
||||
(d = opendir(buf))) {
|
||||
if (buf[dirlen - 1] != '/') {
|
||||
buf[dirlen++] = '/';
|
||||
fp++;
|
||||
}
|
||||
while ((dp = readdir(d))) {
|
||||
if (dirlen + strlen(dp->d_name) > PATH_MAX)
|
||||
continue;
|
||||
strcpy(fp, dp->d_name);
|
||||
if (!(stat(buf, &stat_buf) == 0 &&
|
||||
S_ISREG(stat_buf.st_mode)))
|
||||
continue;
|
||||
for (p = patterns; p->pattern; p++) {
|
||||
if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 &&
|
||||
match[1].rm_so != -1) {
|
||||
len = match[1].rm_eo - match[1].rm_so;
|
||||
save = listing;
|
||||
listing = reallocarray(listing, n + 2,
|
||||
sizeof(char *));
|
||||
if (!listing) {
|
||||
if (save) {
|
||||
save[n] = NULL;
|
||||
FreeStringList(save);
|
||||
}
|
||||
closedir(d);
|
||||
goto bail;
|
||||
if ((dirlen = strlen(*elem) + strlen(subdir) + 1) > PATH_MAX)
|
||||
continue;
|
||||
strcpy(buf, *elem);
|
||||
strcat(buf, "/");
|
||||
strcat(buf, subdir);
|
||||
fp = buf + dirlen;
|
||||
if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) &&
|
||||
(d = opendir(buf))) {
|
||||
if (buf[dirlen - 1] != '/') {
|
||||
buf[dirlen++] = '/';
|
||||
fp++;
|
||||
}
|
||||
while ((dp = readdir(d))) {
|
||||
if (dirlen + strlen(dp->d_name) > PATH_MAX)
|
||||
continue;
|
||||
strcpy(fp, dp->d_name);
|
||||
if (!(stat(buf, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode)))
|
||||
continue;
|
||||
for (p = patterns; p->pattern; p++) {
|
||||
if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 &&
|
||||
match[1].rm_so != -1) {
|
||||
len = match[1].rm_eo - match[1].rm_so;
|
||||
save = listing;
|
||||
listing = reallocarray(listing, n + 2, sizeof(char *));
|
||||
if (!listing) {
|
||||
if (save) {
|
||||
save[n] = NULL;
|
||||
FreeStringList(save);
|
||||
}
|
||||
listing[n] = malloc(len + 1);
|
||||
if (!listing[n]) {
|
||||
FreeStringList(listing);
|
||||
closedir(d);
|
||||
goto bail;
|
||||
}
|
||||
strncpy(listing[n], dp->d_name + match[1].rm_so,
|
||||
len);
|
||||
listing[n][len] = '\0';
|
||||
n++;
|
||||
break;
|
||||
closedir(d);
|
||||
goto bail;
|
||||
}
|
||||
listing[n] = malloc(len + 1);
|
||||
if (!listing[n]) {
|
||||
FreeStringList(listing);
|
||||
closedir(d);
|
||||
goto bail;
|
||||
}
|
||||
strncpy(listing[n], dp->d_name + match[1].rm_so, len);
|
||||
listing[n][len] = '\0';
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
if (listing)
|
||||
|
@ -534,16 +526,9 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
|
|||
|
||||
bail:
|
||||
FreePatterns(patterns);
|
||||
FreeSubdirs(subdirs);
|
||||
return (const char **) ret;
|
||||
}
|
||||
|
||||
void
|
||||
LoaderFreeDirList(char **list)
|
||||
{
|
||||
FreeStringList(list);
|
||||
}
|
||||
|
||||
static Bool
|
||||
CheckVersion(const char *module, XF86ModuleVersionInfo * data,
|
||||
const XF86ModReqInfo * req)
|
||||
|
|
Loading…
Reference in New Issue