[OpenWrt-Devel] [PATCH] block: generate hotplug.d mount events
Alberto Bursi
bobafetthotmail at gmail.com
Wed Dec 5 17:29:34 EST 2018
On 05/12/18 22:35, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal at milecki.pl>
>
> This is what was implemented in mountd and what some scripts used to
> use. It's a pretty generic solution for managing software that may use
> e.g. USB storage.
Could you explain a bit more about what is this doing instead of just
mentioning mountd?
There is pretty scarce info about mountd.
-Alberto
>
> Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
> ---
> block.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/block.c b/block.c
> index 46050b4..fe63fb0 100644
> --- a/block.c
> +++ b/block.c
> @@ -880,6 +880,31 @@ static int exec_mount(const char *source, const char *target,
> return err;
> }
>
> +static void hotplug_call_mount(const char *action, const char *device)
> +{
> + pid_t pid;
> +
> + pid = fork();
> + if (!pid) {
> + char * const argv[] = { "hotplug-call", "mount", NULL };
> + char actionenv[] = "ACTION=xxxxxx";
> + char deviceenv[32];
> + char *envp[] = { actionenv, deviceenv, NULL };
> +
> + snprintf(actionenv, sizeof(actionenv), "ACTION=%s", action);
> + snprintf(deviceenv, sizeof(deviceenv), "DEVICE=%s", device);
> +
> + execve("/sbin/hotplug-call", argv, envp);
> + exit(-1);
> + } else if (pid > 0) {
> + int status;
> +
> + waitpid(pid, &status, 0);
> + if (WEXITSTATUS(status))
> + ULOG_ERR("hotplug-call call failed: %d\n", WEXITSTATUS(status));
> + }
> +}
> +
> static int handle_mount(const char *source, const char *target,
> const char *fstype, struct mount *m)
> {
> @@ -1079,6 +1104,8 @@ static int mount_device(struct probe_info *pr, int type)
>
> handle_swapfiles(true);
>
> + hotplug_call_mount("add", device);
> +
> return 0;
> }
>
> @@ -1091,6 +1118,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,
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list