[espie at nerim.net: PATCH: fix nasty race condition in core libraries]

Marc Espie espie at nerim.net
Mon Jan 31 19:37:19 GMT 2005


Prompted by Stephen Kulow...

----- Forwarded message from Marc Espie <espie at nerim.net> -----

Date: Sat, 29 Jan 2005 14:29:09 +0100
From: Marc Espie <espie at nerim.net>
To: kde-devel at kde.org
Subject: PATCH: fix nasty race condition in core libraries

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()

----- End forwarded message -----




More information about the kde-core-devel mailing list