[PATCH xserver 15/19] loader: Turn LoaderListDirs into LoaderListDir

Adam Jackson ajax at redhat.com
Mon Jan 23 19:32:29 UTC 2017


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).

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 hw/xfree86/common/xf86Config.c    | 76 ------------------------------
 hw/xfree86/common/xf86Config.h    |  1 -
 hw/xfree86/common/xf86Configure.c | 75 +++++++++++++++++++++++++----
 hw/xfree86/loader/loaderProcs.h   |  3 +-
 hw/xfree86/loader/loadmod.c       | 99 +++++++++++++++++----------------------
 5 files changed, 110 insertions(+), 144 deletions(-)

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 3a8f0e1..f03acf3 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -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)
 {
diff --git a/hw/xfree86/common/xf86Config.h b/hw/xfree86/common/xf86Config.h
index 23fb383..bbcb252 100644
--- a/hw/xfree86/common/xf86Config.h
+++ b/hw/xfree86/common/xf86Config.h
@@ -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);
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index e5889b4..f975b98 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -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;
     }
diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index eee9a27..65ca2ec 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -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
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 528cc88..ce10974 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -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)
-- 
2.9.3



More information about the xorg-devel mailing list