Catch a app_server crash in the debug server. Let the registrar restart the app_server and notify all apps.

This commit is contained in:
czeidler
2012-01-22 15:30:14 +13:00
parent 403e134862
commit 04209cdd81
5 changed files with 72 additions and 1 deletions
+4
View File
@@ -13,6 +13,10 @@
#include <Roster.h> #include <Roster.h>
const int32 kMsgAppServerRestarted = 'ASRe';
const int32 kMsgRestartAppServer = 'ReAS';
class BRoster::Private { class BRoster::Private {
public: public:
Private() : fRoster(const_cast<BRoster*>(be_roster)) {} Private() : fRoster(const_cast<BRoster*>(be_roster)) {}
+20 -1
View File
@@ -25,6 +25,7 @@
#include <Locale.h> #include <Locale.h>
#include <Path.h> #include <Path.h>
#include <MessengerPrivate.h>
#include <RegistrarDefs.h> #include <RegistrarDefs.h>
#include <RosterPrivate.h> #include <RosterPrivate.h>
#include <Server.h> #include <Server.h>
@@ -865,8 +866,10 @@ TeamDebugHandler::_HandlerThread()
kill = true; kill = true;
} }
bool isGuiServer = _IsGUIServer();
// kill the team or hand it over to the debugger // kill the team or hand it over to the debugger
thread_id debuggerThread; thread_id debuggerThread = -1;
if (kill) { if (kill) {
// The team shall be killed. Since that is also the handling in case // The team shall be killed. Since that is also the handling in case
// an error occurs while handing over the team to the debugger, we do // an error occurs while handing over the team to the debugger, we do
@@ -919,6 +922,22 @@ TeamDebugHandler::_HandlerThread()
// remove this handler from the roster and delete it // remove this handler from the roster and delete it
TeamDebugHandlerRoster::Default()->RemoveHandler(fTeam); TeamDebugHandlerRoster::Default()->RemoveHandler(fTeam);
if (isGuiServer) {
// wait till debugging is done
status_t dummy;
wait_for_thread(debuggerThread, &dummy);
// find the registrar port
port_id rosterPort = find_port(BPrivate::get_roster_port_name());
port_info info;
BMessenger messenger;
if (rosterPort >= 0 && get_port_info(rosterPort, &info) == B_OK) {
BMessenger::Private(messenger).SetTo(info.team, rosterPort,
B_PREFERRED_TOKEN);
}
messenger.SendMessage(kMsgRestartAppServer);
}
delete this; delete this;
return B_OK; return B_OK;
+6
View File
@@ -350,6 +350,12 @@ Registrar::_MessageReceived(BMessage *message)
} }
break; break;
case kMsgRestartAppServer:
{
fRoster->HandleRestartAppServer(message);
break;
}
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
+40
View File
@@ -28,6 +28,7 @@
#include <AppMisc.h> #include <AppMisc.h>
#include <MessagePrivate.h> #include <MessagePrivate.h>
#include <MessengerPrivate.h> #include <MessengerPrivate.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
#include <storage_support.h> #include <storage_support.h>
@@ -1139,6 +1140,45 @@ TRoster::HandleSaveRecentLists(BMessage* request)
} }
void
TRoster::HandleRestartAppServer(BMessage* request)
{
BAutolock _(fLock);
// TODO: if an app_server is still running, stop it first
const char* pathString;
if (request->FindString("path", &pathString) != B_OK)
pathString = "/boot/system/servers";
BPath path(pathString);
path.Append("app_server");
// NOTE: its required at some point that the binary name is "app_server"
const char **argv = new const char * [2];
argv[0] = strdup(path.Path());
argv[1] = NULL;
thread_id threadId = load_image(1, argv, (const char**)environ);
int i;
for (i = 0; i < 1; i++)
delete argv[i];
delete [] argv;
resume_thread(threadId);
// give the server some time to create the server port
snooze(100000);
// notify all apps
// TODO: whats about ourself?
AppInfoListMessagingTargetSet targetSet(fRegisteredApps);
if (targetSet.HasNext()) {
// send the messages
BMessage message(kMsgAppServerRestarted);
MessageDeliverer::Default()->DeliverMessage(&message, targetSet);
}
}
/*! \brief Clears the current list of recent documents /*! \brief Clears the current list of recent documents
*/ */
void void
+2
View File
@@ -59,6 +59,8 @@ public:
void HandleLoadRecentLists(BMessage* request); void HandleLoadRecentLists(BMessage* request);
void HandleSaveRecentLists(BMessage* request); void HandleSaveRecentLists(BMessage* request);
void HandleRestartAppServer(BMessage* request);
void ClearRecentDocuments(); void ClearRecentDocuments();
void ClearRecentFolders(); void ClearRecentFolders();
void ClearRecentApps(); void ClearRecentApps();