diff options
Diffstat (limited to 'portage_with_autodep/pym/_emerge/EventsLogger.py')
-rw-r--r-- | portage_with_autodep/pym/_emerge/EventsLogger.py | 102 |
1 files changed, 47 insertions, 55 deletions
diff --git a/portage_with_autodep/pym/_emerge/EventsLogger.py b/portage_with_autodep/pym/_emerge/EventsLogger.py index 1ade9fd..68b3c67 100644 --- a/portage_with_autodep/pym/_emerge/EventsLogger.py +++ b/portage_with_autodep/pym/_emerge/EventsLogger.py @@ -100,69 +100,62 @@ class EventsLogger(threading.Thread): continue #import pdb; pdb.set_trace() - #try: - message=record.split(b"\0") - #except UnicodeDecodeError: - # print("Bad message %s" % record) - # continue + try: + message=record.decode("utf8").split("\0") + except UnicodeDecodeError: + print("Bad message %s" % record) + continue # continue #print(message) try: - eventname,filename,stage,result=message[1:5] - eventname=eventname.decode("utf-8") - stage=stage.decode("utf-8") - result=result.decode("utf-8") - except IndexError: - print("IndexError while parsing %s" % record) - except ValueError: - print("ValueError while parsing %s" % record) - except UnicodeDecodeError: - print("UnicodeDecodeError while parsing %s" % record) - - if result=="ASKING": - if self.filter_proc(eventname,filename,stage): - s.sendall(b"ALLOW\0") + if message[4]=="ASKING": + if self.filter_proc(message[1],message[2],message[3]): + s.sendall(b"ALLOW\0") + else: + # TODO: log through portage infrastructure + #print("Blocking an access to %s" % message[2]) + s.sendall(b"DENY\0") else: - # TODO: log through portage infrastructure - #print("Blocking an access to %s" % message[2]) - s.sendall(b"DENY\0") - else: - if not stage in self.events: - self.events[stage]=[{},{}] - - hashofsucesses=self.events[stage][0] - hashoffailures=self.events[stage][1] - - if result=="DENIED": - print("Blocking an access to %s" % filename) - - if result=="OK": - if not filename in hashofsucesses: - hashofsucesses[filename]=[False,False] - - readed_or_writed=hashofsucesses[filename] - - if eventname=="read": - readed_or_writed[0]=True - elif eventname=="write": - readed_or_writed[1]=True - - elif result[0:3]=="ERR" or result=="DENIED": - if not filename in hashoffailures: - hashoffailures[filename]=[False,False] - notfound_or_blocked=hashoffailures[filename] - - if result=="ERR/2": - notfound_or_blocked[0]=True - elif result=="DENIED": - notfound_or_blocked[1]=True + eventname,filename,stage,result=message[1:5] - else: - print("Error in logger module<->analyser protocol") + if not stage in self.events: + self.events[stage]=[{},{}] + hashofsucesses=self.events[stage][0] + hashoffailures=self.events[stage][1] + + if result=="DENIED": + print("Blocking an access to %s" % filename) + + if result=="OK": + if not filename in hashofsucesses: + hashofsucesses[filename]=[False,False] + + readed_or_writed=hashofsucesses[filename] + + if eventname=="read": + readed_or_writed[0]=True + elif eventname=="write": + readed_or_writed[1]=True + + elif result[0:3]=="ERR" or result=="DENIED": + if not filename in hashoffailures: + hashoffailures[filename]=[False,False] + notfound_or_blocked=hashoffailures[filename] + + if result=="ERR/2": + notfound_or_blocked[0]=True + elif result=="DENIED": + notfound_or_blocked[1]=True + + else: + print("Error in logger module<->analyser protocol") + + except IndexError: + print("IndexError while parsing %s" % record) except IOError as e: if e.errno!=4: # handling "Interrupted system call" errors raise @@ -184,5 +177,4 @@ class EventsLogger(threading.Thread): # We assume portage clears tmp folder, so no deleting a socket file # We assume that no new socket data will arrive after this moment - #print(self.events) return self.events |