/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2011-10-09 15:21:16 UTC
  • mfrom: (505.1.11 teddy)
  • Revision ID: teddy@recompile.se-20111009152116-obbil3b2sxu2sixl
Merge from Teddy

Show diffs side-by-side

added added

removed removed

Lines of Context:
465
465
            timeout = self.timeout
466
466
        self.last_checked_ok = datetime.datetime.utcnow()
467
467
        gobject.source_remove(self.disable_initiator_tag)
468
 
        self.expires = datetime.datetime.utcnow() + timeout
469
468
        self.disable_initiator_tag = (gobject.timeout_add
470
469
                                      (_timedelta_to_milliseconds
471
470
                                       (timeout), self.disable))
 
471
        self.expires = datetime.datetime.utcnow() + timeout
472
472
    
473
473
    def need_approval(self):
474
474
        self.last_approval_request = datetime.datetime.utcnow()
1394
1394
                        return
1395
1395
                    
1396
1396
                    #wait until timeout or approved
1397
 
                    #x = float(client
1398
 
                    #          ._timedelta_to_milliseconds(delay))
1399
1397
                    time = datetime.datetime.now()
1400
1398
                    client.changedstate.acquire()
1401
1399
                    (client.changedstate.wait
1516
1514
        except:
1517
1515
            self.handle_error(request, address)
1518
1516
        self.close_request(request)
1519
 
            
 
1517
    
1520
1518
    def process_request(self, request, address):
1521
1519
        """Start a new process to process the request."""
1522
 
        multiprocessing.Process(target = self.sub_process_main,
1523
 
                                args = (request, address)).start()
 
1520
        proc = multiprocessing.Process(target = self.sub_process_main,
 
1521
                                       args = (request,
 
1522
                                               address))
 
1523
        proc.start()
 
1524
        return proc
1524
1525
 
1525
1526
 
1526
1527
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1532
1533
        """
1533
1534
        parent_pipe, self.child_pipe = multiprocessing.Pipe()
1534
1535
        
1535
 
        super(MultiprocessingMixInWithPipe,
1536
 
              self).process_request(request, client_address)
 
1536
        proc = MultiprocessingMixIn.process_request(self, request,
 
1537
                                                    client_address)
1537
1538
        self.child_pipe.close()
1538
 
        self.add_pipe(parent_pipe)
 
1539
        self.add_pipe(parent_pipe, proc)
1539
1540
    
1540
 
    def add_pipe(self, parent_pipe):
 
1541
    def add_pipe(self, parent_pipe, proc):
1541
1542
        """Dummy function; override as necessary"""
1542
1543
        raise NotImplementedError
1543
1544
 
1631
1632
    def server_activate(self):
1632
1633
        if self.enabled:
1633
1634
            return socketserver.TCPServer.server_activate(self)
 
1635
    
1634
1636
    def enable(self):
1635
1637
        self.enabled = True
1636
 
    def add_pipe(self, parent_pipe):
 
1638
    
 
1639
    def add_pipe(self, parent_pipe, proc):
1637
1640
        # Call "handle_ipc" for both data and EOF events
1638
1641
        gobject.io_add_watch(parent_pipe.fileno(),
1639
1642
                             gobject.IO_IN | gobject.IO_HUP,
1640
1643
                             functools.partial(self.handle_ipc,
1641
1644
                                               parent_pipe =
1642
 
                                               parent_pipe))
1643
 
        
 
1645
                                               parent_pipe,
 
1646
                                               proc = proc))
 
1647
    
1644
1648
    def handle_ipc(self, source, condition, parent_pipe=None,
1645
 
                   client_object=None):
 
1649
                   proc = None, client_object=None):
1646
1650
        condition_names = {
1647
1651
            gobject.IO_IN: "IN",   # There is data to read.
1648
1652
            gobject.IO_OUT: "OUT", # Data can be written (without
1659
1663
                                       if cond & condition)
1660
1664
        # error or the other end of multiprocessing.Pipe has closed
1661
1665
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
 
1666
            proc.join()
1662
1667
            return False
1663
1668
        
1664
1669
        # Read a request from the child
1688
1693
                                 functools.partial(self.handle_ipc,
1689
1694
                                                   parent_pipe =
1690
1695
                                                   parent_pipe,
 
1696
                                                   proc = proc,
1691
1697
                                                   client_object =
1692
1698
                                                   client))
1693
1699
            parent_pipe.send(True)
2129
2135
        "Cleanup function; run on exit"
2130
2136
        service.cleanup()
2131
2137
        
 
2138
        multiprocessing.active_children()
2132
2139
        while tcp_server.clients:
2133
2140
            client = tcp_server.clients.pop()
2134
2141
            if use_dbus: