diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-09-20 14:49:42 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-09-27 23:36:55 +0900 |
commit | 0b9b3bfedeb67a905306526af5b10361c191ec37 (patch) | |
tree | 549c6e12265bd34c1c4d52f3ce31d655146375a5 | |
parent | 44cf6006a59c5d3e9e14c8bcd1ff19dbcb5986c3 (diff) | |
download | nyaci-0b9b3bfedeb67a905306526af5b10361c191ec37.tar.gz |
nyabuild: support command execution timeout
-rw-r--r-- | config.rb.example | 2 | ||||
-rw-r--r-- | nyabuild.rb | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/config.rb.example b/config.rb.example index d218121..02bb38e 100644 --- a/config.rb.example +++ b/config.rb.example @@ -65,7 +65,7 @@ NyaConfig.configure( t.run "gem install --no-user-install -N rake-compiler test-unit" t.run "rake compile -- --with-openssl-dir=#{t.s openssl.prefix} --enable-debug" - t.run "rake test TESTOPTS=-v OSSL_MDEBUG=1" + t.run "rake test TESTOPTS=-v OSSL_MDEBUG=1", timeout: 300 } }, } diff --git a/nyabuild.rb b/nyabuild.rb index 37df4eb..cdadb23 100644 --- a/nyabuild.rb +++ b/nyabuild.rb @@ -58,14 +58,19 @@ class NyaBuildTarget @logger = logger end - private def run0(cmd, **opts) + private def run0(cmd, timeout: nil) @logger.log(cmd) - status = Open3.popen2e(cmd, **opts) { |stdin, mergedout, wait_thread| - stdin.close - FileUtils.copy_stream(mergedout, @logger.io) - wait_thread.value - } - unless status.success? + pid = spawn({}, *cmd, pgroup: true, [:out, :err] => @logger.io) + th = Thread.new { _, status = Process.waitpid2(-pid); status } + unless th.join(timeout) + th.kill; th.join + @logger.warn("Execution timed out (%p sec)", timeout) + Process.kill(:KILL, -pid) + _, status = Process.waitpid2(-pid) + raise status.inspect + end + + unless (status = th.value).success? @logger.warn(status.inspect) raise status.inspect end |