app_server: Fixed broken ServerApp allocation.
* Did not use std::nothrow, but exceptions were not catched. * MessageLooper::Run() now returns a status code. * There are a lot more cases of a new without nothrow that need to be investigated.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku, Inc.
|
* Copyright 2001-2016, Haiku, Inc.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -176,10 +176,8 @@ AppServer::_CreateDesktop(uid_t userID, const char* targetScreen)
|
|||||||
desktop = new Desktop(userID, targetScreen);
|
desktop = new Desktop(userID, targetScreen);
|
||||||
|
|
||||||
status_t status = desktop->Init();
|
status_t status = desktop->Init();
|
||||||
if (status == B_OK) {
|
if (status == B_OK)
|
||||||
if (!desktop->Run())
|
status = desktop->Run();
|
||||||
status = B_ERROR;
|
|
||||||
}
|
|
||||||
if (status == B_OK && !fDesktops.AddItem(desktop))
|
if (status == B_OK && !fDesktops.AddItem(desktop))
|
||||||
status = B_NO_MEMORY;
|
status = B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku.
|
* Copyright 2001-2016, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -2539,10 +2539,16 @@ Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
if (link.ReadString(&appSignature) != B_OK)
|
if (link.ReadString(&appSignature) != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ServerApp* app = new ServerApp(this, clientReplyPort,
|
ServerApp* app = new (std::nothrow) ServerApp(this, clientReplyPort,
|
||||||
clientLooperPort, clientTeamID, htoken, appSignature);
|
clientLooperPort, clientTeamID, htoken, appSignature);
|
||||||
if (app->InitCheck() == B_OK
|
status_t status = B_OK;
|
||||||
&& app->Run()) {
|
if (app == NULL)
|
||||||
|
status = B_NO_MEMORY;
|
||||||
|
if (status == B_OK)
|
||||||
|
status = app->InitCheck();
|
||||||
|
if (status == B_OK)
|
||||||
|
status = app->Run();
|
||||||
|
if (status == B_OK) {
|
||||||
// add the new ServerApp to the known list of ServerApps
|
// add the new ServerApp to the known list of ServerApps
|
||||||
fApplicationsLock.Lock();
|
fApplicationsLock.Lock();
|
||||||
fApplications.AddItem(app);
|
fApplications.AddItem(app);
|
||||||
@@ -2553,7 +2559,7 @@ Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
// if everything went well, ServerApp::Run() will notify
|
// if everything went well, ServerApp::Run() will notify
|
||||||
// the client - but since it didn't, we do it here
|
// the client - but since it didn't, we do it here
|
||||||
BPrivate::LinkSender reply(clientReplyPort);
|
BPrivate::LinkSender reply(clientReplyPort);
|
||||||
reply.StartMessage(B_ERROR);
|
reply.StartMessage(status);
|
||||||
reply.Flush();
|
reply.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2007, Haiku.
|
* Copyright 2005-2016, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -30,7 +30,7 @@ MessageLooper::~MessageLooper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
status_t
|
||||||
MessageLooper::Run()
|
MessageLooper::Run()
|
||||||
{
|
{
|
||||||
BAutolock locker(this);
|
BAutolock locker(this);
|
||||||
@@ -44,17 +44,17 @@ MessageLooper::Run()
|
|||||||
fThread = spawn_thread(_message_thread, name, B_DISPLAY_PRIORITY, this);
|
fThread = spawn_thread(_message_thread, name, B_DISPLAY_PRIORITY, this);
|
||||||
if (fThread < B_OK) {
|
if (fThread < B_OK) {
|
||||||
fQuitting = true;
|
fQuitting = true;
|
||||||
return false;
|
return fThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resume_thread(fThread) != B_OK) {
|
if (resume_thread(fThread) != B_OK) {
|
||||||
fQuitting = true;
|
fQuitting = true;
|
||||||
kill_thread(fThread);
|
kill_thread(fThread);
|
||||||
fThread = -1;
|
fThread = -1;
|
||||||
return false;
|
return B_BAD_THREAD_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Haiku.
|
* Copyright 2005-2016, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
|
|
||||||
class MessageLooper : public BLocker {
|
class MessageLooper : public BLocker {
|
||||||
public:
|
public:
|
||||||
MessageLooper(const char* name);
|
MessageLooper(const char* name);
|
||||||
virtual ~MessageLooper();
|
virtual ~MessageLooper();
|
||||||
|
|
||||||
virtual bool Run();
|
virtual status_t Run();
|
||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
|
|
||||||
status_t PostMessage(int32 code,
|
status_t PostMessage(int32 code,
|
||||||
@@ -27,29 +27,33 @@ class MessageLooper : public BLocker {
|
|||||||
|
|
||||||
thread_id Thread() const { return fThread; }
|
thread_id Thread() const { return fThread; }
|
||||||
bool IsQuitting() const { return fQuitting; }
|
bool IsQuitting() const { return fQuitting; }
|
||||||
sem_id DeathSemaphore() const { return fDeathSemaphore; }
|
sem_id DeathSemaphore() const
|
||||||
|
{ return fDeathSemaphore; }
|
||||||
|
|
||||||
virtual port_id MessagePort() const = 0;
|
virtual port_id MessagePort() const = 0;
|
||||||
|
|
||||||
static status_t WaitForQuit(sem_id semaphore,
|
static status_t WaitForQuit(sem_id semaphore,
|
||||||
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void _PrepareQuit();
|
virtual void _PrepareQuit();
|
||||||
virtual void _GetLooperName(char* name, size_t length);
|
virtual void _GetLooperName(char* name, size_t length);
|
||||||
virtual void _DispatchMessage(int32 code, BPrivate::LinkReceiver &link);
|
virtual void _DispatchMessage(int32 code,
|
||||||
|
BPrivate::LinkReceiver& link);
|
||||||
virtual void _MessageLooper();
|
virtual void _MessageLooper();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static int32 _message_thread(void *_looper);
|
static int32 _message_thread(void*_looper);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
thread_id fThread;
|
thread_id fThread;
|
||||||
BPrivate::PortLink fLink;
|
BPrivate::PortLink fLink;
|
||||||
bool fQuitting;
|
bool fQuitting;
|
||||||
sem_id fDeathSemaphore;
|
sem_id fDeathSemaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const int32 kMsgQuitLooper = 'quit';
|
static const int32 kMsgQuitLooper = 'quit';
|
||||||
|
|
||||||
|
|
||||||
#endif /* MESSAGE_LOOPER_H */
|
#endif /* MESSAGE_LOOPER_H */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku.
|
* Copyright 2001-2016, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -105,7 +105,7 @@ ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort,
|
|||||||
fViewCursor(NULL),
|
fViewCursor(NULL),
|
||||||
fCursorHideLevel(0),
|
fCursorHideLevel(0),
|
||||||
fIsActive(false),
|
fIsActive(false),
|
||||||
fMemoryAllocator(new ClientMemoryAllocator(this))
|
fMemoryAllocator(new (std::nothrow) ClientMemoryAllocator(this))
|
||||||
{
|
{
|
||||||
if (fSignature == "")
|
if (fSignature == "")
|
||||||
fSignature = "application/no-signature";
|
fSignature = "application/no-signature";
|
||||||
@@ -194,6 +194,7 @@ ServerApp::~ServerApp()
|
|||||||
fWindowListLock.Lock();
|
fWindowListLock.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fMemoryAllocator != NULL)
|
||||||
fMemoryAllocator->Detach();
|
fMemoryAllocator->Detach();
|
||||||
fMapLocker.Lock();
|
fMapLocker.Lock();
|
||||||
|
|
||||||
@@ -204,6 +205,7 @@ ServerApp::~ServerApp()
|
|||||||
fPictureMap.begin()->second->SetOwner(NULL);
|
fPictureMap.begin()->second->SetOwner(NULL);
|
||||||
|
|
||||||
fDesktop->GetCursorManager().DeleteCursors(fClientTeam);
|
fDesktop->GetCursorManager().DeleteCursors(fClientTeam);
|
||||||
|
if (fMemoryAllocator != NULL)
|
||||||
fMemoryAllocator->ReleaseReference();
|
fMemoryAllocator->ReleaseReference();
|
||||||
|
|
||||||
STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature()));
|
STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature()));
|
||||||
@@ -224,6 +226,9 @@ ServerApp::InitCheck()
|
|||||||
if (fWindowListLock.Sem() < B_OK)
|
if (fWindowListLock.Sem() < B_OK)
|
||||||
return fWindowListLock.Sem();
|
return fWindowListLock.Sem();
|
||||||
|
|
||||||
|
if (fMemoryAllocator == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3318,10 +3323,12 @@ ServerApp::_CreateWindow(int32 code, BPrivate::LinkReceiver& link,
|
|||||||
if (window != NULL) {
|
if (window != NULL) {
|
||||||
status = window->Init(frame, (window_look)look, (window_feel)feel,
|
status = window->Init(frame, (window_look)look, (window_feel)feel,
|
||||||
flags, workspaces);
|
flags, workspaces);
|
||||||
if (status == B_OK && !window->Run()) {
|
if (status == B_OK) {
|
||||||
syslog(LOG_ERR, "ServerApp::_CreateWindow() - failed to run the "
|
status = window->Run();
|
||||||
"window thread\n");
|
if (status != B_OK) {
|
||||||
status = B_ERROR;
|
syslog(LOG_ERR, "ServerApp::_CreateWindow() - failed to run "
|
||||||
|
"the window thread\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user