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

List:       kde-core-devel
Subject:    PATCH: slavebase.cpp
From:       aleXXX <alexander.neundorf () gmx ! net>
Date:       2001-09-13 17:31:13
[Download RAW message or body]

Hi,

I explored the problem with the dtors of ioslaves a bit more.
The dtors are not called when the ioslave is killed and also not if the 
ioslave exit()'s somewhere in a member function (e.g. dispatchLoop();).

The patch installs a default signalhandler which calls the dtor of the 
ioslave when killed, it changes the exit calls in dispatchLoop() to returns, 
so that the ioslave exits normally from kde_main() and the dtor is really 
called, and it wraps the other signal handlers in signal(x,SIGIGN); and 
signal(x,&the_handler);, according to "Parallele Prozesse unter UNIX" this is 
the right way for signal handlers. It should also prevent the loop mentioned 
in the sigsegv handler.

I'd like to apply the patch to HEAD and KDE_2_2_BRANCH.

Bye
Alex

["slavebase.cpp.diff" (text/x-diff)]

Index: slavebase.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/slavebase.cpp,v
retrieving revision 1.89
diff -c -b -u -r1.89 slavebase.cpp
--- slavebase.cpp	2001/09/09 23:15:53	1.89
+++ slavebase.cpp	2001/09/13 17:19:52
@@ -115,6 +115,19 @@
 
 };
 
+SlaveBase *globalSlave=0;
+
+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);
+};
+
 //////////////
 
 SlaveBase::SlaveBase( const QCString &protocol,
@@ -128,6 +141,32 @@
         KCrash::setCrashHandler( sigsegv_handler );
     signal( SIGPIPE, sigpipe_handler );
 
+   signal(SIGINT,&genericsig_handler);
+	signal(SIGQUIT,&genericsig_handler);
+	signal(SIGILL,&genericsig_handler);
+	signal(SIGTRAP,&genericsig_handler);
+	signal(SIGABRT,&genericsig_handler);
+	signal(SIGBUS,&genericsig_handler);
+	signal(SIGALRM,&genericsig_handler);
+	signal(SIGTERM,&genericsig_handler);
+	signal(SIGFPE,&genericsig_handler);
+#ifdef SIGPOLL
+   signal(SIGPOLL, &genericsig_handler);
+#endif
+#ifdef SIGSYS
+   signal(SIGSYS, &genericsig_handler);
+#endif
+#ifdef SIGVTALRM
+   signal(SIGVTALRM, &genericsig_handler);
+#endif
+#ifdef SIGXCPU
+   signal(SIGXCPU, &genericsig_handler);
+#endif
+#ifdef SIGXFSZ
+   signal(SIGXFSZ, &genericsig_handler);
+#endif
+   globalSlave=this;
+
     appconn = new Connection();
     listEntryCurrentSize = 0;
     struct timeval tp;
@@ -205,7 +244,7 @@
           }
           else
           {
-            exit(0);
+            return;
           }
         }
       }
@@ -215,7 +254,7 @@
       kdDebug(7019) << "dispatchLoop(): select returned error "
                     << \
(errno==EBADF?"EBADF":errno==EINTR?"EINTR":errno==EINVAL?"EINVAL":errno==ENOMEM?"ENOMEM":"unknown")
  << " (" << errno << ")" << endl;
-       exit(0);
+       return;
     }
   }
 }
@@ -385,6 +424,7 @@
        cmd = 0;
        if ( m_pConnection->read( &cmd, data ) == -1 ) {
            kdDebug(7019) << "SlaveBase: mimetype: read error" << endl;
+           this->~SlaveBase();
            ::exit(255);
        }
        if ( isSubCommand(cmd) )
@@ -512,6 +552,7 @@
 
 void SlaveBase::sigsegv_handler (int)
 {
+    signal(SIGSEGV,SIG_IGN);
     // Debug and printf should be avoided because they might
     // call malloc.. and get in a nice recursive malloc loop
     write(2, "kioslave : ###############SEG FAULT#############\n", 49);
@@ -524,8 +565,9 @@
     // A SIGPIPE can happen in two cases:
     // 1) Communication error with application.
     // 2) Communication error with network.
-
+    signal(SIGPIPE,SIG_IGN);
     kdDebug(7019) << "SIGPIPE" << endl;
+    signal(SIGPIPE,&sigpipe_handler);
 }
 
 void SlaveBase::setHost(QString const &, int, QString const &, QString const &)



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

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