diff options
author | 2011-05-25 21:26:40 +0000 | |
---|---|---|
committer | 2011-05-25 21:26:40 +0000 | |
commit | 0cd3a5959955d4e398984ef9f31d3e9602ac4fcd (patch) | |
tree | 28a62995cc485d02f1e951597af62565a8b3ac47 | |
parent | better proccess tracking logic (diff) | |
download | autodep-0cd3a5959955d4e398984ef9f31d3e9602ac4fcd.tar.gz autodep-0cd3a5959955d4e398984ef9f31d3e9602ac4fcd.tar.bz2 autodep-0cd3a5959955d4e398984ef9f31d3e9602ac4fcd.zip |
use sockets instead of pipes for IPC
-rw-r--r-- | logger/src/autodep/logfs/__init__.py | 0 | ||||
-rw-r--r-- | logger/src/autodep/logfs/__init__.pyc | bin | 0 -> 138 bytes | |||
-rw-r--r-- | logger/src/autodep/logfs/fstracer.py | 99 | ||||
-rw-r--r-- | logger/src/autodep/logfs/fstracer.pyc | bin | 0 -> 3519 bytes |
4 files changed, 98 insertions, 1 deletions
diff --git a/logger/src/autodep/logfs/__init__.py b/logger/src/autodep/logfs/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/logger/src/autodep/logfs/__init__.py diff --git a/logger/src/autodep/logfs/__init__.pyc b/logger/src/autodep/logfs/__init__.pyc Binary files differnew file mode 100644 index 0000000..ae3151f --- /dev/null +++ b/logger/src/autodep/logfs/__init__.pyc diff --git a/logger/src/autodep/logfs/fstracer.py b/logger/src/autodep/logfs/fstracer.py index abef285..8b5c61b 100644 --- a/logger/src/autodep/logfs/fstracer.py +++ b/logger/src/autodep/logfs/fstracer.py @@ -1,4 +1,101 @@ #!/usr/bin/env python2 +""" +This module is a bridge between low-level logging services and high level handling dependency logic +""" -class fstracer +import os +import time +import tempfile +import socket +import asyncore + +class socket_selecter(asyncore.dispatcher): + connects=0; + def __init__(self,path): + asyncore.dispatcher.__init__(self) + self.path=path + self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.set_reuse_addr() + self.bind(self.path) + self.listen(128) + + def handle_accept(self): + ret = self.accept() + if ret is None: + pass + else: + (sock,addr)=ret + print "Client accepted\n" + self.connects+=1 + handler = log_handler(sock,addr,self) + print "After client accepted connects=%s\n" % self.connects + + +class log_handler(asyncore.dispatcher_with_send): + + def __init__(self, sock, addr,listen_socket_dispatcher): + asyncore.dispatcher_with_send.__init__(self, sock) + self.addr = addr + self.buffer = '' + self.listen_sock_dispatcher=listen_socket_dispatcher + + def handle_read(self): + print self.recv(8192) + + def writable(self): + return (len(self.buffer) > 0) + + def handle_write(self): + pass + #self.send(self.buffer) + #self.buffer = '' + + def handle_close(self): + print "Client closed the socket\n" + self.listen_sock_dispatcher.connects-=1 + if self.listen_sock_dispatcher.connects == 0: + #pass + self.listen_sock_dispatcher.close() + self.close() + + + + +# run the program and get file access events +def getfsevents(prog_name,arguments): + # generating a random socketname + tmpdir = tempfile.mkdtemp() + socketname = os.path.join(tmpdir, 'socket') + + try: + pass + #os.mkfifo(fifoname) + except OSError, e: + print "Failed to create a socket for exchange data with logger: %s" % e + return () + else: + print socketname + + pid=os.fork() + if pid==0: + # wait while the socket opens + os.execvpe(prog_name, arguments,{ + "LD_PRELOAD":"/home/bay/gsoc/logger/src/hook_lib/file_hook.so", + "LOG_SOCKET":socketname + }) + os.exit(0) + else: + server = socket_selecter(socketname) + #fifo = open(fifoname, 'r') + + try: + asyncore.loop() + finally: + if os.path.exists(server.path): + os.unlink(server.path) + os.wait() + + pass + + diff --git a/logger/src/autodep/logfs/fstracer.pyc b/logger/src/autodep/logfs/fstracer.pyc Binary files differnew file mode 100644 index 0000000..9aeedac --- /dev/null +++ b/logger/src/autodep/logfs/fstracer.pyc |