Browse Source

[1704] editorial nits: folded long lines, position of '*', sizeof(), constify.

JINMEI Tatuya 13 years ago
parent
commit
876dd74d15

+ 7 - 3
src/lib/util/interprocess_sync.h

@@ -27,7 +27,9 @@ public:
     /// \brief Constructor
     ///
     /// Creates a interprocess synchronization object
-    InterprocessSync(const std::string component_name) : component_name_(component_name) {}
+    InterprocessSync(const std::string component_name) :
+        component_name_(component_name)
+    {}
 
     /// \brief Destructor
     virtual ~InterprocessSync() {}
@@ -49,8 +51,10 @@ public:
     virtual ~InterprocessSyncLocker() {}
 
 protected:
-    InterprocessSyncLocker(InterprocessSync* sync) : sync_(sync), is_locked_(false) {}
-    InterprocessSync *sync_;
+    InterprocessSyncLocker(InterprocessSync* sync) :
+        sync_(sync), is_locked_(false)
+    {}
+    InterprocessSync* sync_;
     bool is_locked_;
 };
 

+ 18 - 19
src/lib/util/interprocess_sync_file.cc

@@ -27,8 +27,8 @@ namespace isc {
 namespace util {
 
 InterprocessSyncFile::InterprocessSyncFile(const std::string component_name) :
-    InterprocessSync(component_name) {
-
+    InterprocessSync(component_name)
+{
     std::string lockfile_path = LOCKFILE_DIR;
 
     const char* const env = getenv("B10_FROM_SOURCE");
@@ -45,13 +45,14 @@ InterprocessSyncFile::InterprocessSyncFile(const std::string component_name) :
 
     // Open the lockfile in the constructor so it doesn't do the access
     // checks every time a message is logged.
-    mode_t mode = umask(0111);
+    const mode_t mode = umask(0111);
     fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR, 0660);
     umask(mode);
 
     if (fd_ == -1) {
         isc_throw(InterprocessSyncFileError,
-                  "Unable to use interprocess sync lockfile: " + lockfile_path);
+                  "Unable to use interprocess sync lockfile: " +
+                  lockfile_path);
     }
 }
 
@@ -65,14 +66,15 @@ InterprocessSyncFile::~InterprocessSyncFile() {
 
 InterprocessSyncLocker*
 InterprocessSyncFile::getLocker() {
-    InterprocessSyncLocker *locker = new InterprocessSyncFileLocker(this);
-    return locker;
+    InterprocessSyncLocker* locker = new InterprocessSyncFileLocker(this);
+    return (locker);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////
 
-InterprocessSyncFileLocker::InterprocessSyncFileLocker(InterprocessSync* sync) :
-    InterprocessSyncLocker(sync) {
+InterprocessSyncFileLocker::InterprocessSyncFileLocker(InterprocessSync* sync)
+    : InterprocessSyncLocker(sync)
+{
 }
 
 InterprocessSyncFileLocker::~InterprocessSyncFileLocker() {
@@ -85,12 +87,11 @@ InterprocessSyncFileLocker::lock() {
         return (true);
     }
 
-    InterprocessSyncFile *sync = dynamic_cast<InterprocessSyncFile*>(sync_);
-    int fd = sync->getFd();
+    InterprocessSyncFile* sync = dynamic_cast<InterprocessSyncFile*>(sync_);
+    const int fd = sync->getFd();
 
     if (fd != -1) {
         struct flock lock;
-        int status;
 
         // Acquire the exclusive lock
         memset(&lock, 0, sizeof lock);
@@ -99,7 +100,7 @@ InterprocessSyncFileLocker::lock() {
         lock.l_start = 0;
         lock.l_len = 1;
 
-        status = fcntl(fd, F_SETLKW, &lock);
+        const int status = fcntl(fd, F_SETLKW, &lock);
         if (status == 0) {
             is_locked_ = true;
             return (true);
@@ -115,12 +116,11 @@ InterprocessSyncFileLocker::tryLock() {
         return (true);
     }
 
-    InterprocessSyncFile *sync = dynamic_cast<InterprocessSyncFile*>(sync_);
-    int fd = sync->getFd();
+    InterprocessSyncFile* sync = dynamic_cast<InterprocessSyncFile*>(sync_);
+    const int fd = sync->getFd();
 
     if (fd != -1) {
         struct flock lock;
-        int status;
 
         // Acquire the exclusive lock
         memset(&lock, 0, sizeof lock);
@@ -129,7 +129,7 @@ InterprocessSyncFileLocker::tryLock() {
         lock.l_start = 0;
         lock.l_len = 1;
 
-        status = fcntl(fd, F_SETLK, &lock);
+        const int status = fcntl(fd, F_SETLK, &lock);
         if (status == 0) {
             is_locked_ = true;
             return (true);
@@ -146,11 +146,10 @@ InterprocessSyncFileLocker::unlock() {
     }
 
     InterprocessSyncFile *sync = dynamic_cast<InterprocessSyncFile*>(sync_);
-    int fd = sync->getFd();
+    const int fd = sync->getFd();
 
     if (fd != -1) {
         struct flock lock;
-        int status;
 
         // Release the exclusive lock
         memset(&lock, 0, sizeof lock);
@@ -159,7 +158,7 @@ InterprocessSyncFileLocker::unlock() {
         lock.l_start = 0;
         lock.l_len = 1;
 
-        status = fcntl(fd, F_SETLKW, &lock);
+        const int status = fcntl(fd, F_SETLKW, &lock);
         if (status == 0) {
             is_locked_ = false;
             return (true);

+ 4 - 3
src/lib/util/interprocess_sync_file.h

@@ -27,7 +27,8 @@ namespace util {
 ///
 class InterprocessSyncFileError : public Exception {
 public:
-    InterprocessSyncFileError(const char* file, size_t line, const char* what) :
+    InterprocessSyncFileError(const char* file, size_t line,
+                              const char* what) :
         isc::Exception(file, line, what) {}
 };
 
@@ -41,8 +42,8 @@ public:
 
     InterprocessSyncLocker* getLocker();
 
-    int getFd() {
-        return fd_;
+    int getFd() const {
+        return (fd_);
     }
 
 private:

+ 16 - 16
src/lib/util/tests/interprocess_sync_file_unittest.cc

@@ -26,8 +26,8 @@ protected:
 };
 
 TEST_F(InterprocessSyncFileTest, TestLock) {
-  InterprocessSync *sync = new InterprocessSyncFile("test");
-  InterprocessSyncLocker *locker = sync->getLocker();
+  InterprocessSync* sync = new InterprocessSyncFile("test");
+  InterprocessSyncLocker* locker = sync->getLocker();
 
   EXPECT_TRUE(locker->lock());
 
@@ -49,8 +49,8 @@ TEST_F(InterprocessSyncFileTest, TestLock) {
       // Child writes to pipe
       close(fds[0]);
 
-      InterprocessSync *sync2 = new InterprocessSyncFile("test");
-      InterprocessSyncLocker *locker2 = sync2->getLocker();
+      InterprocessSync* sync2 = new InterprocessSyncFile("test");
+      InterprocessSyncLocker* locker2 = sync2->getLocker();
 
       if (!locker2->tryLock()) {
           locked = 1;
@@ -59,7 +59,7 @@ TEST_F(InterprocessSyncFileTest, TestLock) {
       delete locker2;
       delete sync2;
 
-      write(fds[1], &locked, sizeof locked);
+      write(fds[1], &locked, sizeof(locked));
       close(fds[1]);
       exit(0);
   } else {
@@ -68,7 +68,7 @@ TEST_F(InterprocessSyncFileTest, TestLock) {
       close(fds[1]);
 
       // Read status and set flag
-      read(fds[0], &locked, sizeof locked);
+      read(fds[0], &locked, sizeof(locked));
       if (locked == 1) {
         was_locked = true;
       } else {
@@ -86,13 +86,13 @@ TEST_F(InterprocessSyncFileTest, TestLock) {
 }
 
 TEST_F(InterprocessSyncFileTest, TestMultipleFilesDirect) {
-  InterprocessSync *sync = new InterprocessSyncFile("test1");
-  InterprocessSyncLocker *locker = sync->getLocker();
+  InterprocessSync* sync = new InterprocessSyncFile("test1");
+  InterprocessSyncLocker* locker = sync->getLocker();
 
   EXPECT_TRUE(locker->lock());
 
-  InterprocessSync *sync2 = new InterprocessSyncFile("test2");
-  InterprocessSyncLocker *locker2 = sync2->getLocker();
+  InterprocessSync* sync2 = new InterprocessSyncFile("test2");
+  InterprocessSyncLocker* locker2 = sync2->getLocker();
   EXPECT_TRUE(locker2->lock());
   EXPECT_TRUE(locker2->unlock());
   delete sync2;
@@ -105,8 +105,8 @@ TEST_F(InterprocessSyncFileTest, TestMultipleFilesDirect) {
 }
 
 TEST_F(InterprocessSyncFileTest, TestMultipleFilesForked) {
-  InterprocessSync *sync = new InterprocessSyncFile("test");
-  InterprocessSyncLocker *locker = sync->getLocker();
+  InterprocessSync* sync = new InterprocessSyncFile("test");
+  InterprocessSyncLocker* locker = sync->getLocker();
 
   EXPECT_TRUE(locker->lock());
 
@@ -121,8 +121,8 @@ TEST_F(InterprocessSyncFileTest, TestMultipleFilesForked) {
       // Child writes to pipe
       close(fds[0]);
 
-      InterprocessSync *sync2 = new InterprocessSyncFile("test2");
-      InterprocessSyncLocker *locker2 = sync2->getLocker();
+      InterprocessSync* sync2 = new InterprocessSyncFile("test2");
+      InterprocessSyncLocker* locker2 = sync2->getLocker();
 
       if (locker2->tryLock()) {
           locked = 0;
@@ -131,7 +131,7 @@ TEST_F(InterprocessSyncFileTest, TestMultipleFilesForked) {
       delete locker2;
       delete sync2;
 
-      write(fds[1], &locked, sizeof locked);
+      write(fds[1], &locked, sizeof(locked));
       close(fds[1]);
       exit(0);
   } else {
@@ -140,7 +140,7 @@ TEST_F(InterprocessSyncFileTest, TestMultipleFilesForked) {
       close(fds[1]);
 
       // Read status and set flag
-      read(fds[0], &locked, sizeof locked);
+      read(fds[0], &locked, sizeof(locked));
       if (locked == 0) {
         was_not_locked = true;
       } else {