mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
keventd: add passive mode (-p) for coexistence with hotplug plugin
This is a backwards compatible mode for users upgrading and not noticing that keventd is now build by default. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+54
-32
No files matched your search
+8
-6
@@ -221,7 +221,7 @@ battery:
|
|||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
keventd [-cdGhnv] [-g GROUP]
|
keventd [-cdGhnpv] [-g GROUP]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-c Run coldplug at startup
|
-c Run coldplug at startup
|
||||||
@@ -230,6 +230,7 @@ Usage
|
|||||||
-G Disable netlink rebroadcast entirely
|
-G Disable netlink rebroadcast entirely
|
||||||
-h Show help text
|
-h Show help text
|
||||||
-n Run in foreground (no daemon)
|
-n Run in foreground (no daemon)
|
||||||
|
-p Passive mode: power supply events only
|
||||||
-v Show version
|
-v Show version
|
||||||
|
|
||||||
In normal operation, Finit starts keventd automatically via its system
|
In normal operation, Finit starts keventd automatically via its system
|
||||||
@@ -259,11 +260,12 @@ This means keventd can also be tested independently:
|
|||||||
# Run without rebroadcast (e.g., headless embedded system)
|
# Run without rebroadcast (e.g., headless embedded system)
|
||||||
keventd -c -G
|
keventd -c -G
|
||||||
|
|
||||||
When keventd is enabled, it conflicts with external device managers.
|
Only one device manager should be active at a time. This is settled
|
||||||
Only one device manager should be active at a time. The system
|
at build time: with the hotplug plugin enabled, Finit starts keventd
|
||||||
configuration uses the `conflict:` directive to enforce this:
|
in passive mode (`-p`), leaving device management to the udevd, mdevd,
|
||||||
|
or mdev service from `system/10-hotplug.conf` and monitoring only
|
||||||
service conflict:udevd,mdevd,mdev [...] keventd -c -- Finit device manager
|
power supply events. Without the hotplug plugin, keventd runs as the
|
||||||
|
system device manager (`keventd -c`).
|
||||||
|
|
||||||
[libudev-zero]: https://github.com/illiliti/libudev-zero
|
[libudev-zero]: https://github.com/illiliti/libudev-zero
|
||||||
[mdevd]: https://skarnet.org/software/mdevd/
|
[mdevd]: https://skarnet.org/software/mdevd/
|
||||||
+12
-4
@@ -2683,15 +2683,23 @@ int conf_init(uev_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* Start kernel event daemon as soon as possible, if enabled
|
* Start kernel event daemon as soon as possible, if enabled.
|
||||||
|
* In passive mode (-p) alongside the hotplug plugin, keventd
|
||||||
|
* only monitors power supply events (sys/pwr/ac condition).
|
||||||
*/
|
*/
|
||||||
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
||||||
conf_save_service(SVC_TYPE_SERVICE, "keventd", "keventd.conf",
|
conf_save_service(SVC_TYPE_SERVICE, "keventd", "keventd.conf",
|
||||||
"\tdescription = \"Finit kernel event daemon\"\n"
|
"\tdescription = \"kernel event daemon\"\n"
|
||||||
"\trunlevel = \"S12345789\"\n"
|
"\trunlevel = \"S0123456789\"\n"
|
||||||
"\tnotify = \"none\"\n"
|
"\tnotify = \"none\"\n"
|
||||||
"\tcgroup init {}\n"
|
"\tcgroup init {}\n"
|
||||||
"\tcommand = \"" FINIT_EXECPATH_ "/keventd\"\n");
|
"\tcommand = \"" FINIT_EXECPATH_ "/keventd"
|
||||||
|
#ifdef HAVE_HOTPLUG_PLUGIN
|
||||||
|
" -p"
|
||||||
|
#else
|
||||||
|
" -c"
|
||||||
|
#endif
|
||||||
|
"\"\n");
|
||||||
|
|
||||||
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
||||||
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
||||||
|
|||||||
+34
-22
@@ -76,6 +76,7 @@ static int num_ac;
|
|||||||
static int running = 1;
|
static int running = 1;
|
||||||
static int level;
|
static int level;
|
||||||
static int logon;
|
static int logon;
|
||||||
|
static int passive; /* power-supply only, no device management */
|
||||||
|
|
||||||
int debug; /* debug in other modules as well */
|
int debug; /* debug in other modules as well */
|
||||||
|
|
||||||
@@ -283,29 +284,33 @@ static void handle_uevent(char *buf, size_t len)
|
|||||||
|
|
||||||
switch (ev.action) {
|
switch (ev.action) {
|
||||||
case ACT_ADD:
|
case ACT_ADD:
|
||||||
/* Firmware loading takes priority */
|
if (!passive) {
|
||||||
if (ev.firmware)
|
/* Firmware loading takes priority */
|
||||||
firmware_load(&ev);
|
if (ev.firmware)
|
||||||
|
firmware_load(&ev);
|
||||||
|
|
||||||
/* Module loading */
|
/* Module loading */
|
||||||
if (ev.modalias)
|
if (ev.modalias)
|
||||||
modprobe_load(ev.modalias);
|
modprobe_load(ev.modalias);
|
||||||
|
|
||||||
/* Create device node if we have the info */
|
/* Create device node if we have the info */
|
||||||
if (ev.major >= 0 && ev.minor >= 0 && ev.devname)
|
if (ev.major >= 0 && ev.minor >= 0 && ev.devname)
|
||||||
devnode_add(&ev);
|
devnode_add(&ev);
|
||||||
|
|
||||||
/* Create symlinks */
|
/* Create symlinks */
|
||||||
symlink_add(&ev);
|
symlink_add(&ev);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACT_REMOVE:
|
case ACT_REMOVE:
|
||||||
/* Remove symlinks first */
|
if (!passive) {
|
||||||
symlink_del(&ev);
|
/* Remove symlinks first */
|
||||||
|
symlink_del(&ev);
|
||||||
|
|
||||||
/* Remove device node */
|
/* Remove device node */
|
||||||
if (ev.devname)
|
if (ev.devname)
|
||||||
devnode_del(&ev);
|
devnode_del(&ev);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACT_CHANGE:
|
case ACT_CHANGE:
|
||||||
@@ -412,7 +417,7 @@ static void shut_down(int signo)
|
|||||||
static int usage(int rc)
|
static int usage(int rc)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: keventd [-dGhnv] [-c] [-g GROUP]\n"
|
"Usage: keventd [-dGhnpv] [-c] [-g GROUP]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -c Run coldplug at startup\n"
|
" -c Run coldplug at startup\n"
|
||||||
@@ -421,6 +426,7 @@ static int usage(int rc)
|
|||||||
" -G Disable netlink rebroadcast entirely\n"
|
" -G Disable netlink rebroadcast entirely\n"
|
||||||
" -h Show this help text\n"
|
" -h Show this help text\n"
|
||||||
" -n Run in foreground (no daemon)\n"
|
" -n Run in foreground (no daemon)\n"
|
||||||
|
" -p Passive mode: power supply events only (no device management)\n"
|
||||||
" -v Show version\n"
|
" -v Show version\n"
|
||||||
"\n", REBC_DEFAULT_NLGROUP);
|
"\n", REBC_DEFAULT_NLGROUP);
|
||||||
|
|
||||||
@@ -454,7 +460,7 @@ int main(int argc, char *argv[])
|
|||||||
* requested bits verbatim instead of masking them. */
|
* requested bits verbatim instead of masking them. */
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "cdg:Ghnv")) != -1) {
|
while ((c = getopt(argc, argv, "cdg:Ghnpv")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
do_coldplug = 1;
|
do_coldplug = 1;
|
||||||
@@ -474,6 +480,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'n':
|
case 'n':
|
||||||
foreground = 1;
|
foreground = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
passive = 1;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("keventd v%s\n", KEVENTD_VERSION);
|
printf("keventd v%s\n", KEVENTD_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -498,8 +507,10 @@ int main(int argc, char *argv[])
|
|||||||
init_power_supply();
|
init_power_supply();
|
||||||
init_dev_condition_dir();
|
init_dev_condition_dir();
|
||||||
|
|
||||||
/* Disable legacy kernel uevent helper; we own events via netlink */
|
/* Disable legacy kernel uevent helper; we own events via netlink.
|
||||||
disable_uevent_helper();
|
* Skip in passive mode -- the hotplug daemon handles this. */
|
||||||
|
if (!passive)
|
||||||
|
disable_uevent_helper();
|
||||||
|
|
||||||
/* Set up netlink socket for kernel uevents */
|
/* Set up netlink socket for kernel uevents */
|
||||||
pfd.events = POLLIN;
|
pfd.events = POLLIN;
|
||||||
@@ -519,8 +530,9 @@ int main(int argc, char *argv[])
|
|||||||
setsockopt(pfd.fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
|
setsockopt(pfd.fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize rebroadcast socket (default on, -G to disable) */
|
/* Initialize rebroadcast socket (default on, -G to disable).
|
||||||
if (nlgroups)
|
* Skip in passive mode -- the hotplug daemon rebroadcasts. */
|
||||||
|
if (nlgroups && !passive)
|
||||||
rebc_init(nlgroups);
|
rebc_init(nlgroups);
|
||||||
|
|
||||||
/* Run coldplug if requested */
|
/* Run coldplug if requested */
|
||||||
|
|||||||
Reference in new issue
Block a user