diff options
author | unknown <stewart@willster.(none)> | 2006-10-27 18:59:20 +1000 |
---|---|---|
committer | unknown <stewart@willster.(none)> | 2006-10-27 18:59:20 +1000 |
commit | 18f66e026ed090f383bee683ed0d1019f76044c4 (patch) | |
tree | 5c30dd075bfa6a662b7be9fff6fbb79868f25204 /ndb | |
parent | b82448833566bbd43434d6d23035e68013483012 (diff) | |
download | mariadb-git-18f66e026ed090f383bee683ed0d1019f76044c4.tar.gz |
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
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/include/logger/FileLogHandler.hpp | 2 | ||||
-rw-r--r-- | ndb/include/util/File.hpp | 4 | ||||
-rw-r--r-- | 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); |