Handling kernel uevent in userspace
⚫ ueventd ⚬ ueventd creates and 'poll' netlink socket. ueventd_main [init/ueventd.c] ⚬ read kernel event message -> parse -> handle handle_device_event [init/devices.c] -> device_changed [init/init.c] -> queue_device_triggers [init/init_parser.c] | +---------------+ | v : search action list to know what to do for this event. searching action which name is device-added/removed-[device node]. [device node] is from 'DEVPATH' variable of uevent message. ⚬ action list : list declared at [init_parser.c] • builtin action (added by 'queue_builtin_action [init/init_parser.c]') ex. property_init, wait_for_coldboot_done etc. • from script (added by 'parse_action [init/init_parser.c]') section "on device-added-[device path] / on device-removed-[device path]" ex. [init.rc] on device-added-/dev/block/mmcblk0p18 exec /system/bin/sh /system/bin/hello_mmc.sh ⚫ other daemons (ex usbd) ⚬ create and 'poll' netlink socket.
kobject uevent in kernel
⚫ Sendig kobject uevent to user space from kernel ⚬ Concept • Execute user-space binary with predefined + customized environment variables. • Send message to pre-defined netlink socket unit created by kernel. ⚬ From souce code (hotplug) • kernel node [kernel/sysctl.c] (ctl_table) : /proc/sys/kernel/hotplug • kobject_uevent_env() [kobject_uevent.c] default user process executable image path -> CONFIG_UEVENT_HELPER_PATH • kernel/sysctl.c 'uevent_helper' value can be RWed through 'hotplug' node of sysctl. ⚬ From souce code (netlink) • kobject_uevent_env() [kobject_uevent.c] : #if defined(CONFIG_NET) write message to netlink socket unit (NETLINK_KOBJECT_UEVENT) • netlink.h netlink units • Creating in userspace socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT)
No comments:
Post a Comment