|
|
@ -38,8 +38,6 @@ import sys
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
|
|
#import q
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from io import BytesIO
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
from ansible import constants as C
|
|
|
|
from ansible import constants as C
|
|
|
@ -112,8 +110,6 @@ class Server():
|
|
|
|
self.conn = connection_loader.get(play_context.connection, play_context, sys.stdin)
|
|
|
|
self.conn = connection_loader.get(play_context.connection, play_context, sys.stdin)
|
|
|
|
self.conn._connect()
|
|
|
|
self.conn._connect()
|
|
|
|
|
|
|
|
|
|
|
|
#q.q("done setting up connection and connected")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
self.socket.bind(path)
|
|
|
|
self.socket.bind(path)
|
|
|
|
self.socket.listen(1)
|
|
|
|
self.socket.listen(1)
|
|
|
@ -218,7 +214,6 @@ def main():
|
|
|
|
print("FAIL: %s" % e)
|
|
|
|
print("FAIL: %s" % e)
|
|
|
|
print(traceback.format_exc())
|
|
|
|
print(traceback.format_exc())
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
#q.q("done reading in and parsing PlayContext")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# here we create a hash to use later when creating the socket file,
|
|
|
|
# here we create a hash to use later when creating the socket file,
|
|
|
|
# so we can hide the info about the target host/user/etc.
|
|
|
|
# so we can hide the info about the target host/user/etc.
|
|
|
@ -239,15 +234,12 @@ def main():
|
|
|
|
lock_fd = os.open(lk_path, os.O_RDWR|os.O_CREAT, 0o600)
|
|
|
|
lock_fd = os.open(lk_path, os.O_RDWR|os.O_CREAT, 0o600)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_EX)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_EX)
|
|
|
|
if not os.path.exists(sf_path):
|
|
|
|
if not os.path.exists(sf_path):
|
|
|
|
#q.q("creating daemonized connection fork")
|
|
|
|
|
|
|
|
pid = do_fork()
|
|
|
|
pid = do_fork()
|
|
|
|
if pid == 0:
|
|
|
|
if pid == 0:
|
|
|
|
server = Server(sf_path, pc)
|
|
|
|
server = Server(sf_path, pc)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
|
|
|
os.close(lock_fd)
|
|
|
|
os.close(lock_fd)
|
|
|
|
#q.q("fork done, running server")
|
|
|
|
|
|
|
|
server.run()
|
|
|
|
server.run()
|
|
|
|
#q.q("server run complete, exiting")
|
|
|
|
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
|
|
|
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
|
|
|
os.close(lock_fd)
|
|
|
|
os.close(lock_fd)
|
|
|
@ -257,13 +249,10 @@ def main():
|
|
|
|
# the connection will timeout here. Need to make this more resilient.
|
|
|
|
# the connection will timeout here. Need to make this more resilient.
|
|
|
|
rc = 0
|
|
|
|
rc = 0
|
|
|
|
while rc == 0:
|
|
|
|
while rc == 0:
|
|
|
|
#q.q("waiting for input")
|
|
|
|
|
|
|
|
data = sys.stdin.readline()
|
|
|
|
data = sys.stdin.readline()
|
|
|
|
if data == '':
|
|
|
|
if data == '':
|
|
|
|
#q.q("data was empty, aborting")
|
|
|
|
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if data.strip() == '':
|
|
|
|
if data.strip() == '':
|
|
|
|
#q.q("data was empty line, skipping")
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
sf = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
sf = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
attempts = 1
|
|
|
|
attempts = 1
|
|
|
@ -280,15 +269,10 @@ def main():
|
|
|
|
sys.stderr.write("failed to connect to the host, connection timeout\n")
|
|
|
|
sys.stderr.write("failed to connect to the host, connection timeout\n")
|
|
|
|
sys.exit(255)
|
|
|
|
sys.exit(255)
|
|
|
|
|
|
|
|
|
|
|
|
#q.q("sending data to pipe")
|
|
|
|
|
|
|
|
send_data(sf, to_bytes(data.strip()))
|
|
|
|
send_data(sf, to_bytes(data.strip()))
|
|
|
|
#q.q("getting data back")
|
|
|
|
|
|
|
|
rc = int(recv_data(sf), 10)
|
|
|
|
rc = int(recv_data(sf), 10)
|
|
|
|
#q.q(rc)
|
|
|
|
|
|
|
|
stdout = recv_data(sf)
|
|
|
|
stdout = recv_data(sf)
|
|
|
|
#q.q(stdout)
|
|
|
|
|
|
|
|
stderr = recv_data(sf)
|
|
|
|
stderr = recv_data(sf)
|
|
|
|
#q.q(stderr)
|
|
|
|
|
|
|
|
sys.stdout.write(to_native(stdout))
|
|
|
|
sys.stdout.write(to_native(stdout))
|
|
|
|
sys.stderr.write(to_native(stderr))
|
|
|
|
sys.stderr.write(to_native(stderr))
|
|
|
|
#sys.stdout.flush()
|
|
|
|
#sys.stdout.flush()
|
|
|
|