Exemplo n.º 1
0
def run():
    """
    The run method is what actually spawns and manages blackhole.
    """
    signal.signal(signal.SIGTERM, terminate)
    action = set_action()
    set_options()
    # Grab the sockets early for multiprocessing
    if action in ('start',):
        socks = sockets()
        setgid()
        setuid()
    d = daemon(action)
    # Change group and user
    io_loop = fork()
    # Iterate over the dictionary of socket connections
    # and add them to the IOLoop
    for _, sock in socks.iteritems():
        callback = functools.partial(connection_ready, sock)
        io_loop.add_handler(sock.fileno(), callback, io_loop.READ)
    try:
        io_loop.start()
    except (KeyboardInterrupt, SystemExit):
        io_loop.stop()
        d.stop()
        sys.exit(0)
Exemplo n.º 2
0
def run():
    """
    The run method is what actually spawns and manages blackhole.
    """
    signal.signal(signal.SIGTERM, terminate)
    action = set_action()
    set_options()
    # Grab the sockets early for multiprocessing
    if action in ('start', ):
        socks = sockets()
        setgid()
        setuid()
    d = daemon(action)
    # Change group and user
    io_loop = fork()
    # Iterate over the dictionary of socket connections
    # and add them to the IOLoop
    for _, sock in socks.iteritems():
        callback = functools.partial(connection_ready, sock)
        io_loop.add_handler(sock.fileno(), callback, io_loop.READ)
    try:
        io_loop.start()
    except (KeyboardInterrupt, SystemExit):
        io_loop.stop()
        d.stop()
        sys.exit(0)
Exemplo n.º 3
0
 def test_change_group_valid(self, setgid_mock, getgrname_mock):
     with patch('sys.exit') as exit_mock:
         setgid()
         self.assertFalse(exit_mock.called)
Exemplo n.º 4
0
 def test_change_group_no_permission(self, setgid_mock, getgrname_mock,
                                     exit_mock):
     setgid()
     self.assertTrue(exit_mock.called)
Exemplo n.º 5
0
 def test_change_group_valid(self, setgid_mock, getgrname_mock):
     with patch('sys.exit') as exit_mock:
         setgid()
         self.assertFalse(exit_mock.called)
Exemplo n.º 6
0
 def test_change_group_no_permission(self, setgid_mock, getgrname_mock,
                                     exit_mock):
     setgid()
     self.assertTrue(exit_mock.called)