/*
- * probe disks for filesystems and partitions
+ * load kernel modules
*
* Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
*
#include "udev.h"
+static char *kmod;
+
static int builtin_kmod(struct udev_device *dev, const char *command, bool test)
{
printf("soon we load a module here: '%s'\n", command);
+ printf("test: %s\n", kmod);
return EXIT_SUCCESS;
}
+static int builtin_kmod_load(struct udev *udev)
+{
+ printf("load module index\n");
+ asprintf(&kmod, "pid: %u\n", getpid());
+ return 0;
+}
+
+static int builtin_kmod_unload(struct udev *udev)
+{
+ printf("unload module index\n");
+ free(kmod);
+ return 0;
+}
+
const struct udev_builtin udev_builtin_kmod = {
.name = "kmod",
.cmd = builtin_kmod,
+ .load = builtin_kmod_load,
+ .unload = builtin_kmod_unload,
.help = "kernel module loader",
.run_once = false,
};
[UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
};
+int udev_builtin_load(struct udev *udev)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(builtins); i++)
+ if (builtins[i]->load)
+ builtins[i]->load(udev);
+ return 0;
+}
+
+int udev_builtin_unload(struct udev *udev)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(builtins); i++)
+ if (builtins[i]->unload)
+ builtins[i]->unload(udev);
+ return 0;
+}
+
int udev_builtin_list(struct udev *udev)
{
unsigned int i;
const char *name;
int (*cmd)(struct udev_device *dev, const char *command, bool test);
const char *help;
+ int (*load)(struct udev *udev);
+ int (*unload)(struct udev *udev);
bool run_once;
};
extern const struct udev_builtin udev_builtin_path_id;
extern const struct udev_builtin udev_builtin_input_id;
extern const struct udev_builtin udev_builtin_blkid;
extern const struct udev_builtin udev_builtin_kmod;
+int udev_builtin_load(struct udev *udev);
+int udev_builtin_unload(struct udev *udev);
enum udev_builtin_cmd udev_builtin_lookup(const char *command);
const char *udev_builtin_name(enum udev_builtin_cmd cmd);
bool udev_builtin_run_once(enum udev_builtin_cmd cmd);
goto out;
}
+ udev_builtin_load(udev);
+
cmd = udev_builtin_lookup(command);
if (cmd >= UDEV_BUILTIN_MAX) {
fprintf(stderr, "unknown command '%s'\n", command);
}
out:
udev_device_unref(dev);
+ udev_builtin_unload(udev);
return rc;
}
sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
+ udev_builtin_load(udev);
+
rules = udev_rules_new(udev, resolve_names);
if (rules == NULL) {
fprintf(stderr, "error reading rules\n");
udev_event_unref(event);
udev_device_unref(dev);
udev_rules_unref(rules);
+ udev_builtin_unload(udev);
return rc;
}
}
fd_worker = worker_watch[READ_END];
+ udev_builtin_load(udev);
+
rules = udev_rules_new(udev, resolve_names);
if (rules == NULL) {
err(udev, "error reading rules\n");
worker_list_cleanup(udev);
event_queue_cleanup(udev, EVENT_UNDEF);
udev_rules_unref(rules);
+ udev_builtin_unload(udev);
if (fd_signal >= 0)
close(fd_signal);
if (worker_watch[READ_END] >= 0)