From 40a4c8cb20dc72349d8db4ee13abd8a36222321e Mon Sep 17 00:00:00 2001 From: Travis Thieman Date: Fri, 11 Sep 2015 14:08:59 -0400 Subject: [PATCH] Add initial socket ack to prevent false "running previous commands" message --- dusty/cli/__init__.py | 2 +- dusty/constants.py | 1 + dusty/daemon.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dusty/cli/__init__.py b/dusty/cli/__init__.py index 132c9545..063e1417 100644 --- a/dusty/cli/__init__.py +++ b/dusty/cli/__init__.py @@ -80,7 +80,7 @@ def _run_command(sock, command): data = sock.recv(65535) timer.cancel() if data: - stripped = data.decode('utf-8').replace(constants.SOCKET_TERMINATOR, '').replace(constants.SOCKET_ERROR_TERMINATOR, '') + stripped = data.decode('utf-8').replace(constants.SOCKET_ACK, '').replace(constants.SOCKET_TERMINATOR, '').replace(constants.SOCKET_ERROR_TERMINATOR, '') sys.stdout.write(stripped) if data.endswith(constants.SOCKET_TERMINATOR): break diff --git a/dusty/constants.py b/dusty/constants.py index 603d7473..e751822f 100644 --- a/dusty/constants.py +++ b/dusty/constants.py @@ -12,6 +12,7 @@ DUSTY_CONFIG_REGEX = re.compile('\\{}.*\\{}'.format(DUSTY_CONFIG_BEGIN, DUSTY_CONFIG_END), flags=re.DOTALL | re.MULTILINE) DUSTY_CONFIG_GROUP_REGEX = re.compile('.*\\{}(?P.*)\\{}.*'.format(DUSTY_CONFIG_BEGIN, DUSTY_CONFIG_END), flags=re.DOTALL | re.MULTILINE) +SOCKET_ACK = '\1\1' SOCKET_TERMINATOR = '\0\0' SOCKET_ERROR_TERMINATOR = '\0\1' diff --git a/dusty/daemon.py b/dusty/daemon.py index a9738e5b..d47d6286 100644 --- a/dusty/daemon.py +++ b/dusty/daemon.py @@ -16,7 +16,7 @@ from .preflight import preflight_check, refresh_preflight_warnings from .log import configure_logging, make_socket_logger, close_socket_logger -from .constants import SOCKET_PATH, SOCKET_TERMINATOR, SOCKET_ERROR_TERMINATOR +from .constants import SOCKET_PATH, SOCKET_ACK, SOCKET_TERMINATOR, SOCKET_ERROR_TERMINATOR from .payload import Payload, get_payload_function, init_yaml_constructor from .memoize import reset_memoize_cache from .warnings import daemon_warnings @@ -73,6 +73,7 @@ def _listen_on_socket(socket_path, suppress_warnings): while True: try: connection, client_address = sock.accept() + connection.sendall(SOCKET_ACK) make_socket_logger(connection) try: data = connection.recv(1024)