diff --git a/src/servers/registrar/TRoster.cpp b/src/servers/registrar/TRoster.cpp index 2e57215ad4..ea71218e51 100644 --- a/src/servers/registrar/TRoster.cpp +++ b/src/servers/registrar/TRoster.cpp @@ -61,6 +61,9 @@ pre-registered applications. */ +//! The maximal period of time an app may be early pre-registered (60 s). +const bigtime_t kMaximalEarlyPreRegistrationPeriod = 60000000LL; + // constructor /*! \brief Creates a new roster. @@ -732,6 +735,42 @@ TRoster::ActivateApp(RosterAppInfo *info) } } +// CheckSanity +/*! \brief Checks whether the (pre-)registered applications are still running. + + This is necessary, since killed applications don't unregister properly. +*/ +void +TRoster::CheckSanity() +{ + // not early (pre-)registered applications + AppInfoList obsoleteApps; + for (AppInfoList::Iterator it = fRegisteredApps.It(); it.IsValid(); ++it) { + team_info teamInfo; + if (get_team_info((*it)->team, &teamInfo) != B_OK) + obsoleteApps.AddInfo(*it); + } + // remove the apps + for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { + RemoveApp(*it); + delete *it; + } + // early pre-registered applications + obsoleteApps.MakeEmpty(); + bigtime_t timeLimit = system_time() - kMaximalEarlyPreRegistrationPeriod; + for (AppInfoList::Iterator it = fEarlyPreRegisteredApps.It(); + it.IsValid(); + ++it) { + if ((*it)->registration_time < timeLimit) + obsoleteApps.AddInfo(*it); + } + // remove the apps + for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { + fEarlyPreRegisteredApps.RemoveInfo(*it); + delete *it; + } +} + // _AppAdded /*! \brief Hook method invoked, when an application has been added. diff --git a/src/servers/registrar/TRoster.h b/src/servers/registrar/TRoster.h index cea0fb4394..973b98fe41 100644 --- a/src/servers/registrar/TRoster.h +++ b/src/servers/registrar/TRoster.h @@ -69,6 +69,8 @@ public: void RemoveApp(RosterAppInfo *info); void ActivateApp(RosterAppInfo *info); + void CheckSanity(); + private: // hook functions void _AppAdded(RosterAppInfo *info);