Browse Source

Refactor named pipe handling

master
Patrick Lühne 2 years ago
parent
commit
aa17fe4e00
Signed by: patrick GPG Key ID: 05F3611E97A70ABF
  1. 33
      github-fast-env.rb
  2. 29
      github-fast-envd.rb

33
github-fast-env.rb

@ -98,26 +98,31 @@ while true
if command == "ready"
break
end
elsif command == "named-pipes"
if arguments.empty?
log "error", "malformed response"
exit 1
end
if not ["stdin", "stdout", "stderr"].include?(command) or arguments.empty?
log "error", "malformed response"
exit 1
end
pipe_base_path = Base64.decode64(arguments[0])
pipe_path = arguments[0]
log "info", "connecting to named pipes at #{pipe_base_path}"
log "info", "connecting to #{pipe_path}"
pipes["stdin"] = File::open("#{pipe_base_path}.stdin", "w")
pipes["stdin"].sync = true
pipes["stdout"] = File::open("#{pipe_base_path}.stdout", "r")
pipes["stdout"].sync = true
pipes["stderr"] = File::open("#{pipe_base_path}.stderr", "r")
pipes["stderr"].sync = true
if command == "stdin"
pipes[command] = File::open(pipe_path, "w")
log "info", "connected via named pipes"
elsif command == "pseudoterminal"
log "error", "not yet implemented"
exit 1
else
pipes[command] = File::open(pipe_path, "r")
log "error", "malformed response"
exit 1
end
pipes[command].sync = true
log "info", "connected"
end
log "info", "ready"

29
github-fast-envd.rb

@ -39,16 +39,14 @@ $stderr.puts "serving control socket"
connection_id = 0
def open_pipe(connection_id, name)
pipe_path = "/tmp/github-fast-envd.#{connection_id}.#{name}"
if File.exist?(pipe_path) and File.pipe?(pipe_path)
File.unlink(pipe_path)
def open_pipe(path)
if File.exist?(path) and File.pipe?(path)
File.unlink(path)
end
File.mkfifo(pipe_path, mode = 0600)
File.mkfifo(path, mode = 0600)
pipe_path
path
end
def read_command(control_socket)
@ -86,18 +84,19 @@ def read_command(control_socket)
end
def set_up_named_pipes(control_socket, connection_id)
stdin = open_pipe(connection_id, "stdin")
control_socket.puts "stdin #{stdin}"
pipe_base_path = "/tmp/github-fast-envd.#{connection_id}"
pipe_base_path_encoded = Base64.encode64(pipe_base_path).delete("\n")
stdin = open_pipe("#{pipe_base_path}.stdin")
stdout = open_pipe("#{pipe_base_path}.stdout")
stderr = open_pipe("#{pipe_base_path}.stderr")
control_socket.puts "named-pipes #{pipe_base_path_encoded}"
stdin = File::open(stdin, "r")
stdin.sync = true
stdout = open_pipe(connection_id, "stdout")
control_socket.puts "stdout #{stdout}"
stdout = File::open(stdout, "w")
stdout.sync = true
stderr = open_pipe(connection_id, "stderr")
control_socket.puts "stderr #{stderr}"
stderr = File::open(stderr, "w")
stderr.sync = true

Loading…
Cancel
Save