]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_filedb/lib/AtomicFile.cpp
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / libsecurity_filedb / lib / AtomicFile.cpp
index 6095fb0fa065047c2be038f1a63d94b6c0da45a8..fbfae750aabe11197805075a2cf582d6fcd0d01a 100644 (file)
@@ -90,7 +90,7 @@ AtomicFile::~AtomicFile()
 {
 }
 
-// Aquire the write lock and remove the file.
+// Acquire the write lock and remove the file.
 void
 AtomicFile::performDelete()
 {
@@ -109,7 +109,7 @@ AtomicFile::performDelete()
        ::unlink(mLockFilePath.c_str());
 }
 
-// Aquire the write lock and rename the file (and bump the version and stuff).
+// Acquire the write lock and rename the file (and bump the version and stuff).
 void
 AtomicFile::rename(const std::string &inNewPath)
 {
@@ -158,7 +158,7 @@ AtomicFile::create(mode_t mode)
                // Now that we have created the lock and the new db file create a tempfile
                // object.
                RefPointer<AtomicTempFile> temp(new AtomicTempFile(*this, lock, mode));
-               secnotice("atomicfile", "%p created %s", this, path);
+               secinfo("atomicfile", "%p created %s", this, path);
                return temp;
        }
        catch (...)
@@ -202,7 +202,7 @@ AtomicFile::mode() const
        if (::stat(path, &st) == -1)
        {
                int error = errno;
-               secnotice("atomicfile", "stat %s: %s", path, strerror(error));
+               secinfo("atomicfile", "stat %s: %s", path, strerror(error));
                UnixError::throwMe(error);
        }
        return st.st_mode;
@@ -392,12 +392,12 @@ AtomicBufferedFile::~AtomicBufferedFile()
                // In release mode, the assert() is compiled out so rv may be unused.
                __unused int rv = AtomicFile::rclose(mFileRef);
                assert(rv == 0);
-               secnotice("atomicfile", "%p closed %s", this, mPath.c_str());
+               secinfo("atomicfile", "%p closed %s", this, mPath.c_str());
        }
 
        if (mBuffer)
        {
-               secnotice("atomicfile", "%p free %s buffer %p", this, mPath.c_str(), mBuffer);
+               secinfo("atomicfile", "%p free %s buffer %p", this, mPath.c_str(), mBuffer);
                unloadBuffer();
        }
 }
@@ -419,7 +419,7 @@ AtomicBufferedFile::open()
     if (mFileRef == -1)
     {
         int error = errno;
-               secnotice("atomicfile", "open %s: %s", path, strerror(error));
+               secinfo("atomicfile", "open %s: %s", path, strerror(error));
 
         // Do the obvious error code translations here.
                // @@@ Consider moving these up a level.
@@ -440,7 +440,7 @@ AtomicBufferedFile::open()
        else
        {
                int error = errno;
-               secnotice("atomicfile", "lseek(%s, END): %s", path, strerror(error));
+               secinfo("atomicfile", "lseek(%s, END): %s", path, strerror(error));
                AtomicFile::rclose(mFileRef);
                mFileRef = -1;
                UnixError::throwMe(error);
@@ -459,6 +459,7 @@ AtomicBufferedFile::unloadBuffer()
 {
     if(mBuffer) {
         delete [] mBuffer;
+        mBuffer = NULL;
     }
 }
 
@@ -468,10 +469,10 @@ void
 AtomicBufferedFile::loadBuffer()
 {
     // make a buffer big enough to hold the entire file
-    mBuffer = new uint8[mLength];
+    mBuffer = new uint8[(size_t) mLength];
     if(lseek(mFileRef, 0, SEEK_SET) < 0) {
         int error = errno;
-        secnotice("atomicfile", "lseek(%s, BEGINNING): %s", mPath.c_str(), strerror(error));
+        secinfo("atomicfile", "lseek(%s, BEGINNING): %s", mPath.c_str(), strerror(error));
         UnixError::throwMe(error);
     }
     ssize_t pos = 0;
@@ -485,11 +486,9 @@ AtomicBufferedFile::loadBuffer()
             if (errno != EINTR)
             {
                 int error = errno;
-                secnotice("atomicfile", "read(%s, %zd): %s", mPath.c_str(), bytesToRead, strerror(error));
-                if (mFileRef >= 0) {
-                    AtomicFile::rclose(mFileRef);
-                    mFileRef = -1;
-                }
+                secinfo("atomicfile", "read(%s, %zd): %s", mPath.c_str(), bytesToRead, strerror(error));
+                AtomicFile::rclose(mFileRef);
+                mFileRef = -1;
                 UnixError::throwMe(error);
             }
         }
@@ -514,20 +513,20 @@ AtomicBufferedFile::read(off_t inOffset, off_t inLength, off_t &outLength)
 {
        if (mFileRef < 0)
        {
-               secnotice("atomicfile", "read %s: file yet not opened, opening", mPath.c_str());
+               secinfo("atomicfile", "read %s: file yet not opened, opening", mPath.c_str());
                open();
        }
 
        off_t bytesLeft = inLength;
        if (mBuffer)
        {
-               secnotice("atomicfile", "%p free %s buffer %p", this, mPath.c_str(), mBuffer);
+               secinfo("atomicfile", "%p free %s buffer %p", this, mPath.c_str(), mBuffer);
                unloadBuffer();
        }
 
        loadBuffer();
        
-       secnotice("atomicfile", "%p allocated %s buffer %p size %qd", this, mPath.c_str(), mBuffer, bytesLeft);
+       secinfo("atomicfile", "%p allocated %s buffer %p size %qd", this, mPath.c_str(), mBuffer, bytesLeft);
        
        off_t maxEnd = inOffset + inLength;
        if (maxEnd > mLength)
@@ -558,7 +557,7 @@ AtomicBufferedFile::close()
                        UnixError::throwMe(error);
                }
 
-               secnotice("atomicfile", "%p closed %s", this, mPath.c_str());
+               secinfo("atomicfile", "%p closed %s", this, mPath.c_str());
        }
 }
 
@@ -625,7 +624,7 @@ AtomicTempFile::create(mode_t mode)
     if (mFileRef == -1)
     {
         int error = errno;
-               secnotice("atomicfile", "open %s: %s", path, strerror(error));
+               secnotice("atomicfile", "create %s: %s", path, strerror(error));
 
         // Do the obvious error code translations here.
                // @@@ Consider moving these up a level.
@@ -752,7 +751,7 @@ AtomicTempFile::fsync()
                        UnixError::throwMe(error);
                }
 
-               secnotice("atomicfile", "%p fsynced %s", this, mPath.c_str());
+               secinfo("atomicfile", "%p fsynced %s", this, mPath.c_str());
        }
 }
 
@@ -774,7 +773,7 @@ AtomicTempFile::close()
                        UnixError::throwMe(error);
                }
 
-               secnotice("atomicfile", "%p closed %s", this, mPath.c_str());
+               secinfo("atomicfile", "%p closed %s", this, mPath.c_str());
        }
 }
 
@@ -1112,7 +1111,7 @@ NetworkFileLocker::lock(mode_t mode)
                else
                        doSyslog = true;
 
-               secnotice("atomicfile", "Locking %s", path);          /* in order to cater for clock skew: get */
+               secinfo("atomicfile", "Locking %s", path);          /* in order to cater for clock skew: get */
                if (!xcreat(path, mode, t))    /* time t from the filesystem */
                {
                        /* lock acquired, hurray! */