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

List:       kmail-devel
Subject:    [patch] kmail startup lock revisited
From:       David Faure <dfaure () klaralvdalens-datakonsult ! se>
Date:       2007-02-05 9:25:36
Message-ID: 200702051025.55444.dfaure () klaralvdalens-datakonsult ! se
[Download RAW message or body]

And another patch from me, a bit tested this time:

KMail annoys me on most startups with a "I seem to be running on another display on \
this machine" message box. However it's definitely not running at all yet (the \
machine just booted); the problem is that kmail's lock file mentions a PID that is \
running, but that isn't kmail. How about we use DCOP to find out if kmail is really \
running, and with which PID? See attached patch.
Works when kmail isn't running, at least ;)

David.


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

Index: Makefile.am
===================================================================
--- Makefile.am	(revision 627192)
+++ Makefile.am	(working copy)
@@ -77,7 +77,7 @@ libkmailprivate_la_SOURCES = kmmessage.c
                 kmfawidgets.cpp kmfoldermbox.cpp kmfolderimap.cpp \
                 undostack.cpp kmfoldercachedimap.cpp \
                 kmfoldermaildir.cpp popaccount.cpp colorlistbox.cpp \
-                kmkernel.cpp kmailIface.skel kmailicalIface.skel \
+                kmkernel.cpp kmailIface.skel kmailIface.stub kmailicalIface.skel \
                 accountdialog.cpp searchwindow.cpp vcardviewer.cpp \
                 vacationdialog.cpp vacation.cpp sievedebugdialog.cpp \
                 sieveconfig.cpp sievejob.cpp \
Index: kmstartup.cpp
===================================================================
--- kmstartup.cpp	(revision 627192)
+++ kmstartup.cpp	(working copy)
@@ -19,6 +19,7 @@
 #include <config.h>
 
 #include "kmstartup.h"
+#include "kmailIface_stub.h"
 
 #include "kmkernel.h" //control center
 #include "kcursorsaver.h"
@@ -156,10 +157,21 @@ void lockOrDie() {
       first_instance = true;
   // check if the lock file is stale by trying to see if
   // the other pid is currently running.
-  // Not 100% correct but better safe than sorry
   else if (hostName == oldHostName && oldPid != getpid()) {
-      if ( kill(oldPid, 0) == -1 )
-          first_instance = ( errno == ESRCH );
+      if ( kill(oldPid, 0) == -1 && errno == ESRCH ) {
+          kdDebug() << oldPid << " is not running." << endl;
+          first_instance = true;
+      } else {
+          kdDebug() << oldPid << " is running, trying dcop." << endl;
+          // oldPid is running. Let's check if it's kmail or something else
+          KMailIface_stub kmailStub( "kmail", "KMailIface" );
+          long kmailPid = kmailStub.getpid(); // we'll get 0 if no kmail is running at all
+          if ( kmailPid )
+              kdDebug() << "Currently running kmail has pid=" << kmailPid << endl;
+          if ( kmailPid != oldPid ) {
+              first_instance = true;
+          }
+      }
   }
 
   if ( !first_instance ) {
Index: kmkernel.cpp
===================================================================
--- kmkernel.cpp	(revision 627192)
+++ kmkernel.cpp	(working copy)
@@ -1,9 +1,6 @@
 /*  -*- mode: C++; c-file-style: "gnu" -*- */
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include "config.h"
 #include "kmkernel.h"
 
 #include <weaver.h>
@@ -2316,6 +2313,11 @@ bool KMKernel::canQueryClose()
   return true;
 }
 
+long KMKernel::getpid()
+{
+  return ::getpid();
+}
+
 void KMKernel::messageCountChanged()
 {
   mTimeOfLastMessageCountChange = ::time( 0 );
Index: kmkernel.h
===================================================================
--- kmkernel.h	(revision 627192)
+++ kmkernel.h	(working copy)
@@ -369,6 +369,7 @@ public:
   void abortMailCheck();
 
   bool canQueryClose();
+  long getpid();
 
   /**
    * Called by the folder tree if the count of unread/total messages changed.
Index: kmailIface.h
===================================================================
--- kmailIface.h	(revision 627192)
+++ kmailIface.h	(working copy)
@@ -107,6 +107,7 @@ k_dcop:
   virtual DCOPRef getFolder( const QString& vpath ) =0;
   virtual void selectFolder( QString folder ) =0;
   virtual bool canQueryClose() =0;
+  virtual long getpid() =0;
 
   /**
    * Set the KMail Default transport.


_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


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

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