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

emu86: unbounded e command doesn't work when no stdin is available #7

Open
hintron opened this issue Jun 13, 2023 · 4 comments
Open
Labels
bug Something isn't working

Comments

@hintron
Copy link
Owner

hintron commented Jun 13, 2023

I'm trying to set up regression tests to run on the Git pre-commit hook. The problem is that the hook is not an interactive shell, so stdin is disabled/points to nothing. This messes up with the e command, though the e N command seems to work just fine. The symptoms of e are that nothing is printed to the debug terminal and the program hangs indefinitely.

@hintron
Copy link
Owner Author

hintron commented Jun 13, 2023

In addition to replacing e with e N, it also seems to work if the pre-commit script re-introduces stdin like so

exec < /dev/tty

See https://stackoverflow.com/questions/3417896/how-do-i-prompt-the-user-from-within-a-commit-msg-hook.

@hintron hintron added the bug Something isn't working label Jun 13, 2023
@hintron
Copy link
Owner Author

hintron commented Jun 13, 2023

SimControl.cpp:

void CSimControl::Execute(unsigned int repeatCount)
...
		if(ProgramWindow.KeyPress()) c = ProgramWindow.GetProgramInput();

Conio.cpp:

// Returns key if a key has been pressed and is waiting to be read.
bool keyPress(void)
{
	FD_SET(STDIN_FD, &stdin_wait_set);

	if(select(1, &stdin_wait_set, NULL, NULL, &tm_zero) > 0) return true;
	return false;
}

I need to debug to see what happens here when STDIN_FD is closed. But it seems like it's undefined behavior:

https://stackoverflow.com/questions/543541/what-does-select2-do-if-you-close2-a-file-descriptor-in-a-separate-thread

Perhaps I could add some kind of check that skips checking for input if stdin is closed

@hintron
Copy link
Owner Author

hintron commented Jun 14, 2023

It looks like the problem is not that stdin is closed, but rather that it's set to /dev/null. When stdin is closed, e works just fine.

@hintron
Copy link
Owner Author

hintron commented Jun 14, 2023

Here's a reproducer:

exec 0</dev/null
emu86 -c "l artoss.bin;simptris;e"

So the Git pre-commit hook must set stdin to /dev/null, which messes things up.

Closing stdin completely works fine:

exec 0<&-
emu86 -c "l artoss.bin;simptris;e"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant