Esempio n. 1
0
 def __init__(self):
     threading.Thread.__init__(self)
     open(_QUEUE_PATH_,'a')
     self.PID_of_forked = []
     self.PID_of_forked_lock = threading.Lock() 
     self.ev = publish_subscribe.eventHandler.EventHandler(name="ForkDetector")
     self.ev.subscribe('spawner.spawn_and_attach_completed', self.respondToForkedProcess)
     try:
         self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, True)
     except:
         self.ev.publish("ERROR.forkDetector", {'info':"MSQ ya existente"})
         self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, False)
Esempio n. 2
0
 def __init__(self, spawmer):
     threading.Thread.__init__(self)
     open(_QUEUE_PATH_, _QUEUE_CHAR_)
     self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, True)
     self.spawmer = spawmer
     self.eventHandler = publish_subscribe.eventHandler.EventHandler()
     self.pidToattach = []
     self.eventHandler.subscribe("debugger.attached", self.attached)
Esempio n. 3
0
class ForkDetector(threading.Thread):
    
    def __init__(self, spawmer):
        threading.Thread.__init__(self)
        open(_QUEUE_PATH_, _QUEUE_CHAR_)
        self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, True)
        self.spawmer = spawmer
        self.eventHandler = publish_subscribe.eventHandler.EventHandler()
        self.pidToattach = []
        self.eventHandler.subscribe("debugger.attached", self.attached)
        
    def ObtenerID(self, msg):
        struct = unpack('<li', msg)
        return struct[1]
    
    def CrearRespuesta(self, pid):
        msg = pack('<li', pid, 0)
        return msg
    
    def salir(self):
        respuesta = pack('<li', 1, 1)
        self.msgQueue.push(respuesta)
        
    def attached(self, data):
        pid = data
        if pid in self.pidToattach:
            self.pidToattach.remove(pid)
            respuesta = self.CrearRespuesta(pid)
            self.msgQueue.push(respuesta)
        
    def run(self):
        while (True):
            msg = self.msgQueue.pull(type=1)
            pid = self.ObtenerID(msg)
            if pid == 1:
                del self.msgQueue
                return 0
            
            self.pidToattach.append(pid)
            self.eventHandler.publish("debugger.attach", pid)
Esempio n. 4
0
class ForkDetector(threading.Thread):
    
    def __init__(self):
        threading.Thread.__init__(self)
        open(_QUEUE_PATH_,'a')
        self.PID_of_forked = []
        self.PID_of_forked_lock = threading.Lock() 
        self.ev = publish_subscribe.eventHandler.EventHandler(name="ForkDetector")
        self.ev.subscribe('spawner.spawn_and_attach_completed', self.respondToForkedProcess)
        try:
            self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, True)
        except:
            self.ev.publish("ERROR.forkDetector", {'info':"MSQ ya existente"})
            self.msgQueue = MessageQueue(_QUEUE_PATH_, _QUEUE_CHAR_, 0666, False)
    
    def respondToForkedProcess(self, data):
        pid = data['pid']

        self.PID_of_forked_lock.acquire() 
        if pid in self.PID_of_forked:
            msg = self.CrearMensaje(pid, 0)
            self.msgQueue.push(msg)
            self.PID_of_forked.remove(pid)
        self.PID_of_forked_lock.release()
            

    def ObtenerPID(self, msg):
#         print msg.encode('hex_codec')
#         print len(msg)

        struct = unpack(_STRUCT_FORMAT_, msg) 
        
#         print struct
        return struct[1]
    
    def CrearMensaje(self, mtype ,pid):
        msg = pack(_STRUCT_FORMAT_, mtype, pid)
        return msg
    
    def finalizar(self):
        if hasattr(self, 'msgQueue'):
            msg = pack(_STRUCT_FORMAT_, 1, 0)
#             print msg.encode('hex_codec')
#             print sys.getsizeof(msg)
            self.msgQueue.push(msg)
            
    def run(self):
        salir = False
        try:
            while (not salir): 
                msg = self.msgQueue.pull(type=1)
                pid = self.ObtenerPID(msg)
                if pid == 0:
                    salir = True
                else:
                    self.PID_of_forked_lock.acquire() 
                    self.PID_of_forked.append(pid)
                    self.PID_of_forked_lock.release()
                    self.ev.publish("spawner.add-debugger-and-attach.ForkDetector", {'pid': pid, "continue": True})

        except Exception as inst:
            print type(inst)
            print traceback.format_exc()
            self.msgQueue = None
            
        finally:
            del self.msgQueue
            os.remove(_QUEUE_PATH_)
Esempio n. 5
0
   # From the value of one char, we calculate the other
   assert 0 <= char_id_in < 128
   char_id_out = char_id_in + 128

   # Because the MessageQueue constructor expect a 'char', we do the translate
   char_id_in = chr(char_id_in)
   char_id_out = chr(char_id_out)

   pid = str(os.getpid())

   syslog.openlog("inbound[%s]" % pid)
   syslog.syslog(syslog.LOG_INFO, "Init 'inbound' process. Creating queues. Arguments: Path: %s Char_in_id: %s GroupId: %i Localhost: %s NetworkName: %s PID: %s" % (
      path, hex(ord(char_id_in)), group_id, localhost_name, network_name, pid))
   userland_inbound_queue = MessageQueue(path, char_id_in, 0644, True)
   userland_outbound_queue = MessageQueue(path, char_id_out, 0644, True)

   localhost_name = ":".join([localhost_name, pid])
   
   driver = Driver(localhost_name, path, char_id_out, group_id, network_name, userland_inbound_queue)
   
   head_process = Popen(["python", "outbound.py", path, char_id_out, str(group_id), localhost_name])
   
   try:
      while True:
         try:
            syslog.syslog(syslog.LOG_INFO, "Pushing 'BrokenLink' in the output queue.")
            userland_outbound_queue.push(driver.create_linkbroken_msj())
            driver.clean()

            syslog.syslog(syslog.LOG_INFO, "Construction the ring")
Esempio n. 6
0
      print "  - network_name: the name of the network, which message addressed to network_name will be delivery to any node in that network (broadcast address)."
      print
      print "Note: you should NOT be executing this code by your self."
      sys.exit(1)

   
   path, char_id_out, group_id, localhost_name, network_name = sys.argv[1:]
   group_id = int(group_id)
   assert group_id >= 0
   assert ":" in localhost_name

   syslog.openlog("leader[%s]" % localhost_name.split(':')[1])
   syslog.syslog(syslog.LOG_INFO, "Init 'leader' process. Creating queue. Arguments: Path: %s Char_out_id: %s GroupId: %i Localhost: %s NetworkName: %s Parent PID: %s" % (
      path, hex(ord(char_id_out)), group_id, localhost_name.split(':')[0], network_name, localhost_name.split(':')[1]))

   userland_outbound_queue = MessageQueue(path, char_id_out, 0644, False)

   datagram_socket = None

   leader_beacon = ring.create_beacon('FIND', group_id, len(localhost_name), None, None, localhost_name, None, None, False)
   assert len(leader_beacon) < ring.BEACON_BUF_MAX_SIZE
 
   start_time = time.time()

   try:
      sender = socket_udp(True)
      receiver = socket_udp(False)
      time.sleep(beacon_service.DISCOVERY_TIME*4)
      while True:
         try:
            syslog.syslog(syslog.LOG_INFO, "Sending FIND beacon...")