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

List:       kde-devel
Subject:    PATCH: fix nasty race condition in core libraries
From:       Marc Espie <espie () nerim ! net>
Date:       2005-01-29 13:29:09
Message-ID: 20050129132909.GA1131 () tetto ! home
[Download RAW message or body]

I've finally found out why kded crashes frequently when one starts
konqueror directly on OpenBSD.

It's because of the following race condition.

For some reason, it doesn't happen (or doesn't happen that often) under
other OSes, but it is fairly deadly. Having setupHandlers in the
KProcessController constructor means the sigchild handler may get called
before theKProcessController has finished building, and the ::write ends
in a segfault.

Under OpenBSD, the way threads are implemented mean the SIGCHLD happens
right away when we do the sigprocmask, whereas for other OSes it might
happen infrequently.

I'd like to commit this before the new KDE gets released...

Any objection ?

Index: kprocctrl.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kprocctrl.cpp,v
retrieving revision 1.59
diff -u -p -u -p -r1.59 kprocctrl.cpp
--- kprocctrl.cpp	7 Sep 2004 11:42:17 -0000	1.59
+++ kprocctrl.cpp	29 Jan 2005 11:32:46 -0000
@@ -39,7 +39,10 @@ int KProcessController::refCount;
 void KProcessController::ref()
 {
   if( !refCount )
+  {
     theKProcessController = new KProcessController;
+    setupHandlers();
+  }
   refCount++;
 }
 
@@ -71,7 +74,6 @@ KProcessController::KProcessController()
   QObject::connect( notifier, SIGNAL(activated(int)),
                     SLOT(slotDoHousekeeping()));
 
-  setupHandlers();
 }
 
 KProcessController::~KProcessController()
 
>> Visit http://mail.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