Browse Source

Handle interrupts

master
Patrick Lühne 2 years ago
parent
commit
41ce4614d4
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
  1. 67
      github-fast-env.rb
  2. 8
      github-fast-envd.rb

67
github-fast-env.rb

@ -31,7 +31,6 @@ if ARGV.length > 1
end
# TODO: support arguments
# TODO: forward signals
script_path = File.realpath(ARGV[0])
control_socket_path = "/tmp/github-fast-envd.sock"
@ -48,6 +47,62 @@ def log(level, message)
end
end
$remote_process_id = nil
Signal.trap("HUP") do
if $remote_process_id
Process.kill("HUP", $remote_process_id)
else
Signal.trap("HUP", "DEFAULT")
Process.kill("HUP", 0)
end
end
Signal.trap("INT") do
if $remote_process_id
Process.kill("INT", $remote_process_id)
else
Signal.trap("INT", "DEFAULT")
Process.kill("INT", 0)
end
end
Signal.trap("QUIT") do
if $remote_process_id
Process.kill("QUIT", $remote_process_id)
else
Signal.trap("QUIT", "DEFAULT")
Process.kill("QUIT", 0)
end
end
Signal.trap("TERM") do
if $remote_process_id
Process.kill("TERM", $remote_process_id)
else
Signal.trap("TERM", "DEFAULT")
Process.kill("TERM", 0)
end
end
Signal.trap("TSTP") do
if $remote_process_id
Process.kill("TSTP", $remote_process_id)
end
Signal.trap("TSTP", "DEFAULT")
Process.kill("TSTP", 0)
end
Signal.trap("CONT") do
if $remote_process_id
Process.kill("CONT", $remote_process_id)
end
Signal.trap("CONT", "DEFAULT")
Process.kill("CONT", 0)
end
def read_command
ready_ios = IO.select([$control_socket], [], [], 10)
@ -114,7 +169,15 @@ pipes = {"stdin" => nil, "stdout" => nil, "stderr" => nil}
while true
command, arguments = read_command
if command == "ready"
if command == "pid"
if arguments.empty?
log "error", "malformed response"
exit 1
end
$remote_process_id = arguments[0].to_i
log "trace", "remote process ID: #{$remote_process_id}"
elsif command == "ready"
break
elsif command == "named-pipes"
if arguments.empty?

8
github-fast-envd.rb

@ -177,6 +177,9 @@ while true
connection_id += 1
child_process = fork {
process_id = Process.pid
control_socket.puts "pid #{process_id}"
exit_code = "unknown"
if mode == "named-pipes"
@ -185,7 +188,7 @@ while true
set_up_pseudoterminal(control_socket, pseudoterminal_path)
end
$original_stderr.puts " executing script " + script_path
$original_stderr.puts " executing script #{script_path} (#{process_id})"
begin
begin
@ -224,13 +227,12 @@ while true
end
begin
# TODO: which exit code to return when interrupted?
control_socket.puts "done #{exit_code}"
rescue
end
control_socket.close
$original_stderr.puts " finished handling request"
$original_stderr.puts " finished handling request (#{process_id})"
Kernel.exit!
}

Loading…
Cancel
Save