-
Notifications
You must be signed in to change notification settings - Fork 322
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
EINVAL when writing to sysfs with "echo param > file" #475
Comments
Ah. Standalone echo requests TOYFLAG_LINEBUF but called as a toybox builtin it can't reset the glibc line buffering because "man 3 setlinebuf" says "may be used only after opening a stream and before any other operations have been performed on it". (You'd think if you did a flush you could then change the buffer, but no. I guess it doesn't track whether you passed in a pointer or it allocated its own, so can't free it?) Anyway, NOFORK is calling echo without line buffering, so the writes are being decoupled. Right. Hmmm... Thanks for the heads up, lemme think about this a bit. (How on earth do I add a check for this to the regression test suite...) |
Did commit 3e0e8c6 fix it for you? I meant to hold off on that until after the next release because I'm going to have missed a flush somewhere, but I've been meaning to do something like that for a while now anyway... Elliott: heads up, that one's a bit intrusive. |
Yup, it looks like it's fixed in master, thank you. |
thanks. i didn't get time for an update today, but i'll have a look next week. (i think relying more on stdio's defaults is a great choice though, so happy to work through the pain with you on that :-) ) |
I was trying to avoid "oops, I missed a flush" whack-a-mole through the entire codebase, but I guess we're confronting that. I confirmed toysh doesn't use stdio (it deals with raw filehandles because of all the redirection, there's input-side FILE * for line reading but no output to them I'm aware of), and most of the rest I can TOYFLAG_LINEBUF the command. Another related TODO item I have is turning read_password() into read_rawline() with an extra "echo" parameter, so I don't need to explicitly fflush() before prompt strings that don't end with a newline. But that gets into "readline() supporting unicode" territory, since hexedit is using lib/utf8.c plumbing for that already. There's still some design work here, so for now I just sprayed it down with fflush() and I can grep for that and pull it back out later... Interactive line editing and command history is the big "toyflag is ready" cliff in the minds of people who don't know the plumbing, so I've been relucant to tackle it with so many known issues still dangling in the code, but at some point I've just gotta push the button... |
Steps to reproduce:
echo <value> > <file>
Expected behavior:
The file is written without errors.
Actual behavior:
The command fails, but the file is written.
Hypothesis:
Echo writes the argument passed to it, and the newline at the end in different write calls. This causes the kernel to try to use "\n" as the value in sysfs, which doesn't work.
Here's a snippet from strace:
But if echo is called with
toybox echo
it works fine:The text was updated successfully, but these errors were encountered: