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

List:       kde-commits
Subject:    KDE/kdelibs
From:       David Faure <faure () kde ! org>
Date:       2010-12-06 11:17:10
Message-ID: 20101206111711.025C7AC8A4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1204125 by dfaure:

Fix autoloading of phase-2 modules when restarting kded.

There will be a "phase 2" only if we're in the KDE startup. If kded is restarted
by its crashhandled or by hand, then there will be no second phase autoload, so load
these modules now [if in a KDE session]

As reported by these guys more than a year ago:
CCMAIL: kde@michael-jansen.biz, ervin@kde.org


 M  +32 -14    kded/kded.cpp  
 M  +2 -0      kinit/kinit.cpp  


--- trunk/KDE/kdelibs/kded/kded.cpp #1204124:1204125
@@ -209,37 +209,58 @@
   Q_UNUSED(module);
 }
 
+static int phaseForModule(const KService::Ptr& service)
+{
+    const QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
+    return phasev.isValid() ? phasev.toInt() : 2;
+}
+
 void Kded::initModules()
 {
      m_dontLoad.clear();
      bool kde_running = !qgetenv( "KDE_FULL_SESSION" ).isEmpty();
+    if (kde_running) {
     // not the same user like the one running the session (most likely we're run via \
sudo or something)  const QByteArray sessionUID = qgetenv( "KDE_SESSION_UID" );
     if( !sessionUID.isEmpty() && uid_t( sessionUID.toInt() ) != getuid())
         kde_running = false;
+
+        // not the same kde version as the current desktop
+        const QByteArray kdeSession = qgetenv("KDE_SESSION_VERSION");
+        if (kdeSession.toInt() != KDE_VERSION_MAJOR)
+            kde_running = false;
+    }
+
+    // There will be a "phase 2" only if we're in the KDE startup.
+    // If kded is restarted by its crashhandled or by hand,
+    // then there will be no second phase autoload, so load
+    // these modules now, if in a KDE session.
+    const bool loadPhase2Now = (kde_running && \
qgetenv("KDED_STARTED_BY_KDEINIT").toInt() == 0); +
      // Preload kded modules.
      const KService::List kdedModules = \
                KServiceTypeTrader::self()->query("KDEDModule");
      for(KService::List::ConstIterator it = kdedModules.begin(); it != \
kdedModules.end(); ++it)  {
          KService::Ptr service = *it;
          // Should the service load on startup?
-         bool autoload = isModuleAutoloaded(service);
+         const bool autoload = isModuleAutoloaded(service);
 
          // see ksmserver's README for description of the phases
-         QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
-         int phase = phasev.isValid() ? phasev.toInt() : 2;
          bool prevent_autoload = false;
-         switch( phase )
+         switch( phaseForModule(service) )
          {
              case 0: // always autoload
                  break;
              case 1: // autoload only in KDE
-                 if( !kde_running )
+                 if (!kde_running) {
                      prevent_autoload = true;
+                 }
                  break;
              case 2: // autoload delayed, only in KDE
              default:
+                 if (!loadPhase2Now) {
                  prevent_autoload = true;
+                 }
                  break;
          }
 
@@ -267,18 +288,15 @@
      kDebug(7020) << "Loading second phase autoload";
      KSharedConfig::Ptr config = KGlobal::config();
      KService::List kdedModules = KServiceTypeTrader::self()->query("KDEDModule");
-     for(KService::List::ConstIterator it = kdedModules.constBegin(); it != \
                kdedModules.constEnd(); ++it)
-     {
-         KService::Ptr service = *it;
-         bool autoload = service->property("X-KDE-Kded-autoload", \
                QVariant::Bool).toBool();
-         KConfigGroup cg(config, \
                QString("Module-%1").arg(service->desktopEntryName()));
-         autoload = cg.readEntry("autoload", autoload);
-         QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
-         int phase = phasev.isValid() ? phasev.toInt() : 2;
-         if( phase == 2 && autoload )
+    for(KService::List::ConstIterator it = kdedModules.constBegin(); it != \
kdedModules.constEnd(); ++it) { +        const KService::Ptr service = *it;
+        const bool autoload = isModuleAutoloaded(service);
+        if (autoload && phaseForModule(service) == 2) {
+            //kDebug(7020) << "2nd phase: loading" << service->desktopEntryName();
             loadModule(service, false);
      }
 }
+}
 
 void Kded::noDemandLoad(const QString &obj)
 {
--- trunk/KDE/kdelibs/kinit/kinit.cpp #1204124:1204125
@@ -1841,7 +1841,9 @@
 
    if (launch_kded)
    {
+      setenv("KDED_STARTED_BY_KDEINIT", "1", true);
       pid = launch( 1, KDED_EXENAME, 0 );
+      unsetenv("KDED_STARTED_BY_KDEINIT");
 #ifndef NDEBUG
       fprintf(stderr, "kdeinit4: Launched KDED, pid = %ld result = %d\n", (long) \
pid, d.result);  #endif


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

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