Exemple #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)
Exemple #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)
Exemple #3
0
 def test_change_user_valid(self, setgid_mock, getpwnam_mock):
     with patch('sys.exit') as exit_mock:
         setuid()
         self.assertFalse(exit_mock.called)
Exemple #4
0
 def test_change_user_no_permission(self, setgid_mock, getpwnam_mock,
                                    exit_mock):
     setuid()
     self.assertTrue(exit_mock.called)
Exemple #5
0
 def test_change_user_valid(self, setgid_mock, getpwnam_mock):
     with patch('sys.exit') as exit_mock:
         setuid()
         self.assertFalse(exit_mock.called)
Exemple #6
0
 def test_change_user_no_permission(self, setgid_mock, getpwnam_mock,
                                    exit_mock):
     setuid()
     self.assertTrue(exit_mock.called)