read() called twice for /proc files
woops! sent too early!
Is there a general solution to the case of read() being called minimum twice for a file in /proc? I have a small file in /proc, whose data takes a fair time to generate. My read() handler gets called once for the data, and once so I can return 0 to terminate read().
This results in the actual read taking twice as long. Perhaps I am missing something...
What if the proc generic stuff used file->private_data as an EOF flag. It seems really bizarre that the read loop loops until return 0 or eof is set. We promptly throw away the EOF information that the read() handler set.
Would it break anything? Is there something I am not seeing in the larger picture?
Signature · 4 lines
Tim Hockin Systems Software Engineer Sun Microsystems, Cobalt Server Appliances [email protected]
Quoted 4 lines · Tim Hockin
Is there a general solution to the case of
read()being called minimum twice for a file in /proc? I have a small file in /proc, whose data takes a fair time to generate. Myread()handler gets called once for the data, and once so I can return 0 to terminateread().
I'm guessing you mean that the user is calling read once (and not a second time to get the 0/eof return), and that proc_file_read() is calling your read_proc twice. If that's the case, you can just set the eof flag on the first call (on which you return the data), and you won't be called again unless the user reads again.
And of course, as David Miller suggests, you can check the offset first, before generating data.
Signature · 1 line
/Jonathan Lundell.