From: Kay Sievers Date: Wed, 21 Dec 2011 22:10:56 +0000 (+0100) Subject: add builtin load/unload initializers X-Git-Tag: 176~55 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa29418a13dc1e1eedca702663e733cc8d9f9859;p=systemd add builtin load/unload initializers --- diff --git a/udev/udev-builtin-kmod.c b/udev/udev-builtin-kmod.c index df057735..90f9c564 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 * @@ -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 36821702..9f217276 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 0a3d7c45..a07c525a 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 f8af8992..18f04bf8 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 e807fc05..a7c6226a 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 05d4b2d6..d1f7cd89 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)