Skip to content

Add support for piping into wsl-sudo.py #10

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kajic
Copy link

@kajic kajic commented Dec 6, 2024

Make the following work:

echo "foo" | ./wsl-sudo.py cat

Without these changes, cat would hang indefinitely on the pipe.

Fix the issue by:

  1. Prevent the server process from inheriting the client's stdin, by explicitly setting its stdin to subprocess.DEVNULL. The primary reason for this is to prevent the server process from messing up the client's stdin pipe. It's unclear if there is an issue with wsl, but letting the server inherit the pipe seems to consume it, leaving nothing for the client to read.
    Besides, the server receives all of its input from the client-server socket, so it doesn't even need the client's stdin.
  2. Send an empty string CMD_STDIN command from the client to the server when a empty chunk is read from stdin. The client already uses 'empty string' to detect a closed pipe, and now, by also transmitting an empty string to the server, the server can do the same.
  3. Receive the empty string CMD_STDIN in the server's transfer loop, closing the server's child process stdin in response.

Make the following work:
echo "foo" | ./wsl-sudo.py cat

Without these changes, cat would hang indefinitely on the pipe.

Fix the issue by:
1. Prevent the server process from inheriting the client's stdin, by
explicitly setting its stdin to subprocess.DEVNULL. The primary reason
for this is to prevent the server process from messing up the client's
stdin pipe. It's unclear if there is an issue with wsl, but letting the
server inherit the pipe seems to consume it, leaving nothing for the
client to read.
Besides, the server receives all of its input from the client-server
socket, so it doesn't even need the client's stdin.
2. Send an empty string CMD_STDIN command from the client to the server
when a empty chunk is read from stdin. The client already uses
'empty string' to detect a closed pipe, and now, by also transmitting
an empty string to the server, the server can do the same.
3. Receive the empty string CMD_STDIN in the server's transfer loop,
closing the server's child process stdin in response.
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

Successfully merging this pull request may close these issues.

1 participant