mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
add builtin load/unload initializers
This commit is contained in:
parent
81dadce58f
commit
aa29418a13
@ -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,
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user