libcamera: ipa_manager: Sort IPA modules by name

Sort IPA modules by name when enumerating modules in a directory in
order to guarantee a stable ordering. This eases debugging by making
issues more reproducible.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2019-10-03 23:57:12 +03:00
parent f102ea69cc
commit 200bb4c60f

View file

@ -7,6 +7,7 @@
#include "ipa_manager.h" #include "ipa_manager.h"
#include <algorithm>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -112,7 +113,7 @@ int IPAManager::addDir(const char *libDir)
if (!dir) if (!dir)
return -errno; return -errno;
unsigned int count = 0; std::vector<std::string> paths;
while ((ent = readdir(dir)) != nullptr) { while ((ent = readdir(dir)) != nullptr) {
int offset = strlen(ent->d_name) - 3; int offset = strlen(ent->d_name) - 3;
if (offset < 0) if (offset < 0)
@ -120,8 +121,16 @@ int IPAManager::addDir(const char *libDir)
if (strcmp(&ent->d_name[offset], ".so")) if (strcmp(&ent->d_name[offset], ".so"))
continue; continue;
IPAModule *ipaModule = new IPAModule(std::string(libDir) + paths.push_back(std::string(libDir) + "/" + ent->d_name);
"/" + ent->d_name); }
closedir(dir);
/* Ensure a stable ordering of modules. */
std::sort(paths.begin(), paths.end());
unsigned int count = 0;
for (const std::string &path : paths) {
IPAModule *ipaModule = new IPAModule(path);
if (!ipaModule->isValid()) { if (!ipaModule->isValid()) {
delete ipaModule; delete ipaModule;
continue; continue;
@ -131,7 +140,6 @@ int IPAManager::addDir(const char *libDir)
count++; count++;
} }
closedir(dir);
return count; return count;
} }