[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: Re: [patch] kmail startup lock revisited
From: David Faure <dfaure () klaralvdalens-datakonsult ! se>
Date: 2007-03-22 15:02:28
Message-ID: 200703221602.31381.dfaure () klaralvdalens-datakonsult ! se
[Download RAW message or body]
On Tuesday 06 February 2007, David Faure wrote:
> On Tuesday 06 February 2007, Ingo Klöcker wrote:
> > On Tuesday 06 February 2007 00:03, David Faure wrote:
> > > Yes, but I'm really annoyed by this constant bogus warning box, when
> > > I know very well that I'm not running kmail on two displays...
> >
> > I guess checking the name of the process with PID oldPid isn't a
> > feasible (and portable) alternative?
>
> It's not portable, but it's definitely feasible on at least linux :-)
> That sounds like a good plan, actually. Rather simple.
Works fine, too.
(It's quite fortunate that neither kmail nor kontact are kdeinit modules,
otherwise the solution would become much more complex.)
--
David Faure, faure@kde.org, dfaure@klaralvdalens-datakonsult.se
KDE/KOffice developer, Qt consultancy projects
Klarälvdalens Datakonsult AB, Platform-independent software solutions
["kmstartup.diff" (text/x-diff)]
Index: kmstartup.cpp
===================================================================
--- kmstartup.cpp (revision 643307)
+++ kmstartup.cpp (working copy)
@@ -36,10 +36,12 @@
#include <errno.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <qfile.h>
#undef Status // stupid X headers
@@ -154,12 +156,34 @@
bool first_instance = false;
if ( oldPid == -1 )
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 );
+ // check if the lock file is stale
+#ifdef Q_OS_LINUX
+ if ( ::access("/proc", X_OK ) == 0 ) {
+ // On linux with /proc we can even check that it's really kmail and not something else
+ char path_buffer[MAXPATHLEN + 1];
+ path_buffer[MAXPATHLEN] = 0;
+ const QString procPath = QString("/proc/%1/exe").arg(oldPid);
+ const int length = readlink (procPath.latin1(), path_buffer, MAXPATHLEN);
+ if ( length == -1 ) // not such pid
+ first_instance = true;
+ else {
+ path_buffer[length] = '\0';
+ const QString path = QFile::decodeName(path_buffer);
+ kdDebug() << k_funcinfo << path << endl;
+ const int pos = path.findRev('/');
+ const QString fileName = path.mid(pos+1);
+ kdDebug() << "Found process " << oldPid << " running. It's: " << fileName << endl;
+ first_instance = fileName != "kmail" && fileName != "kontact";
+ }
+ } else
+#endif
+ {
+ // Otherwise we just check if the other pid is currently running.
+ // Not 100% correct but better safe than sorry.
+ if ( kill(oldPid, 0) == -1 )
+ first_instance = ( errno == ESRCH );
+ }
}
if ( !first_instance ) {
_______________________________________________
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