Set f_file to -1/F_UNUSED when possible after closing them
This will help avoid trashing file descriptors that get reused later in the
daemon
Sponsored by: EMC / Isilon Storage Division
Submitted by: Miles Ohlrich <miles.ohlrich@isilon.com>
Differential D3081
Set f_file to -1/F_UNUSED when possible after closing it to avoid trashing/double-closing file descriptors later ngie on Jul 14 2015, 8:43 PM. Authored by Tags None Referenced Files
Details
Diff Detail
Event TimelineComment Actions Hi NGie, Looking at the code, I see that in some places we discard an entry from the list by setting its type to F_UNUSED, instead of clearing the file descriptor number. Would you by any chance know what's up with that? Maybe all of these code paths should do the same? Still, I think that setting the file descriptor to -1 is a good idea to improve robustness. If it's the case that setting the type to F_UNUSED would also need to be done, would it make sense to add a function, say, killfile(), that does both these things and use that throughout the code? Comment Actions In some places files are discarded by setting f->f_type to F_UNUSED. It seems like that's a more correct way to handle closed files, and I think the real bug is that we're not doing that everywhere. At the very least, this should be lifted into a subroutine. Comment Actions Agreed. This should be put in a separate/static function. Here's what Miles said he in an internal email: """ fprintlog() will close the file descriptor (and not set it to -1), which means that the caller cannot determine if the file descriptor was closed. Coverity analysis found that logmsg() was calling fprintlog() and then calling close(f->f_file), which could cause a double close in some cases. So my interpretation was a bit off, but (in theory) if the file descriptor was reused, it could also cause problems. Comment Actions Something like that would be a good idea, yes (and I think that's what Mark was implying too). Comment Actions
Comment Actions
|