diff --git a/hardware.c b/hardware.c index 9651f4c8..da89dd9c 100644 --- a/hardware.c +++ b/hardware.c @@ -117,15 +117,34 @@ static int load(const char *id, return status; } +/* + * Check if a HAL with given name and subname exists, if so return 0, otherwise + * otherwise return negative. On success path will contain the path to the HAL. + */ +static int hw_module_exists(char *path, size_t path_len, const char *name, + const char *subname) +{ + snprintf(path, path_len, "%s/%s.%s.so", + HAL_LIBRARY_PATH2, name, subname); + if (access(path, R_OK) == 0) + return 0; + + snprintf(path, path_len, "%s/%s.%s.so", + HAL_LIBRARY_PATH1, name, subname); + if (access(path, R_OK) == 0) + return 0; + + return -ENOENT; +} + int hw_get_module_by_class(const char *class_id, const char *inst, const struct hw_module_t **module) { - int status; int i; - const struct hw_module_t *hmi = NULL; char prop[PATH_MAX]; char path[PATH_MAX]; char name[PATH_MAX]; + char prop_name[PATH_MAX]; if (inst) snprintf(name, PATH_MAX, "%s.%s", class_id, inst); @@ -139,38 +158,35 @@ int hw_get_module_by_class(const char *class_id, const char *inst, * We also assume that dlopen() is thread-safe. */ - /* Loop through the configuration variants looking for a module */ - for (i=0 ; i