ioslave terminating mechanism

Waldo Bastian bastian at kde.org
Thu Apr 18 00:08:10 BST 2002


On Wednesday 17 April 2002 02:39 pm, aleXXX wrote:
> On Wednesday 17 April 2002 20:41, Waldo Bastian wrote:
> > On Wednesday 17 April 2002 08:11 am, Malte Starostik wrote:
> > > Not sure, but I suspect that this code in slavebase.cpp is rather
> > > dangerous:
> > >
> > > void genericsig_handler(int sigNumber)
> > > {
> > >    signal(sigNumber,SIG_IGN);
> > >    //I don't think we can have the same problem here as in the sigsegv
> > > handler kdDebug()<<"kioslave : exiting due to signal
> > > "<<sigNumber<<endl; //call the dtor of the slave and exit
> > >    if (globalSlave!=0)
> > >       globalSlave->~SlaveBase();
> > >    exit(2);
> > > };
> >
> > Yes, I think the whole concept of calling a destructor there is
> > misguided. If you need to clean anything up in your io-slave when you get
> > killed you should install a signal handler yourself.
> >
> > Cheers,
> > Waldo
>
> Actually I always expected that the ioslave dtors are called when an
> ioslave exits, until I found out that this is not the case and added the
> dtor calls. Ioslaves feel more like plugins, you think you're writing only
> a lib and a lib shouldn't exit its process (i.e. not handle signals).
> This fixes major problems e.g. with the smbro ioslave.
> I guess other ioslave authors expect the same, why else should they have
> written dtors for their ioslaves ?

That's nice and all but it fails to take into account that signal delivery is 
asynchronous and the current code can deadlock when the siganl happens to 
arrive at an inconvenient time. E.g. within a malloc or free call. When you 
then call the destructor your process will deadlock.

You simply can't call arbitrary code (the destructor of a slave) at any 
arbitrary moment (when the signal arrives) and expect it to work.

Cheers,
Waldo
-- 
bastian at kde.org  |   SuSE Labs KDE Developer  |  bastian at suse.com





More information about the kde-core-devel mailing list