-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
top: Add printing option for security attributes
Signed-off-by: iipeace <[email protected]>
- Loading branch information
Showing
1 changed file
with
49 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
__credits__ = "Peace Lee" | ||
__license__ = "GPLv2" | ||
__version__ = "3.9.8" | ||
__revision__ = "240127" | ||
__revision__ = "240129" | ||
__maintainer__ = "Peace Lee" | ||
__email__ = "[email protected]" | ||
__repository__ = "https://github.com/iipeace/guider" | ||
|
@@ -25942,6 +25942,7 @@ class SysMgr(object): | |
|
||
# flag # | ||
affinityEnable = False | ||
attrEnable = False | ||
barGraphEnable = None | ||
binderEnable = False | ||
blockEnable = False | ||
|
@@ -33372,7 +33373,7 @@ def isValidEnableOption(options): | |
if not options: | ||
return False | ||
|
||
optionList = "BCDEFGHILMNOPRSUTWXYabcdefghijklmnopqrrstuvwxy" | ||
optionList = "ABCDEFGHILMNOPRSUTWXYabcdefghijklmnopqrrstuvwxy" | ||
for opt in options: | ||
if not opt in optionList: | ||
return False | ||
|
@@ -33999,24 +34000,25 @@ def readSchedFeatures(): | |
return [] | ||
|
||
@staticmethod | ||
def readProcData(tid, path, num=-1): | ||
def readProcData(tid, path, num=-1, verb=True): | ||
path = "%s/%s/%s" % (SysMgr.procPath, tid, path) | ||
|
||
try: | ||
f = open(path, "r") | ||
|
||
if num == -1: | ||
return f.readlines() | ||
elif num == 0: | ||
return f.readline().replace("\n", "") | ||
else: | ||
return f.readline().replace("\n", "").split()[num - 1] | ||
except SystemExit: | ||
sys.exit(0) | ||
except: | ||
SysMgr.printOpenErr(path) | ||
if verb: | ||
SysMgr.printOpenErr(path) | ||
return None | ||
|
||
if num == -1: | ||
return f.readlines() | ||
elif num == 0: | ||
return f.readline().replace("\n", "") | ||
else: | ||
return f.readline().replace("\n", "").split()[num - 1] | ||
|
||
@staticmethod | ||
def hasMainArg(dash=False): | ||
if len(sys.argv) <= 2 or (not dash and sys.argv[2].startswith("-")): | ||
|
@@ -34566,9 +34568,9 @@ def printHelp(force=False, isExit=True): | |
topSubStr = """ | ||
Options: | ||
-e <CHARACTER> enable options | ||
[ a:affinity | b:block | B:bar | c:cpu | ||
C:compress | d:disk | D:DWARF | e:encode | ||
E:exec | f:float | F:wfc | G:cgroup | ||
[ a:affinity | A:secAttr | b:block | B:bar | ||
c:cpu | C:compress | d:disk | D:DWARF | ||
e:encode | E:exec | f:float | F:wfc | G:cgroup | ||
h:sigHandler | H:sched | i:irq | I:elastic | ||
k:peak | l:threshold | L:cmdline | m:mem | ||
M:min | n:net | N:namespace | o:oomScore | ||
|
@@ -45249,6 +45251,7 @@ def _setOpt(items, val, name): | |
|
||
_setOpt(items, SysMgr.affinityEnable, "AFNT ") | ||
_setOpt(items, SysMgr.andlogEnable, "ANDL ") | ||
_setOpt(items, SysMgr.attrEnable, "ATTR ") | ||
_setOpt(items, SysMgr.barGraphEnable, "BAR ") | ||
_setOpt(items, SysMgr.blockEnable, "BLOCK ") | ||
_setOpt(items, SysMgr.cmdlineEnable, "CMD ") | ||
|
@@ -48210,7 +48213,7 @@ def printPipe(line="", newline=True, flush=False, pager=True, trim=True): | |
# defopt = '-FRSXMQi' | ||
defopt = "-FRXMQi" | ||
|
||
# set SIGCHLD # | ||
# receive SIGCHLD # | ||
signal.signal(signal.SIGCHLD, signal.SIG_DFL) | ||
|
||
# verify pager option support # | ||
|
@@ -50016,6 +50019,8 @@ def parseAnalOption(option=None): | |
TaskAnalyzer.setLastField("wchan") | ||
elif "h" in options: | ||
TaskAnalyzer.setLastField("signal") | ||
elif "A" in options: | ||
TaskAnalyzer.setLastField("attr") | ||
|
||
if "f" in options: | ||
SysMgr.floatEnable = True | ||
|
@@ -55603,7 +55608,7 @@ def _enableSigPipe(): | |
myEnv = deepcopy(os.environ) | ||
myEnv["REMOTERUN"] = "True" | ||
|
||
# set SIGCHLD # | ||
# receive SIGCHLD # | ||
signal.signal(signal.SIGCHLD, signal.SIG_DFL) | ||
|
||
# set print flag # | ||
|
@@ -58822,6 +58827,10 @@ def _getMemUsage(pid): | |
buf = buf[pos:].split("\n") | ||
info = buf.pop(0) | ||
pid = info.split("(", 1)[1].split(")", 1)[0] | ||
if not SysMgr.isAlive(pid): | ||
procInfo = info[info.find(":") + 2 :].split("]", 1)[0] | ||
SysMgr.printErr("%s is not alive" % procInfo) | ||
continue | ||
pids[pid] = None | ||
bufLen = len(buf) | ||
pos = 0 | ||
|
@@ -59095,6 +59104,12 @@ def _getMemUsage(pid): | |
for call in callList: | ||
memsProc.setdefault(pid, []) | ||
memsProc[pid].append(call[:2]) | ||
|
||
# check target process list # | ||
if not pids: | ||
SysMgr.printErr("no target process alive") | ||
return | ||
|
||
elif SysMgr.hasMainArg(): | ||
targetList = SysMgr.getMainArgs(False) | ||
elif SysMgr.filterGroup: | ||
|
@@ -59151,6 +59166,8 @@ def _getMemUsage(pid): | |
try: | ||
dbgObj = Debugger(pid) | ||
dbgObj.initValues() | ||
except SystemExit: | ||
sys.exit(0) | ||
except: | ||
continue | ||
|
||
|
@@ -66342,7 +66359,7 @@ def _cputask(idx, load): | |
signal.signal(signal.SIGALRM, SysMgr.onAlarm) | ||
signal.alarm(SysMgr.intervalEnable) | ||
|
||
# ignore SIGCHLD # | ||
# receive SIGCHLD # | ||
signal.signal(signal.SIGCHLD, signal.SIG_DFL) | ||
except SystemExit: | ||
sys.exit(0) | ||
|
@@ -85555,6 +85572,9 @@ def attach(self, pid=None, verb=False, cont=False): | |
) | ||
return -1 | ||
|
||
# recover SIGCHLD # | ||
signal.signal(signal.SIGCHLD, signal.SIG_DFL) | ||
|
||
doExit = False | ||
|
||
while 1: | ||
|
@@ -119845,6 +119865,7 @@ def readTraceData(fname): | |
@staticmethod | ||
def setLastField(option): | ||
SysMgr.affinityEnable = False | ||
SysMgr.attrEnable = False | ||
SysMgr.wchanEnable = False | ||
SysMgr.sigHandlerEnable = False | ||
SysMgr.oomEnable = False | ||
|
@@ -119860,6 +119881,8 @@ def setLastField(option): | |
SysMgr.sigHandlerEnable = True | ||
elif option == "oom": | ||
SysMgr.oomEnable = True | ||
elif option == "attr": | ||
SysMgr.attrEnable = True | ||
else: | ||
SysMgr.printErr("failed to set '%s' as a last field" % option) | ||
|
||
|
@@ -135406,6 +135429,8 @@ def _getTypes(): | |
etc = "SignalHandler" | ||
elif SysMgr.nsEnable: | ||
etc = "Namespace[%s]" % SysMgr.nsType | ||
elif SysMgr.attrEnable: | ||
etc = "SecurityAttr" | ||
elif SysMgr.processEnable: | ||
etc = "Parent" | ||
else: | ||
|
@@ -135902,6 +135927,11 @@ def _memFactorPG(stat): | |
if SysMgr.wchanEnable: | ||
self.saveProcWchanData(value["taskPath"], idx) | ||
|
||
# save attr info # | ||
if SysMgr.attrEnable: | ||
vattr = SysMgr.readProcData(idx, "attr/current", verb=False) | ||
value["attr"] = "%22s" % vattr[0].strip() if vattr else "None" | ||
|
||
# save fdinfo # | ||
if "DMABUF" in SysMgr.environList: | ||
self.saveFdinfoData(idx) | ||
|
@@ -136106,6 +136136,8 @@ def _memFactorPG(stat): | |
nsid = os.readlink("%s/ns/%s" % (value["taskPath"], ns)) | ||
nsid = nsid[len(ns) + 2 : -1] | ||
etc = self.nsProcData[ns][nsid] | ||
elif SysMgr.attrEnable: | ||
etc = value["attr"] | ||
else: | ||
pgid = procData[idx]["stat"][self.ppidIdx] | ||
if pgid == "0": | ||
|