Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

busybox: 'ash: write error: EPIPE' when piping some large text variable into head command #166

Open
damianloew opened this issue Aug 12, 2021 · 2 comments · May be fixed by phoenix-rtos/libphoenix#124
Labels
busybox test suite Issues that cause fails in busybox test suite libphoenix

Comments

@damianloew
Copy link
Contributor

damianloew commented Aug 12, 2021

Screenshot from 2021-08-12 13-00-55
To reproduce:

  1. edit /etc/rc.psh in rootskel like that (for posixsrv run in background):
    image

  2. run system image

  3. run /bin/psh /etc/rc.psh (for posixsrv run in background)

  4. run /bin/sh

  5. run text='yes abc | head -c 9999'

  6. run echo "$text" | head -c 5

@Maxez
Copy link

Maxez commented Aug 17, 2021

Code in echo.c which prints the error (full_write() sets errno to EPIPE):

errno = 0;
/*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer);
free(buffer);
if (/*WRONG:r < 0*/ errno) {
    bb_perror_msg(bb_msg_write_error);
    return 1;
}

Busybox applets (echo in this case) assume correct SIGPIPE signal behaviour which terminates the process.
As a quick check I modified proc_write() in kernel so that SIGPIPE signal gets sent:

err = proc_send(oid.port, msg);

if (err >= 0) {
    if ((err = msg->o.io.err) == -EPIPE)
	threads_sigpost(proc_current()->process, proc_current(), 13 /*SIGPIPE*/);
}

As a result default SIGPIPE signal handler terminates the process and error messages no longer appear on the screen:
sigpipe

Please note that 'the quick check' probably isn't a correct way of sending SIGPIPE signal - I'll check how it should be done.

@nalajcie
Copy link
Member

Verified on host (linux) that the echo $text process is being killed by SIGPIPE (incomplete write) if the write size exceeds the kernel pipe buffer (65535 bytes by default), code to reproduce:

strace -f busybox ash -c 'text=$(yes abc | head -c 655360); busybox echo $text | busybox head -c 5'

image

I don't know if the EPIPE errno is being set in case of partial write (to be checked).

Maxez pushed a commit to phoenix-rtos/libphoenix that referenced this issue Aug 19, 2021
@damianloew damianloew added the busybox test suite Issues that cause fails in busybox test suite label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
busybox test suite Issues that cause fails in busybox test suite libphoenix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants