Commit f2363823 authored by Julien Muchembled's avatar Julien Muchembled

New --console option

parent f3d45f8e
...@@ -56,6 +56,11 @@ def getConfig(): ...@@ -56,6 +56,11 @@ def getConfig():
help="Exit after configuration parsing. Status code is the" help="Exit after configuration parsing. Status code is the"
" result of the given Python expression. For example:\n" " result of the given Python expression. For example:\n"
" main_interface != 'eth0'") " main_interface != 'eth0'")
_('--console', metavar='SOCK',
help="Socket path to Python console that can be used to inspect or"
" patch this process. Use:\n"
" socat - UNIX:<SOCK>\n"
"to access it.")
_ = parser.add_argument_group('routing').add_argument _ = parser.add_argument_group('routing').add_argument
_('-B', dest='babel_args', metavar='ARG', action='append', default=[], _('-B', dest='babel_args', metavar='ARG', action='append', default=[],
...@@ -389,10 +394,23 @@ def main(): ...@@ -389,10 +394,23 @@ def main():
tunnel_manager.killAll) tunnel_manager.killAll)
except AttributeError: except AttributeError:
pass pass
if config.console:
from re6st.debug import Console
def console(socket, frame=sys._getframe()):
try:
import pdb; pdb.Pdb(stdin=socket,
stdout=socket).set_trace()
frame.f_locals # main() locals
finally:
socket.close()
console = Console(config.console, console)
cleanup.append(console.close)
# main loop # main loop
exit.release() exit.release()
select_list = [forwarder.select] if forwarder else [] select_list = [forwarder.select] if forwarder else []
if config.console:
select_list.append(console.select)
select_list += tunnel_manager.select, utils.select select_list += tunnel_manager.select, utils.select
while True: while True:
args = R.copy(), {}, [] args = R.copy(), {}, []
......
import errno, os, socket, stat, threading
class Socket(object):
def __init__(self, socket):
# In case that the default timeout is not None.
socket.settimeout(None)
self._socket = socket
self._buf = ''
def close(self):
self._socket.close()
def write(self, data):
self._socket.send(data)
def readline(self):
recv = self._socket.recv
data = self._buf
while True:
i = 1 + data.find('\n')
if i:
self._buf = data[i:]
return data[:i]
d = recv(4096)
data += d
if not d:
self._buf = ''
return data
def flush(self):
pass
def closed(self):
self._socket.setblocking(0)
try:
self._socket.recv(0)
return True
except socket.error, (err, _):
if err != errno.EAGAIN:
raise
self._socket.setblocking(1)
return False
class Console(object):
def __init__(self, path, pdb):
self.path = path
s = socket.socket(socket.AF_UNIX)
try:
self.close()
except OSError, e:
if e.errno != errno.ENOENT:
raise
s.bind(path)
s.listen(5)
def accept():
t = threading.Thread(target=pdb, args=(Socket(s.accept()[0]),))
t.daemon = True
t.start()
def select(r, w, t):
r[s] = accept
self.select = select
def close(self):
if stat.S_ISSOCK(os.lstat(self.path).st_mode):
os.remove(self.path)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment