Skip to content

Commit

Permalink
Fix castings objects in parent() and get_children()
Browse files Browse the repository at this point in the history
The old way didn't work because of the ProcessWrapper and its
delegating to the self._process. It lead to malfunction of the
`_apply_rules` method
  • Loading branch information
FrostyX committed Mar 31, 2015
1 parent eacd3bf commit 802a74c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions tracer/resources/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ProcessWrapper(object):
def __init__(self, pid=None):
self._process = psutil.Process(pid)

def __nonzero__(self):
return bool(self._process)

def name(self):
return self._attr("name")

Expand Down Expand Up @@ -118,13 +121,11 @@ def files(self):

return sorted(files)

@property
def parent(self):
"""The parent process casted from ``psutil.Process`` to tracer ``Process``"""
p = super(Process, self).parent()
if p:
p.__class__ = Process
return p
if self.ppid():
return Process(self.ppid())
return None

def username(self):
"""The user who owns the process. If user was deleted in the meantime,
Expand All @@ -140,9 +141,7 @@ def children(self, recursive=False):
"""The collection of process's children. Each of them casted from ``psutil.Process``
to tracer ``Process``."""
children = super(Process, self).children(recursive)
for child in children:
child.__class__ = Process
return ProcessesCollection(children)
return ProcessesCollection([Process(child.pid) for child in children])

@property
def exe(self):
Expand Down
4 changes: 2 additions & 2 deletions tracer/resources/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def trace_affected(self, user=None):
return ApplicationsCollection(affected.values())

def _apply_rules(self, process):
parent = process.parent
parent = process.parent()
if not parent:
return process

rule = self._rules.find(parent.name)
rule = self._rules.find(parent.name())

if not rule or not rule.action:
return process
Expand Down

0 comments on commit 802a74c

Please sign in to comment.