summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2011-12-21 23:10:56 +0100
committerKay Sievers <kay.sievers@vrfy.org>2011-12-21 23:10:56 +0100
commitaa29418a13dc1e1eedca702663e733cc8d9f9859 (patch)
tree9e72f070d6176c329c285fcd50b1661e7d8b337f
parent81dadce58f80edae4dc45ba55a2c41cb0f26570b (diff)
add builtin load/unload initializers
-rw-r--r--udev/udev-builtin-kmod.c21
-rw-r--r--udev/udev-builtin.c20
-rw-r--r--udev/udev.h4
-rw-r--r--udev/udevadm-test-builtin.c3
-rw-r--r--udev/udevadm-test.c3
-rw-r--r--udev/udevd.c3
6 files changed, 53 insertions, 1 deletions
diff --git a/udev/udev-builtin-kmod.c b/udev/udev-builtin-kmod.c
index df057735d7..90f9c564ed 100644
--- a/udev/udev-builtin-kmod.c
+++ b/udev/udev-builtin-kmod.c
@@ -1,5 +1,5 @@
/*
- * probe disks for filesystems and partitions
+ * load kernel modules
*
* Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
*
@@ -28,15 +28,34 @@
#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,
};
diff --git a/udev/udev-builtin.c b/udev/udev-builtin.c
index 36821702c1..9f21727699 100644
--- a/udev/udev-builtin.c
+++ b/udev/udev-builtin.c
@@ -33,6 +33,26 @@ static const struct udev_builtin *builtins[] = {
[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;
diff --git a/udev/udev.h b/udev/udev.h
index 0a3d7c4506..a07c525a89 100644
--- a/udev/udev.h
+++ b/udev/udev.h
@@ -158,6 +158,8 @@ struct udev_builtin {
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;
@@ -165,6 +167,8 @@ extern const struct udev_builtin udev_builtin_usb_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);
diff --git a/udev/udevadm-test-builtin.c b/udev/udevadm-test-builtin.c
index f8af8992d0..18f04bf888 100644
--- a/udev/udevadm-test-builtin.c
+++ b/udev/udevadm-test-builtin.c
@@ -99,6 +99,8 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[])
goto out;
}
+ udev_builtin_load(udev);
+
cmd = udev_builtin_lookup(command);
if (cmd >= UDEV_BUILTIN_MAX) {
fprintf(stderr, "unknown command '%s'\n", command);
@@ -113,6 +115,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[])
}
out:
udev_device_unref(dev);
+ udev_builtin_unload(udev);
return rc;
}
diff --git a/udev/udevadm-test.c b/udev/udevadm-test.c
index e807fc05a6..a7c6226a56 100644
--- a/udev/udevadm-test.c
+++ b/udev/udevadm-test.c
@@ -103,6 +103,8 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
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");
@@ -159,6 +161,7 @@ out:
udev_event_unref(event);
udev_device_unref(dev);
udev_rules_unref(rules);
+ udev_builtin_unload(udev);
return rc;
}
diff --git a/udev/udevd.c b/udev/udevd.c
index 05d4b2d66b..d1f7cd8909 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -1513,6 +1513,8 @@ int main(int argc, char *argv[])
}
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");
@@ -1712,6 +1714,7 @@ exit_daemonize:
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)