sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <f32file.h>
|
sl@0
|
17 |
#include <e32debug.h>
|
sl@0
|
18 |
|
sl@0
|
19 |
//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
|
sl@0
|
20 |
//processes (or some other) when they leftover and may cause OOM condinitons.
|
sl@0
|
21 |
static void KillProcessL(const TDesC& aProcessName)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
TFullName name;
|
sl@0
|
24 |
|
sl@0
|
25 |
TInt err = KErrNotFound;
|
sl@0
|
26 |
|
sl@0
|
27 |
TBuf<64> pattern(aProcessName);
|
sl@0
|
28 |
TInt length = pattern.Length();
|
sl@0
|
29 |
pattern += _L("*");
|
sl@0
|
30 |
TFindProcess procFinder(pattern);
|
sl@0
|
31 |
|
sl@0
|
32 |
while(procFinder.Next(name) == KErrNone)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
if(name.Length() > length)
|
sl@0
|
35 |
{//If found name is a string containing aProcessName string.
|
sl@0
|
36 |
TChar c(name[length]);
|
sl@0
|
37 |
if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
|
sl@0
|
38 |
{//If the found name is other valid application name starting with aProcessName string.
|
sl@0
|
39 |
RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
|
sl@0
|
40 |
continue;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
}
|
sl@0
|
43 |
RProcess proc;
|
sl@0
|
44 |
|
sl@0
|
45 |
err = proc.Open(name);
|
sl@0
|
46 |
if(err == KErrNone)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
|
sl@0
|
49 |
//If the process is alive, terminate it
|
sl@0
|
50 |
if(proc.ExitType() == EExitPending)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
proc.Kill(0);
|
sl@0
|
53 |
RDebug::Print(_L("\"%S\" process killed.\n"), &name);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
//If the process has already died record the error
|
sl@0
|
57 |
else err = KErrDied;
|
sl@0
|
58 |
|
sl@0
|
59 |
}
|
sl@0
|
60 |
proc.Close();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
User::Leave(err);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
void DoTestsL()
|
sl@0
|
66 |
{
|
sl@0
|
67 |
TFileName name;
|
sl@0
|
68 |
User::CommandLine(name);
|
sl@0
|
69 |
KillProcessL(name);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
GLDEF_C TInt E32Main()
|
sl@0
|
73 |
{
|
sl@0
|
74 |
CTrapCleanup* cleanup=CTrapCleanup::New();
|
sl@0
|
75 |
if(cleanup == NULL)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
return KErrNoMemory;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
TRAPD(err,DoTestsL());
|
sl@0
|
81 |
|
sl@0
|
82 |
delete cleanup;
|
sl@0
|
83 |
return err;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|