Bug 274281 [BeOS] BeOS lets events stay in port through the 'restarts' in LaunchChild causing crashes on faulty events.

patch by tqh <thesuckiestemail@yahoo.se> r=sergei_d sr=shaver (for the xpcom/ part)
This commit is contained in:
cbiesinger%web.de 2004-12-28 13:56:17 +00:00
parent fbf5e17933
commit 47d7110411
2 changed files with 53 additions and 13 deletions

View File

@ -23,6 +23,7 @@
* Duncan Wilcox <duncan@be.com>
* Yannick Koehler <ykoehler@mythrium.com>
* Makoto Hamanaka <VYA04230@nifty.com>
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -123,17 +124,32 @@ NS_IMETHODIMP nsAppShell::Create(int* argc, char ** argv)
PR_snprintf(semname, sizeof(semname), "sync%lx",
(long unsigned) PR_GetCurrentThread());
if((eventport = find_port(portname)) < 0)
/*
* Set up the port for communicating. As restarts thru execv may occur
* and ports survive those (with faulty events as result). Combined with the fact
* that plevent.c can setup the port ahead of us we need to take extra
* care that the port is created for this launch, otherwise we need to reopen it
* so that faulty messages gets lost.
*
* We do this by checking if the sem has been created. If it is we can reuse the port (if it exists).
* Otherwise we need to create the sem and the port, deleting any open ports before.
*/
syncsem = my_find_sem(semname);
eventport = find_port(portname);
if(B_ERROR != syncsem)
{
// we're here first
eventport = create_port(100, portname);
syncsem = create_sem(0, semname);
if(eventport < 0)
{
eventport = create_port(200, portname);
}
else
return NS_OK;
}
if(eventport >= 0)
{
// the PLEventQueue stuff (in plevent.c) created the queue before we started
syncsem = my_find_sem(semname);
delete_port(eventport);
}
eventport = create_port(200, portname);
syncsem = create_sem(0, semname);
return NS_OK;
}

View File

@ -903,7 +903,20 @@ failed:
/* hook up to the nsToolkit queue, however the appshell
* isn't necessairly started, so we might have to create
* the queue ourselves
*
* Set up the port for communicating. As restarts thru execv may occur
* and ports survive those (with faulty events as result). Combined with the fact
* that nsAppShell.cpp may or may not have created the port we need to take extra
* care that the port is created for this launch, otherwise we need to reopen it
* so that faulty messages gets lost.
*
* We do this by checking if the sem has been created. If it is we can reuse the port (if it exists).
* Otherwise we need to create the sem and the port, deleting any open ports before.
*/
sem_info info;
int32 cookie = 0;
char portname[64];
char semname[64];
PR_snprintf(portname, sizeof(portname), "event%lx",
@ -911,17 +924,28 @@ failed:
PR_snprintf(semname, sizeof(semname), "sync%lx",
(long unsigned) self->handlerThread);
if((self->eventport = find_port(portname)) < 0)
self->eventport = find_port(portname);
while(get_next_sem_info(0, &cookie, &info) == B_OK)
{
/* create port
*/
self->eventport = create_port(500, portname);
if(strcmp(semname, info.name) != 0) {
continue;
}
//found semaphore
if(self->eventport < 0) {
self->eventport = create_port(200, portname);
}
return PR_SUCCESS;
}
//setup the port and semaphore
if(self->eventport >= 0)
{
delete_port( self->eventport );
}
self->eventport = create_port(200, portname);
/* We don't use the sem, but it has to be there
*/
create_sem(0, semname);
}
return PR_SUCCESS;
#else
return PR_SUCCESS;