rem: checkConfigUpdates();   const QString lockLocation = locateLocal("appdata", "lock"); KSimpleConfig config(lockLocation); int oldPid = config.readNumEntry("pid", -1); const QString oldHostName = config.readEntry("hostname"); const QString hostName = getMyHostName();  if (oldPid != -1 &&  oldPid != getpid() && hostName != oldHostName &&  (kill(oldPid, 0) != -1 || errno != ESRCH)) { QString msg = i18n("Only one instance of KMail can be run at " "any one time. It is already running on a different display " "with PID %1 on host %2 according to the lock file located " "at %3.").arg(oldPid).arg(oldHostName).arg(lockLocation);  KNotifyClient::userEvent( msg,  KNotifyClient::Messagebox, KNotifyClient::Error ); fprintf(stderr, "*** KMail is already running with PID %d on host %s\n", oldPid, oldHostName.local8Bit().data()); return 1; }  config.writeEntry("pid", getpid()); config.writeEntry("hostname", hostName); config.sync();
add: kmail::checkConfigUpdates(); kmail::lockOrDie();
context: int main(int argc, char *argv[]){  // WABA: KMail is a KUniqueApplication. Unfortunately this makes debugging  // a bit harder: You should pass --nofork as commandline argument when using  // a debugger. In gdb you can do this by typing "set args --nofork" before  // typing "run".  KAboutData about("kmail", I18N_NOOP("KMail"),                   KMAIL_VERSION,		   I18N_NOOP("The KDE Email client."),		   KAboutData::License_GPL,                   I18N_NOOP("(c) 1997-2002, The KMail developers"),		   0,		   "http://kmail.kde.org");  about.addAuthor( "Ingo Kl\303\266cker", I18N_NOOP("Maintainer"), "kloecker@kde.de" );  about.addAuthor( "Don Sanders", I18N_NOOP("Adopter and co-maintainer"), "sanders@kde.org" );  about.addAuthor( "Stefan Taferner ", I18N_NOOP("Original author"), "taferner@kde.org" );  about.addAuthor( "Michael H\303\244ckel", I18N_NOOP("Former maintainer"), "haeckel@kde.org" );  about.addAuthor( "Carsten Burghardt", I18N_NOOP("Core developer"), "carsten.burghardt@web.de" );  about.addAuthor( "Marc Mutz", I18N_NOOP("Core developer"), "mutz@kde.org" );  about.addAuthor( "Daniel Naber", I18N_NOOP("Documentation"), "daniel.naber@t-online.de" );  about.addAuthor( "Zack Rusin", I18N_NOOP("Core developer"), "zack@kde.org" );  about.addAuthor( "Toyohiro Asukai", 0, "toyohiro@ksmplus.com" );  about.addAuthor( "Waldo Bastian", 0, "bastian@kde.org" );  about.addAuthor( "Steven Brown", 0, "swbrown@ucsd.edu" );  about.addAuthor( "Matthias Kalle Dalheimer", 0, "kalle@kde.org" );  about.addAuthor( "Cristi Dumitrescu", 0, "cristid@chip.ro" );  about.addAuthor( "Philippe Fremy", 0, "pfremy@chez.com" );  about.addAuthor( "Kurt Granroth", 0, "granroth@kde.org" );  about.addAuthor( "Andreas Gungl", I18N_NOOP("PGP 6 support and further enhancements of the encryption support"), "a.gungl@gmx.de" );  about.addAuthor( "Heiko Hund", 0, "heiko@ist.eigentlich.net" );  about.addAuthor( "Igor Janssen", 0, "rm@linux.ru.net" );  about.addAuthor( "Matt Johnston", 0, "matt@caifex.org" );  about.addAuthor( "Christer Kaivo-oja", 0, "whizkid@telia.com" );  about.addAuthor( "Lars Knoll", I18N_NOOP("Original encryption support\nPGP 2 and PGP 5 support"), "knoll@kde.org" );  about.addAuthor( "J. Nick Koston", I18N_NOOP("GnuPG support"), "bdraco@darkorb.net" );  about.addAuthor( "Stephan Kulow", 0, "coolo@kde.org" );  about.addAuthor( "Guillaume Laurent", 0, "glaurent@telegraph-road.org" );  about.addAuthor( "Sam Magnuson", 0, "sam@trolltech.com" );  about.addAuthor( "Laurent Montel", 0, "lmontel@mandrakesoft.com" );  about.addAuthor( "Matt Newell", 0, "newellm@proaxis.com" );  about.addAuthor( "Denis Perchine", 0, "dyp@perchine.com" );  about.addAuthor( "Samuel Penn", 0, "sam@bifrost.demon.co.uk" );  about.addAuthor( "Carsten Pfeiffer", 0, "pfeiffer@kde.org" );  about.addAuthor( "Sven Radej", 0, "radej@kde.org" );  about.addAuthor( "Mark Roberts", 0, "mark@taurine.demon.co.uk" );  about.addAuthor( "Wolfgang Rohdewald", 0, "wrohdewald@dplanet.ch" );  about.addAuthor( "Espen Sand", 0, "espen@kde.org" );  about.addAuthor( "Aaron J. Seigo", 0, "aseigo@olympusproject.org" );  about.addAuthor( "George Staikos", 0, "staikos@kde.org" );  about.addAuthor( "Jason Stephenson", 0, "panda@mis.net" );  about.addAuthor( "Jacek Stolarczyk", 0, "jacek@mer.chemia.polsl.gliwice.pl" );  about.addAuthor( "Roberto S. Teixeira", 0, "maragato@kde.org" );  about.addAuthor( "Ronen Tzur", 0, "rtzur@shani.net" );  about.addAuthor( "Mario Weilguni", 0, "mweilguni@sime.com" );  about.addAuthor( "Wynn Wilkes", 0, "wynnw@calderasystems.com" );  about.addAuthor( "Robert D. Williams", 0, "rwilliams@kde.org" );  about.addAuthor( "Markus Wuebben", 0, "markus.wuebben@kde.org" );  about.addAuthor( "Karl-Heinz Zimmer", 0, "khz@kde.org" );  about.addCredit( "Bernhard Reiter", 0, "bernhard@intevation.de" );  about.addCredit( "Jan Simonson", I18N_NOOP("beta testing of PGP 6 support"), "jan@simonson.pp.se" );  about.addCredit( "Jan-Oliver Wagner", 0, "jan@intevation.de" );  about.addCredit( "Wolfgang Westphal", I18N_NOOP("multiple encryption keys per address"), "wolfgang.westphal@gmx.de" );  about.addCredit( "Thorsten Zachmann", I18N_NOOP("POP filters"), "t.zachmann@zagge.de" );  KCmdLineArgs::init(argc, argv, &about);  KCmdLineArgs::addCmdLineOptions( kmoptions ); // Add kmail options  if (!KMailApplication::start())     return 0;  KMailApplication app;  KGlobal::locale()->insertCatalogue("libkdenetwork");  // Check that all updates have been run on the config file:  checkConfigUpdates();  // Check and create a lock file to prevent concurrent access to kmail files  const QString lockLocation = locateLocal("appdata", "lock");  KSimpleConfig config(lockLocation);  int oldPid = config.readNumEntry("pid", -1);  const QString oldHostName = config.readEntry("hostname");  const QString hostName = getMyHostName();  // proceed if there is no lock at present  if (oldPid != -1 &&  // proceed if the lock is our pid, or if the lock is from the same host      oldPid != getpid() && hostName != oldHostName &&  // proceed if the pid doesn't exist      (kill(oldPid, 0) != -1 || errno != ESRCH))  {    QString msg = i18n("Only one instance of KMail can be run at "      "any one time. It is already running on a different display "      "with PID %1 on host %2 according to the lock file located "      "at %3.").arg(oldPid).arg(oldHostName).arg(lockLocation);    KNotifyClient::userEvent( msg,  KNotifyClient::Messagebox,      KNotifyClient::Error );    fprintf(stderr, "*** KMail is already running with PID %d on host %s\n",            oldPid, oldHostName.local8Bit().data());    return 1;  }  config.writeEntry("pid", getpid());  config.writeEntry("hostname", hostName);  config.sync();  kapp->dcopClient()->suspend(); // Don't handle DCOP requests yet  //local, do the init  KMKernel kmailKernel;  kmailKernel.init();  kapp->dcopClient()->setDefaultObject( kmailKernel.objId() );  // and session management  kmailKernel.doSessionManagement();  // any dead letters?  kmailKernel.recoverDeadLetters();  setSignalHandler(signalHandler);  kapp->dcopClient()->resume(); // Ok. We are ready for DCOP requests.  kernel->setStartingUp( false ); // Starting up is finished  // Go!  int ret = kapp->exec();  // clean up  kmailKernel.cleanup();  config.writeEntry("pid", -1);  config.sync();  return ret;}