From c088fa4aecbd3b084775e4a47e6e4cc64bd965bb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Oct 2006 18:59:20 +1000 Subject: BUG#22301 ndb: File_class::size() is not thread safe ndb/include/logger/FileLogHandler.hpp: use off_t for file offset ndb/include/util/File.hpp: use off_t for returning file offset (size) ndb/src/common/util/File.cpp: make File_class::size(FILE*) safe when having multiple threads writing to the file --- ndb/include/logger/FileLogHandler.hpp | 2 +- ndb/include/util/File.hpp | 4 ++-- ndb/src/common/util/File.cpp | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ndb/include/logger/FileLogHandler.hpp b/ndb/include/logger/FileLogHandler.hpp index 8fb25e72be7..60a455390b5 100644 --- a/ndb/include/logger/FileLogHandler.hpp +++ b/ndb/include/logger/FileLogHandler.hpp @@ -102,7 +102,7 @@ private: bool setMaxFiles(const BaseString &files); int m_maxNoFiles; - long m_maxFileSize; + off_t m_maxFileSize; unsigned int m_maxLogEntries; File_class* m_pLogFile; }; diff --git a/ndb/include/util/File.hpp b/ndb/include/util/File.hpp index fc71394c8c5..89c03d60cae 100644 --- a/ndb/include/util/File.hpp +++ b/ndb/include/util/File.hpp @@ -50,7 +50,7 @@ public: * @param f a pointer to a FILE descriptor. * @return the size of the file. */ - static long size(FILE* f); + static off_t size(FILE* f); /** * Renames a file. @@ -182,7 +182,7 @@ public: * * @return the file size. */ - long size() const; + off_t size() const; /** * Returns the filename. diff --git a/ndb/src/common/util/File.cpp b/ndb/src/common/util/File.cpp index 4f0b6bb77b0..8e61a5d93f2 100644 --- a/ndb/src/common/util/File.cpp +++ b/ndb/src/common/util/File.cpp @@ -45,17 +45,16 @@ File_class::exists(const char* aFileName) return (my_stat(aFileName, &stmp, MYF(0))!=NULL); } -long +off_t File_class::size(FILE* f) { - long cur_pos = 0, length = 0; - - cur_pos = ::ftell(f); - ::fseek(f, 0, SEEK_END); - length = ::ftell(f); - ::fseek(f, cur_pos, SEEK_SET); // restore original position + MY_STAT s; + + // Note that my_fstat behaves *differently* than my_stat. ARGGGHH! + if(my_fstat(::fileno(f), &s, MYF(0))) + return 0; - return length; + return s.st_size; } bool @@ -168,8 +167,8 @@ File_class::writeChar(const char* buf) { return writeChar(buf, 0, ::strlen(buf)); } - -long + +off_t File_class::size() const { return File_class::size(m_file); -- cgit v1.2.1