-
Notifications
You must be signed in to change notification settings - Fork 4
/
linux.py
executable file
·62 lines (50 loc) · 1.87 KB
/
linux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import time
import os
from Peach.agent import Monitor
class LinuxApport(Monitor):
def __init__(self, args):
if 'Executable' in args:
self.programPath = str(args['ProgramPath']).replace("'''", "")
self.processName = os.path.basename(self.programPath)
else:
self.processName = None
if 'LogFolder' in args:
self.logFolder = str(args['LogFolder']).replace("'''", "")
else:
self.logFolder = "/var/crash/"
if 'Apport' in args:
self.Apport = self.logFolder = str(args['Apport']).replace("'''", "")
else:
self.Apport = "/usr/share/apport/apport"
self._name = "LinuxApport"
self.data = None
self.startingFiles = None
def OnTestStarting(self):
self.startingFiles = os.listdir(self.logFolder)
def GetMonitorData(self):
if not self.data:
return None
return {"LinuxApport.txt": self.data}
def DetectedFault(self):
try:
time.sleep(0.25)
time.sleep(0.25)
self.data = None
for f in os.listdir(self.logFolder):
if f not in self.startingFiles and f.endswith(".crash") and \
(self.processName is None or f.find(self.processName) > -1):
fd = open(os.path.join(self.logFolder, f), "rb")
self.data = fd.read()
fd.close()
os.unlink(os.path.join(self.logFolder, f))
return True
return False
except:
print(sys.exc_info())
return False
def StopRun(self):
return False