[Bug 3547] shell read is maybe too safe
Denys Vlasenko
vda.linux at googlemail.com
Mon Apr 11 01:04:06 UTC 2011
On Thursday 07 April 2011 22:50, Ian Wienand wrote:
> The following doesn't exit when SIGHUP is sent to busybox ash/hush,
> but waits for something to be read.
>
> ---
> #!/bin/sh
> echo $$
> trap "exit 0" HUP
> while [ 1 ]
> do
> read ignored
> done
> ---
>
> bash and dash on my system does exit straight away
>
> safe_read appears to ignore EINTR, which I guess it too safe in this
> situation
>
> -i
>
> Signed-off-by: Ian Wienand <ianw at vmware.com>
> ---
> libbb/read_printf.c | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/libbb/read_printf.c b/libbb/read_printf.c
> index 8664bc6..23943db 100644
> --- a/libbb/read_printf.c
> +++ b/libbb/read_printf.c
> @@ -61,9 +61,16 @@ ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count)
> ssize_t n;
>
> while (1) {
> - n = safe_read(fd, buf, count);
> - if (n >= 0 || errno != EAGAIN)
> + /*
> + * note safe_read is a little too safe here; if a
> + * signal comes in while we are reading (causing read
> + * to return EINTR) we should terminate so any
> + * potential trap handler can run.
> + */
*trap* handler?
This is a generic libbb function, not a shell-specific function.
The comment assumes the function is shell specific.
Which is conceptually wrong.
But there's a bigger problem:
I tested the patch and it fixes ash but doesn't fix hush...
--
vda
More information about the busybox
mailing list