diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index 64a0572acb..015c0bd879 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. +// Copyright (c) 2001-2005, Haiku, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -524,10 +524,10 @@ void AppServer::InitDecorators(void) \param buffer Attachment buffer for the message. */ -void AppServer::DispatchMessage(int32 code, BPortLink &msg) +void +AppServer::DispatchMessage(int32 code, BPortLink &msg) { - switch(code) - { + switch (code) { case AS_CREATE_APP: { // Create the ServerApp to node monitor a new BApplication @@ -540,35 +540,40 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg) // 4) char * - signature of the regular app // Find the necessary data - team_id clientTeamID=-1; - port_id clientLooperPort=-1; - port_id app_port=-1; - int32 htoken=B_NULL_TOKEN; - char *app_signature=NULL; + team_id clientTeamID = -1; + port_id clientLooperPort = -1; + port_id app_port = -1; + int32 htoken = B_NULL_TOKEN; + char *app_signature = NULL; msg.Read(&app_port); msg.Read(&clientLooperPort); msg.Read(&clientTeamID); msg.Read(&htoken); msg.ReadString(&app_signature); - - // Create the ServerApp subthread for this app - acquire_sem(fAppListLock); - - port_id server_listen=create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature); - if(server_listenAddItem(newapp); - + fAppList->AddItem(app); + release_sem(fAppListLock); BPortLink replylink(app_port); @@ -577,34 +582,29 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg) replylink.Flush(); // This is necessary because BPortLink::ReadString allocates memory - if(app_signature) - free(app_signature); - + free(app_signature); break; } case AS_DELETE_APP: { // Delete a ServerApp. Received only from the respective ServerApp when a // BApplication asks it to quit. - + // Attached Data: // 1) thread_id - thread ID of the ServerApp to be deleted - - int32 i=0, - appnum=fAppList->CountItems(); - - ServerApp *srvapp=NULL; - thread_id srvapp_id=-1; - if(msg.Read(&srvapp_id)CountItems(); + ServerApp *srvapp = NULL; + thread_id srvapp_id = -1; + + if (msg.Read(&srvapp_id) < B_OK) break; acquire_sem(fAppListLock); // Run through the list of apps and nuke the proper one - for(i= 0; i < appnum; i++) - { - srvapp=(ServerApp *)fAppList->ItemAt(i); + for (i = 0; i < appnum; i++) { + srvapp = (ServerApp *)fAppList->ItemAt(i); if(srvapp != NULL && srvapp->MonitorThreadID() == srvapp_id) { diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index cf1fc5571a..b755ceb618 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -86,7 +86,7 @@ MIME fSignature. */ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort, - team_id clientTeamID, int32 handlerID, const char* signature) + team_id clientTeamID, int32 handlerID, const char* signature) : fClientAppPort(sendport), fMessagePort(rcvport), @@ -109,18 +109,18 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort { if (fSignature == "") fSignature = "application/x-vnd.NULL-application-signature"; - + // although this isn't pretty, ATM we have only one RootLayer. // there should be a way that this ServerApp be attached to a particular // RootLayer to know which RootLayer's cursor to modify. ServerCursor *defaultCursor = desktop->ActiveRootLayer()->GetCursorManager().GetCursor(B_CURSOR_DEFAULT); - + if (defaultCursor) { fAppCursor = new ServerCursor(defaultCursor); fAppCursor->SetOwningTeam(fClientTeamID); } - + // fLockSem = create_sem(1, "ServerApp sem"); Run(); @@ -301,15 +301,26 @@ ServerApp::MonitorApp(void *data) int32 code; status_t err = B_OK; - while(!app->fQuitting) { + while (!app->fQuitting) { STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort)); err = msgqueue.GetNextMessage(&code); if (err < B_OK) { STRACE(("ServerApp::MonitorApp(): GetNextMessage returned %s\n", strerror(err))); + + // ToDo: this should kill the app, but it doesn't work + port_id serverport = find_port(SERVER_PORT_NAME); + if (serverport == B_NAME_NOT_FOUND){ + printf("PANIC: ServerApp %s could not find the app_server port!\n",app->fSignature.String()); + break; + } + app->fMsgSender->SetPort(serverport); + app->fMsgSender->StartMessage(AS_DELETE_APP); + app->fMsgSender->Attach(&app->fMonitorThreadID, sizeof(thread_id)); + app->fMsgSender->Flush(); break; } - switch(code) { + switch (code) { case AS_CREATE_WINDOW: { // Create the ServerWindow to node monitor a new OBWindow