[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: nspluginviewer still crashes
From:       Waldo Bastian <bastian () kde ! org>
Date:       2001-08-10 23:57:17
[Download RAW message or body]

On Friday 10 August 2001 04:09 pm, Kurt Granroth wrote:
> On Friday 10 August 2001 02:48 pm, Kurt Granroth wrote:
> > On Friday 10 August 2001 12:57 pm, Philipp Siegert wrote:
> > > on http://www.sunremo.de nspluginviewer still crashes with my CVS
> > > builds from today. The branch is KDE_2_2_RELEASE. The QT version is not
> > > compiled with opengl support.
> > > Can anyone reproduce that ?
>
> Hehe.. actually, this one is somewhat funny.  It's a problem between the
> nspluginviewer and (get this) KTempFile!  The viewer uses a temp file when
> loading a remote plugin.  KTempFile accepts a file prefix and a file
> extension to create a random temp name of the form <filePrefix><random
> number><file extension>.  Now the plugin viewer passes along null as the
> prefix and the filename of the remote object as the extension.
>
> This works great normally because KTempFile is pretty flexible.  In fact,
> there really is only one major caveat to using KTempFile.. the file
> extension can never have the 'X' character in it.  Can you see where we're
> going? :-)

Someone replaced the working version with some BSD crap it seems.

Please try this patch.

Cheers,
Waldo
-- 
KDE 2.2: We deliver.

["ktempfile.diff" (text/x-diff)]

Index: ktempfile.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/ktempfile.cpp,v
retrieving revision 1.19
diff -u -3 -d -p -r1.19 ktempfile.cpp
--- ktempfile.cpp	2001/07/14 04:41:31	1.19
+++ ktempfile.cpp	2001/08/10 23:54:36
@@ -90,27 +90,45 @@ bool
 KTempFile::create(const QString &filePrefix, const QString &fileExtension,
 		  int mode)
 {
-   mTmpName = filePrefix+QString("XXXXXX")+fileExtension;
-   QCString nme = QFile::encodeName(mTmpName);
-   if((mFd = mkstemps(nme.data(), nme.length()-nme.findRev('X')-1)) < 0)
-   {
-       mError = EACCES;
-       mTmpName = QString::null;
-       return false;
-   }
+   // The following is not guranteed to work correctly on NFS
+   // In that case we depend on a good random number
+   int maxTries = 20;
+   int tries = 0;
+   do {
+      tries++;
+      mTmpName = filePrefix+QString(".%1").arg(kapp->random())+fileExtension;
 
-   // got a file descriptor. nme contains the name
-   mTmpName = QFile::decodeName(nme);
-   mode_t tmp = 0;
-   mode_t umsk = umask(tmp);
-   umask(umsk);
-   chmod(nme, mode&(~umsk));
+      if (checkAccess(mTmpName, W_OK))
+      {
+#ifdef O_NOFOLLOW
+         mFd = open(QFile::encodeName(mTmpName), O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, mode);
+#else
+         mFd = open(QFile::encodeName(mTmpName), O_RDWR|O_CREAT|O_EXCL, mode);
+#endif
+         if ((mFd <= 0) && (tries >= maxTries))
+         {
+            mError = errno;
+            mTmpName = QString::null;
+            return false;
+         }
+      }
+      else
+      {
+         if (tries >= maxTries)
+         {
+            mError = EACCES;
+            mTmpName = QString::null;
+            return false;
+         }
+      }
+   }
+   while( mFd <= 0);
 
    // Success!
    bOpen = true;
 
    // Set uid/gid (neccesary for SUID programs)
-   chown(nme, getuid(), getgid());
+   chown(QFile::encodeName(mTmpName), getuid(), getgid());
    return true;
 }
 

>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic