* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <unistd.h>
+#include <ctype.h>
#include <errno.h>
#include <fnmatch.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
-#include <sys/utsname.h>
+#include <unistd.h>
#include <sys/stat.h>
+#include <sys/utsname.h>
+
+#include <shared/hash.h>
+#include <shared/util.h>
#include "libkmod.h"
#include "libkmod-internal.h"
[KMOD_INDEX_MODULES_DEP] = { .fn = "modules.dep", .prefix = "" },
[KMOD_INDEX_MODULES_ALIAS] = { .fn = "modules.alias", .prefix = "alias " },
[KMOD_INDEX_MODULES_SYMBOL] = { .fn = "modules.symbols", .prefix = "alias "},
+ [KMOD_INDEX_MODULES_BUILTIN_ALIAS] = { .fn = "modules.builtin.alias", .prefix = "" },
[KMOD_INDEX_MODULES_BUILTIN] = { .fn = "modules.builtin", .prefix = ""},
};
vfprintf(fp, format, args);
}
-const char *kmod_get_dirname(const struct kmod_ctx *ctx)
+
+/**
+ * kmod_get_dirname:
+ * @ctx: kmod library context
+ *
+ * Retrieve the absolute path used for linux modules in this context. The path
+ * is computed from the arguments to kmod_new().
+ */
+KMOD_EXPORT const char *kmod_get_dirname(const struct kmod_ctx *ctx)
{
return ctx->dirname;
}
* @config_paths: ordered array of paths (directories or files) where
* to load from user-defined configuration parameters such as
* alias, blacklists, commands (install, remove). If
- * NULL defaults to /run/modprobe.d, /etc/modprobe.d and
+ * NULL defaults to /etc/modprobe.d, /run/modprobe.d and
* /lib/modprobe.d. Give an empty vector if configuration should
* not be read. This array must be null terminated.
*
fail:
*list = kmod_list_remove_n_latest(*list, nmatch);
+ index_values_free(realnames);
return err;
}
name, list);
}
-int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
{
- char *line = NULL;
- int err = 0;
-
- assert(*list == NULL);
+ char *line;
if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) {
DBG(ctx, "use mmaped index '%s' modname=%s\n",
idx = index_file_open(fn);
if (idx == NULL) {
DBG(ctx, "could not open builtin file '%s'\n", fn);
- goto finish;
+ return NULL;
}
line = index_search(idx, name);
index_file_close(idx);
}
+ return line;
+}
+
+int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx,
+ const char *name,
+ struct kmod_list **list)
+{
+ struct kmod_list *l;
+ int ret;
+
+ assert(*list == NULL);
+
+ ret = kmod_lookup_alias_from_alias_bin(ctx,
+ KMOD_INDEX_MODULES_BUILTIN_ALIAS,
+ name, list);
+
+ kmod_list_foreach(l, *list) {
+ struct kmod_module *mod = l->data;
+ kmod_module_set_builtin(mod, true);
+ }
+
+ return ret;
+}
+
+int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
+ struct kmod_list **list)
+{
+ char *line;
+ int err = 0;
+
+ assert(*list == NULL);
+
+ line = lookup_builtin_file(ctx, name);
if (line != NULL) {
struct kmod_module *mod;
goto finish;
}
+ /* already mark it as builtin since it's being created from
+ * this index */
kmod_module_set_builtin(mod, true);
*list = kmod_list_append(*list, mod);
if (*list == NULL)
return err;
}
+bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name)
+{
+ _cleanup_free_ char *line;
+
+ line = lookup_builtin_file(ctx, name);
+
+ return line != NULL;
+}
+
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name)
{
struct index_file *idx;
kmod_module_set_visited((struct kmod_module *)v, visited);
}
+void kmod_set_modules_required(struct kmod_ctx *ctx, bool required)
+{
+ struct hash_iter iter;
+ const void *v;
+
+ hash_iter_init(ctx->modules_by_name, &iter);
+ while (hash_iter_next(&iter, NULL, &v))
+ kmod_module_set_required((struct kmod_module *)v, required);
+}
+
static bool is_cache_invalid(const char *path, unsigned long long stamp)
{
struct stat st;
*/
KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
{
+ int ret = 0;
size_t i;
if (ctx == NULL)
snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
index_files[i].fn);
- ctx->indexes[i] = index_mm_open(ctx, path,
- &ctx->indexes_stamp[i]);
- if (ctx->indexes[i] == NULL)
- goto fail;
+ ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i],
+ &ctx->indexes[i]);
+
+ /*
+ * modules.builtin.alias are considered optional since it's
+ * recently added and older installations may not have it;
+ * we allow failing for any reason
+ */
+ if (ret) {
+ if (i != KMOD_INDEX_MODULES_BUILTIN_ALIAS)
+ break;
+ ret = 0;
+ }
}
- return 0;
+ if (ret)
+ kmod_unload_resources(ctx);
-fail:
- kmod_unload_resources(ctx);
- return -ENOMEM;
+ return ret;
}
/**