Bug 148115 - Compile error on Solaris 8 - kdelibs/kdeui/icons/kpixmapcache.cpp has ::flock, LOCK_EX, LOCK_SH and LOCK_UN undefined
Summary: Compile error on Solaris 8 - kdelibs/kdeui/icons/kpixmapcache.cpp has ::flock...
Status: RESOLVED FIXED
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Solaris
: NOR normal
Target Milestone: ---
Assignee: Rivo Laks
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-22 18:38 UTC by Steve Evans
Modified: 2007-07-25 15:05 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Evans 2007-07-22 18:38:55 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
Compiler:          gcc 3.4.6 
OS:                Solaris

I get this compile error on Solaris:

[  9%] Building CXX object kdeui/CMakeFiles/kdeui.dir/icons/kpixmapcache.o
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp: In constructor `LockFile::LockFile(const QString&, bool)':
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp:59: error: `::flock' has not been declared
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp:59: error: `LOCK_EX' was not declared in this scope
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp:59: error: `LOCK_SH' was not declared in this scope
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp: In destructor `LockFile::~LockFile()':
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp:78: error: `::flock' has not been declared
/cad4/stevee/kde-svn/kdelibs/kdeui/icons/kpixmapcache.cpp:78: error: `LOCK_UN' was not declared in this scope
Comment 1 Rivo Laks 2007-07-25 15:05:53 UTC
SVN commit 692378 by rivol:

I'm finally convinced: use KLockFile everywhere.
BUG: 148115

 M  +3 -43     kpixmapcache.cpp  


--- trunk/KDE/kdelibs/kdeui/icons/kpixmapcache.cpp #692377:692378
@@ -36,68 +36,41 @@
 #include <klockfile.h>
 #include <ksvgrenderer.h>
 
-#include <sys/file.h>
 
-
 //#define DISABLE_PIXMAPCACHE
 
-#ifdef Q_OS_WIN
- #define USE_KLOCKFILE
-#endif
-
 #define KPIXMAPCACHE_VERSION 0x000104
 
 
-// There's also KLockFile class which works with NFS as well. But temporary
-//  dirs shouldn't be in NFS, so this simple class should do the job.
 class LockFile
 {
 public:
     LockFile(const QString& filename, bool exclusive = false)
-            : mFile(filename)
     {
         mValid = false;
-#ifndef USE_KLOCKFILE
-        if (!mFile.open(QIODevice::ReadOnly)) {
-            kError() << k_funcinfo << "Failed to open file '" << filename << "'" << endl;
-        } else if (::flock(mFile.handle(), exclusive ? LOCK_EX : LOCK_SH)) {
-            kError() << k_funcinfo << "Failed to acquire " <<
-                    (exclusive ? "exclusive" : "shared")  << " lock '" << filename << "'" << endl;
-        } else {
-            mValid = true;
-        }
-#else
         mLockFile = new KLockFile(filename);
         KLockFile::LockResult result = mLockFile->lock(KLockFile::NoBlockFlag);
+        // TODO: If locking blocks then sleep for a small amount of time (e.g.
+        //  20ms) and try again for a few times
         if (result != KLockFile::LockOK) {
             kError() << k_funcinfo << "Failed to lock file '" << filename << "', result = " << result << endl;
         } else {
             mValid = true;
         }
-#endif
     }
     ~LockFile()
     {
-#ifndef USE_KLOCKFILE
         if (mValid) {
-            ::flock(mFile.handle(), LOCK_UN);
-        }
-#else
-        if (mValid) {
             mLockFile->unlock();
         }
         delete mLockFile;
-#endif
     }
 
     bool isValid() const  { return mValid; }
 
 private:
-    QFile mFile;
     bool mValid;
-#ifdef USE_KLOCKFILE
     KLockFile* mLockFile;
-#endif
 };
 
 
@@ -172,8 +145,7 @@
 
 bool KPixmapCache::Private::checkLockFile()
 {
-#ifdef USE_KLOCKFILE
-    // For KLockFile we need to ensure the lock file _doesn't_ exist.
+    // For KLockFile we need to ensure the lock file doesn't exist.
     if (QFile::exists(mLockFileName)) {
         if (!QFile::remove(mLockFileName)) {
             kError() << k_funcinfo << "Couldn't remove lockfile '" << mLockFileName << "'" << endl;
@@ -181,18 +153,6 @@
         }
     }
     return true;
-#else
-    // For flock() the lockfile should exist
-    if (!QFile::exists(mLockFileName)) {
-        QFile tmp(mLockFileName);
-        if (!tmp.open(QIODevice::WriteOnly)) {
-            kError() << k_funcinfo << "Couldn't create lockfile '" << mLockFileName << "'" << endl;
-            return false;
-        }
-    }
-    // TODO: check lockfile permissions?
-    return true;
-#endif
 }
 
 bool KPixmapCache::Private::checkFileVersion(const QString& filename)