servers & kits: Rehabilitate app_server restart functionality.
* It's not really possible to distinguish between a first startup
and a restart inside app_server itself. Due to the new BServer
setup, the same port will still be used, too. So, change the
messages sent to just "AppServerStarted".
* Since the message is sent out much later than the port is created,
by the time applications see it, the app_server may have already
been started a while and applications may have connected to it.
So, check if we really need to reconnect in BApplication before
actually trying to do that.
* BWindow now starts with updates disabled, so they must be
enabled after reconnecting.
After this commit, basic app_server restart functionality works again;
it's restarted automatically by launch_daemon after dying or being killed
and applications automatically reconnect. However, some problems still
linger (e.g. Terminal doesn't always recreate its windows, colors
on the Desktop look wrong, missing desktop background image, etc.)
Diff
headers/private/app/RosterPrivate.h | 3 +--
src/kits/app/Application.cpp | 10 +++++++++-
src/kits/interface/Window.cpp | 3 ++-
src/servers/app/AppServer.cpp | 7 ++++++-
src/servers/input/InputServer.cpp | 3 ++-
src/servers/registrar/Registrar.cpp | 10 ++++++----
src/servers/registrar/TRoster.cpp | 29 ++---------------------------
src/servers/registrar/TRoster.h | 2 +-
8 files changed, 28 insertions(+), 39 deletions(-)
@@ -13,8 +13,7 @@
#include <Roster.h>
const int32 kMsgAppServerRestarted = 'ASRe';
const int32 kMsgRestartAppServer = 'ReAS';
const int32 kMsgAppServerStarted = '_ASt';
class BRoster::Private {
@@ -691,7 +691,7 @@
be_roster->ActivateApp(Team());
break;
case kMsgAppServerRestarted:
case kMsgAppServerStarted:
_ReconnectToServer();
break;
@@ -1454,6 +1454,12 @@
void
BApplication::_ReconnectToServer()
{
team_info dummy;
if (get_team_info(fServerLink->TargetTeam(), &dummy) == B_OK) {
return;
}
delete_port(fServerLink->ReceiverPort());
@@ -1470,7 +1476,7 @@
if (window == NULL)
continue;
BMessenger windowMessenger(window);
windowMessenger.SendMessage(kMsgAppServerRestarted);
windowMessenger.SendMessage(kMsgAppServerStarted);
}
reconnect_bitmaps_to_app_server();
@@ -739,7 +739,7 @@
if (message->what == B_KEY_DOWN)
_KeyboardNavigation();
if (message->what == (int32)kMsgAppServerRestarted) {
if (message->what == kMsgAppServerStarted) {
fLink->SetSenderPort(
BApplication::Private::ServerLink()->SenderPort());
@@ -786,6 +786,7 @@
fTopView->_CreateSelf();
EnableUpdates();
_SendShowOrHideMessage();
}
@@ -17,6 +17,7 @@
#include <AutoDeleter.h>
#include <LaunchRoster.h>
#include <PortLink.h>
#include <RosterPrivate.h>
#include "BitmapManager.h"
#include "Desktop.h"
@@ -70,15 +71,19 @@
gBitmapManager = new BitmapManager();
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
#if 0
#ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST
BMessage data;
data.AddString("name", "app_server");
data.AddInt32("session", 0);
BLaunchRoster().Target("login", data);
#endif
BMessage request(kMsgAppServerStarted);
BRoster::Private().SendTo(&request, NULL, false);
#endif
}
@@ -582,9 +582,10 @@
return;
}
case kMsgAppServerRestarted:
case kMsgAppServerStarted:
{
BApplication::MessageReceived(message);
BPrivate::AppServerLink link;
link.StartMessage(AS_REGISTER_INPUT_SERVER);
link.Flush();
@@ -51,7 +51,7 @@
/*! \brief Creates the registrar application class.
\param error Passed to the BApplication constructor for returning an
\param error Passed to the BServer constructor for returning an
error code.
*/
Registrar::Registrar(status_t* _error)
@@ -375,9 +375,11 @@
}
break;
case kMsgRestartAppServer:
case kMsgAppServerStarted:
{
fRoster->HandleRestartAppServer(message);
fRoster->HandleAppServerStarted(message);
break;
}
@@ -477,7 +479,7 @@
"registrar main() caught exception: %s", exception.what());
debugger(buffer);
} catch (...) {
debugger("registrar main() caught unknown exception");
debugger("registrar main() caught unknown exception");
}
PRINT("delete app...\n");
@@ -1141,39 +1141,14 @@
void
TRoster::HandleRestartAppServer(BMessage* request)
TRoster::HandleAppServerStarted(BMessage* request)
{
BAutolock _(fLock);
const char* pathString;
if (request->FindString("path", &pathString) != B_OK)
pathString = "/boot/system/servers";
BPath path(pathString);
path.Append("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);
snooze(100000);
AppInfoListMessagingTargetSet targetSet(fRegisteredApps);
if (targetSet.HasNext()) {
BMessage message(kMsgAppServerRestarted);
BMessage message(kMsgAppServerStarted);
MessageDeliverer::Default()->DeliverMessage(&message, targetSet);
}
}
@@ -56,7 +56,7 @@
void HandleLoadRecentLists(BMessage* request);
void HandleSaveRecentLists(BMessage* request);
void HandleRestartAppServer(BMessage* request);
void HandleAppServerStarted(BMessage* request);
void ClearRecentDocuments();
void ClearRecentFolders();