0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <e32base.h>
|
|
17 |
#include "coredumpserver.h"
|
|
18 |
#include <debuglogging.h>
|
|
19 |
|
|
20 |
_LIT(KWildCard, "*");
|
|
21 |
|
|
22 |
/**
|
|
23 |
Checks whether another instance of the CDS exists in the system. It is checked
|
|
24 |
that:
|
|
25 |
* the secure id of another process is KSecurityServerSecureID??
|
|
26 |
* the PID is different to this process
|
|
27 |
* the FileName of the other process contains KCoreDumpServerName
|
|
28 |
|
|
29 |
The final check is only made for the benefit of hardware boards, in a
|
|
30 |
production device, the first two checks would be sufficient.
|
|
31 |
|
|
32 |
@return ETrue if the CDS is judged to be already running, EFalse otherwise
|
|
33 |
*/
|
|
34 |
TBool CDSAlreadyExists()
|
|
35 |
{
|
|
36 |
//find PID of this process
|
|
37 |
RProcess process;
|
|
38 |
TProcessId thisProcessId = process.Id();
|
|
39 |
|
|
40 |
TFindProcess find(KWildCard);
|
|
41 |
TFullName name;
|
|
42 |
|
|
43 |
//try and find another CDS based on SecureID value??, which has a different PID
|
|
44 |
while(find.Next(name)==KErrNone)
|
|
45 |
{
|
|
46 |
if (process.Open(find) == KErrNone)
|
|
47 |
{
|
|
48 |
//if(process.SecureId() == KSecurityServerSecureID) //does CDS have something like that
|
|
49 |
{
|
|
50 |
if(process.Id() != thisProcessId)
|
|
51 |
{
|
|
52 |
if(process.FileName().Find(KCoreDumpServerName) != KErrNotFound)
|
|
53 |
{
|
|
54 |
LOG_MSG( "core_dump_main.cpp::CDSAlreadyExists() returning: true" );
|
|
55 |
process.Close();
|
|
56 |
return ETrue;
|
|
57 |
}
|
|
58 |
}
|
|
59 |
}
|
|
60 |
}
|
|
61 |
process.Close();
|
|
62 |
}
|
|
63 |
|
|
64 |
LOG_MSG( "core_dump_main.cpp::CDSAlreadyExists() returning: false\n" );
|
|
65 |
return EFalse;
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
/**
|
|
70 |
Perform all server initialisation, in particular creation of the
|
|
71 |
scheduler and server and then run the scheduler
|
|
72 |
*/
|
|
73 |
|
|
74 |
void CCoreDumpServer::RunServerL()
|
|
75 |
{
|
|
76 |
|
|
77 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> new (ELeave) CActiveScheduler\n" );
|
|
78 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
|
|
79 |
|
|
80 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> PushL(scheduler)\n" );
|
|
81 |
CleanupStack::PushL(scheduler);
|
|
82 |
|
|
83 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> Install(scheduler)\n" );
|
|
84 |
CActiveScheduler::Install(scheduler);
|
|
85 |
|
|
86 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> CCoreDumpServer::NewLC()\n" );
|
|
87 |
CCoreDumpServer::NewLC();
|
|
88 |
|
|
89 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> Rendezvous(KErrNone)\n" );
|
|
90 |
RProcess::Rendezvous(KErrNone);
|
|
91 |
|
|
92 |
LOG_MSG( "CCoreDumpServer::RunServerL() -> CActiveScheduler::Start()\n" );
|
|
93 |
CActiveScheduler::Start();
|
|
94 |
|
|
95 |
// Free the server and active scheduler.
|
|
96 |
CleanupStack::PopAndDestroy(2, scheduler);
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
Entry point for Core Dump Server
|
|
101 |
*/
|
|
102 |
TInt E32Main()
|
|
103 |
{
|
|
104 |
__UHEAP_MARK;
|
|
105 |
|
|
106 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
107 |
|
|
108 |
TInt err = KErrNoMemory;
|
|
109 |
if (cleanup)
|
|
110 |
{
|
|
111 |
if(!CDSAlreadyExists())
|
|
112 |
{
|
|
113 |
TRAP(err, CCoreDumpServer::RunServerL());
|
|
114 |
}
|
|
115 |
else
|
|
116 |
err = KErrAlreadyExists;
|
|
117 |
delete cleanup;
|
|
118 |
}
|
|
119 |
|
|
120 |
LOG_MSG2( "<- core_dump_main.cpp::E32Main() returning: %d\n", err );
|
|
121 |
__UHEAP_MARKEND;
|
|
122 |
return KErrNone;
|
|
123 |
}
|
|
124 |
|