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

--script-sh breaks with /dev/null or closed stdin #33

Open
lmb opened this issue Jun 25, 2019 · 3 comments
Open

--script-sh breaks with /dev/null or closed stdin #33

lmb opened this issue Jun 25, 2019 · 3 comments

Comments

@lmb
Copy link
Contributor

lmb commented Jun 25, 2019

This is probably an upstream QEMU bug, but I think it'd be good to try and find a work around. The following command hangs indefinitely:

$ virtme-run --show-boot-console --kimg linux-5.2-rc4.bz --script-sh "echo foo" < /dev/null
...
[    2.121087] virtme-init: udev is done
[    2.237338] ip (184) used greatest stack depth: 12488 bytes left
[    2.246030] virtme-init: starting script

If I change virtme-init to strace what is happening, I can see that the script is hanging on writing "foo". Removing < /dev/null makes everything work again.

Usually I wouldn't care, but Docker also redirects stdin to /dev/null. On previous QEMU versions it was possible to work around this by closing stdin via 0<&-, but as of 3.1.0 this breaks.

There is a work-around however:

$ virtme-run --show-boot-console --kimg linux-5.2-rc4.bz --script-sh "echo foo" < /dev/zero

This might end up flooding stdin with zeros, so I'm not sure what the implications of this are. cat | virtme-run doesn't work, since cat just exits due to stdin being /dev/null, which leads to stdin to QEMU being closed.

  • Is there a way to fix this behaviour from virtme-init or similar?
  • If not, is there a better work around than /dev/zero?
lmb added a commit to cilium/ebpf that referenced this issue May 21, 2021
To work around a qemu bug [1] we redirect stdin of virtme-run from
/dev/zero. This has the possible downside that a read from /dev/zero
always returns data. This means that anything reading stdin in the
VM will get a bunch of garbage.

Detect a closed stdin and replace it with an empty fifo.

1: amluto/virtme#33
lmb added a commit to cilium/ebpf that referenced this issue May 26, 2021
To work around a qemu bug [1] we redirect stdin of virtme-run from
/dev/zero. This has the possible downside that a read from /dev/zero
always returns data. This means that anything reading stdin in the
VM will get a bunch of garbage.

Detect a closed stdin and replace it with an empty fifo.

1: amluto/virtme#33
@zevweiss
Copy link
Contributor

Might this problem be resolved by #80?

@marcosps
Copy link
Contributor

@lmb would you try using https://github.com/arighi/virtme and checking if the problem is gone?

@lmb
Copy link
Contributor Author

lmb commented Apr 17, 2023

I don't really have a way to reproduce this anymore, sorry :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants