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:
Adam Jackson 2016-04-14 11:30:02 -04:00
parent c54a9ca152
commit ba726ba6a7
5 changed files with 110 additions and 144 deletions

View File

@ -518,82 +518,6 @@ xf86InputDriverlistFromConfig(void)
return modulearray; 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 static void
configFiles(XF86ConfFilesPtr fileconf) configFiles(XF86ConfFilesPtr fileconf)
{ {

View File

@ -61,7 +61,6 @@ typedef struct _ModuleDefault {
*/ */
const char **xf86ModulelistFromConfig(void ***); const char **xf86ModulelistFromConfig(void ***);
const char **xf86DriverlistFromConfig(void); const char **xf86DriverlistFromConfig(void);
const char **xf86DriverlistFromCompile(void);
const char **xf86InputDriverlistFromConfig(void); const char **xf86InputDriverlistFromConfig(void);
Bool xf86BuiltinInputDriver(const char *); Bool xf86BuiltinInputDriver(const char *);
ConfigStatus xf86HandleConfigFile(Bool); ConfigStatus xf86HandleConfigFile(Bool);

View File

@ -400,14 +400,9 @@ configureModuleSection(void)
{ {
const char **elist, **el; const char **elist, **el;
/* Find the list of extension modules. */
const char *esubdirs[] = {
"extensions",
NULL
};
parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec); parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec);
elist = LoaderListDirs(esubdirs, NULL); elist = LoaderListDir("extensions", NULL);
if (elist) { if (elist) {
for (el = elist; *el; el++) { for (el = elist; *el; el++) {
XF86LoadPtr module; XF86LoadPtr module;
@ -534,6 +529,70 @@ configureDDCMonitorSection(int screennum)
return ptr; 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 void
DoConfigure(void) DoConfigure(void)
{ {
@ -545,7 +604,7 @@ DoConfigure(void)
const char **vlist, **vl; const char **vlist, **vl;
int *dev2screen; int *dev2screen;
vlist = xf86DriverlistFromCompile(); vlist = GenerateDriverList();
if (!vlist) { if (!vlist) {
ErrorF("Missing output drivers. Configuration failed.\n"); ErrorF("Missing output drivers. Configuration failed.\n");
@ -784,7 +843,7 @@ DoShowOptions(void)
char *pSymbol = 0; char *pSymbol = 0;
XF86ModuleData *initData = 0; XF86ModuleData *initData = 0;
if (!(vlist = xf86DriverlistFromCompile())) { if (!(vlist = GenerateDriverList())) {
ErrorF("Missing output drivers\n"); ErrorF("Missing output drivers\n");
goto bail; goto bail;
} }

View File

@ -85,8 +85,7 @@ unsigned long LoaderGetModuleVersion(ModuleDescPtr mod);
void LoaderResetOptions(void); void LoaderResetOptions(void);
void LoaderSetOptions(unsigned long); void LoaderSetOptions(unsigned long);
const char **LoaderListDirs(const char **, const char **); const char **LoaderListDir(const char *, const char **);
void LoaderFreeDirList(char **);
/* Options for LoaderSetOptions */ /* Options for LoaderSetOptions */
#define LDR_OPT_ABI_MISMATCH_NONFATAL 0x0001 #define LDR_OPT_ABI_MISMATCH_NONFATAL 0x0001

View File

@ -448,13 +448,11 @@ FindModule(const char *module, const char *dirname, const char **subdirlist,
} }
const char ** const char **
LoaderListDirs(const char **subdirlist, const char **patternlist) LoaderListDir(const char *subdir, const char **patternlist)
{ {
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
char **pathlist; char **pathlist;
char **elem; char **elem;
const char **subdirs;
const char **s;
PatternPtr patterns = NULL; PatternPtr patterns = NULL;
PatternPtr p; PatternPtr p;
DIR *d; DIR *d;
@ -470,17 +468,15 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
if (!(pathlist = defaultPathList)) if (!(pathlist = defaultPathList))
return NULL; return NULL;
if (!(subdirs = InitSubdirs(subdirlist)))
goto bail;
if (!(patterns = InitPatterns(patternlist))) if (!(patterns = InitPatterns(patternlist)))
goto bail; goto bail;
for (elem = pathlist; *elem; elem++) { for (elem = pathlist; *elem; elem++) {
for (s = subdirs; *s; s++) { if ((dirlen = strlen(*elem) + strlen(subdir) + 1) > PATH_MAX)
if ((dirlen = strlen(*elem) + strlen(*s)) > PATH_MAX)
continue; continue;
strcpy(buf, *elem); strcpy(buf, *elem);
strcat(buf, *s); strcat(buf, "/");
strcat(buf, subdir);
fp = buf + dirlen; fp = buf + dirlen;
if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) && if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) &&
(d = opendir(buf))) { (d = opendir(buf))) {
@ -492,16 +488,14 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
if (dirlen + strlen(dp->d_name) > PATH_MAX) if (dirlen + strlen(dp->d_name) > PATH_MAX)
continue; continue;
strcpy(fp, dp->d_name); strcpy(fp, dp->d_name);
if (!(stat(buf, &stat_buf) == 0 && if (!(stat(buf, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode)))
S_ISREG(stat_buf.st_mode)))
continue; continue;
for (p = patterns; p->pattern; p++) { for (p = patterns; p->pattern; p++) {
if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 && if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 &&
match[1].rm_so != -1) { match[1].rm_so != -1) {
len = match[1].rm_eo - match[1].rm_so; len = match[1].rm_eo - match[1].rm_so;
save = listing; save = listing;
listing = reallocarray(listing, n + 2, listing = reallocarray(listing, n + 2, sizeof(char *));
sizeof(char *));
if (!listing) { if (!listing) {
if (save) { if (save) {
save[n] = NULL; save[n] = NULL;
@ -516,8 +510,7 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
closedir(d); closedir(d);
goto bail; goto bail;
} }
strncpy(listing[n], dp->d_name + match[1].rm_so, strncpy(listing[n], dp->d_name + match[1].rm_so, len);
len);
listing[n][len] = '\0'; listing[n][len] = '\0';
n++; n++;
break; break;
@ -527,23 +520,15 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
closedir(d); closedir(d);
} }
} }
}
if (listing) if (listing)
listing[n] = NULL; listing[n] = NULL;
ret = listing; ret = listing;
bail: bail:
FreePatterns(patterns); FreePatterns(patterns);
FreeSubdirs(subdirs);
return (const char **) ret; return (const char **) ret;
} }
void
LoaderFreeDirList(char **list)
{
FreeStringList(list);
}
static Bool static Bool
CheckVersion(const char *module, XF86ModuleVersionInfo * data, CheckVersion(const char *module, XF86ModuleVersionInfo * data,
const XF86ModReqInfo * req) const XF86ModReqInfo * req)