From: Rafał Miłecki <ra...@milecki.pl> With this change block generates 2 "mount" hotplug.d subsystem events: 1) "add" when block device gets mounted 2) "remove" when block device gets unmounted
This allows e.g. controlling USB storage dependant software using hotplug.d listeners. A very similar solution was implemented in mountd which was replaced by blockd. Signed-off-by: Rafał Miłecki <ra...@milecki.pl> --- V2: Use hotplug_call() helper. It requires [PATCH libubox] hotplug: add hotplug_call() helper --- block.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/block.c b/block.c index 46050b4..99e02b0 100644 --- a/block.c +++ b/block.c @@ -38,6 +38,7 @@ #include <uci.h> #include <uci_blob.h> +#include <libubox/hotplug.h> #include <libubox/ulog.h> #include <libubox/list.h> #include <libubox/vlist.h> @@ -880,6 +881,24 @@ static int exec_mount(const char *source, const char *target, return err; } +static int hotplug_call_mount(const char *action, const char *device) +{ + char actionenv[] = "ACTION=xxxxxx"; + char deviceenv[32]; + char *envp[] = { actionenv, deviceenv, NULL }; + int err; + + snprintf(actionenv, sizeof(actionenv), "ACTION=%s", action); + snprintf(deviceenv, sizeof(deviceenv), "DEVICE=%s", device); + + err = hotplug_call("mount", envp); + if (err) { + ULOG_ERR("hotplug-call call failed: %d\n", err); + } + + return err; +} + static int handle_mount(const char *source, const char *target, const char *fstype, struct mount *m) { @@ -1079,6 +1098,8 @@ static int mount_device(struct probe_info *pr, int type) handle_swapfiles(true); + hotplug_call_mount("add", device); + return 0; } @@ -1091,6 +1112,8 @@ static int umount_device(char *path) if (!mp) return -1; + hotplug_call_mount("remove", basename(path)); + err = umount2(mp, MNT_DETACH); if (err) ULOG_ERR("unmounting %s (%s) failed (%d) - %m\n", path, mp, -- 2.13.7 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel