Re: What's the practical use of the error close() returns?

2012-07-29 Thread Daniel Shahaf
Shachar Shemesh wrote on Sun, Jul 29, 2012 at 06:35:18 +0300: On 07/29/2012 02:12 AM, Daniel Shahaf wrote: So if the disk hardware fails after close() returns but before the OS caches are flushed... It is not part of close(2)'s job description to protect against this scenario. If you

Re: What's the practical use of the error close() returns?

2012-07-28 Thread Shachar Shemesh
On 07/27/2012 02:52 PM, Elazar Leibovich wrote: (as mentioned earlier, the no space left could just as well happen after the file was closed, so I don't mind that much it's not reported on a close()) Ehm, no. First of all, please note a subtle but important difference between your question

Re: What's the practical use of the error close() returns?

2012-07-28 Thread Amos Shapira
BTW - everyone here keeps assuming that close(2) is called on disk files, what about other types of file descriptors (sockets, pipes, character and block devices, virtual filesystem files)? How would you adjust your answers for that case? On 28 July 2012 16:56, Shachar Shemesh shac...@shemesh.biz

Re: What's the practical use of the error close() returns?

2012-07-28 Thread Daniel Shahaf
Shachar Shemesh wrote on Sat, Jul 28, 2012 at 09:56:40 +0300: On 07/27/2012 02:52 PM, Elazar Leibovich wrote: (as mentioned earlier, the no space left could just as well happen after the file was closed, so I don't mind that much it's not reported on a close()) Ehm, no. First of

Re: What's the practical use of the error close() returns?

2012-07-28 Thread Shachar Shemesh
On 07/29/2012 02:12 AM, Daniel Shahaf wrote: So if the disk hardware fails after close() returns but before the OS caches are flushed... It is not part of close(2)'s job description to protect against this scenario. If you want to protect against this scenario, use sync(2). Shachar --

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Orna Agmon Ben-Yehuda
My practical answer: I always check fclose() . It happened to me that it returned errors when the file I was trying to close was already closed (which usually meant I had a bug, because I closed one file twice, another never. It also failed with no space left on device, when it was trying to

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Elazar Leibovich
Thanks! You nailed it! closing a file twice is an error that makes sense to be issued at close. So simple, how could I miss it? (as mentioned earlier, the no space left could just as well happen after the file was closed, so I don't mind that much it's not reported on a close()) On Fri, Jul 27,

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Orna Agmon Ben-Yehuda
On Fri, Jul 27, 2012 at 2:52 PM, Elazar Leibovich elaz...@gmail.com wrote: Thanks! You nailed it! closing a file twice is an error that makes sense to be issued at close. So simple, how could I miss it? (as mentioned earlier, the no space left could just as well happen after the file was

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Oleg Goldshmidt
On Fri, Jul 27, 2012 at 2:52 PM, Elazar Leibovich elaz...@gmail.com wrote: You nailed it! closing a file twice is an error that makes sense to be issued at close. So simple, how could I miss it? Not only for catching your bugs. If fclose(3) returns an error any further access to the

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Baruch Even
On Fri, Jul 27, 2012 at 7:06 PM, Oleg Goldshmidt p...@goldshmidt.org wrote: On Fri, Jul 27, 2012 at 2:52 PM, Elazar Leibovich elaz...@gmail.com wrote: You nailed it! closing a file twice is an error that makes sense to be issued at close. So simple, how could I miss it? Not only for

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Oleg Goldshmidt
This might not really be helpful to know, the file descriptor is left in an unspecified state according to POSIX, see: http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR The fact that POSIX does not specify the fd's state is, indeed, not helpful. The *reason* why it does not specify it is

Re: What's the practical use of the error close() returns?

2012-07-27 Thread Nadav Har'El
On Fri, Jul 27, 2012, Elazar Leibovich wrote about Re: What's the practical use of the error close() returns?: You nailed it! closing a file twice is an error that makes sense to be issued at close. So simple, how could I miss it? Yes, that's a good reason - nice catch. I also didn't think

What's the practical use of the error close() returns?

2012-07-26 Thread Elazar Leibovich
I was always intrigued by this unix tidbit, closing a file can return an error. In practice, it is rarely checked (as far as I've seen) What does it mean? If I understand it correctly, recent write can lie about its success. But when do you really need it? If you have a piece of information you

Re: What's the practical use of the error close() returns?

2012-07-26 Thread Nadav Har'El
On Thu, Jul 26, 2012, Elazar Leibovich wrote about What's the practical use of the error close() returns?: I was always intrigued by this unix tidbit, closing a file can return an error. In practice, it is rarely checked (as far as I've seen) Here are my two cents: In Unix/Linux, writing

Re: What's the practical use of the error close() returns?

2012-07-26 Thread Elazar Leibovich
On Fri, Jul 27, 2012 at 12:12 AM, Nadav Har'El n...@math.technion.ac.ilwrote: So it seems to me that checking the close() only *sometimes* lets you know of write errors which you'll otherwise miss. But since you'll anyway miss other write errors (those coming after the close()), it's not