webmcp

changeset 487:91d0c8304d74

Do not execute abortable command if termination has already been requested
author jbe
date Mon Jun 12 03:18:54 2017 +0200 (12 months ago)
parents 7d53e12f0804
children 5b1c4f76e44f
files framework/env/execute/command.lua
line diff
     1.1 --- a/framework/env/execute/command.lua	Sun Jun 11 23:27:17 2017 +0200
     1.2 +++ b/framework/env/execute/command.lua	Mon Jun 12 03:18:54 2017 +0200
     1.3 @@ -23,16 +23,7 @@
     1.4    local moonbridge_io = require("moonbridge_io")
     1.5    local poll = args.poll or moonbridge_io.poll
     1.6  
     1.7 -  local start = moonbridge_io.timeref()
     1.8 -  local process, errmsg = moonbridge_io.exec(table.unpack(args.command))
     1.9 -  if not process then return nil, errmsg end
    1.10 -
    1.11    local stdout_chunks, stderr_chunks = {}, {}
    1.12 -  local read_fds = {[process.stdout] = true, [process.stderr] = true}
    1.13 -  local write_fds = {[process.stdin] = true}
    1.14 -  if args.db then
    1.15 -    read_fds[args.db.fd] = true
    1.16 -  end
    1.17  
    1.18    local function return_error(errmsg)
    1.19      if args.stdout_result_handler then
    1.20 @@ -41,6 +32,24 @@
    1.21      return nil, errmsg
    1.22    end
    1.23  
    1.24 +  if args.abortable then
    1.25 +    local pollready, pollmsg, pollterm = poll(nil, nil, 0, true)
    1.26 +    if pollterm then
    1.27 +      if args.abort_handler then args.abort_handler() end
    1.28 +      return_error(pollmsg)
    1.29 +    end
    1.30 +  end
    1.31 +
    1.32 +  local start = moonbridge_io.timeref()
    1.33 +  local process, errmsg = moonbridge_io.exec(table.unpack(args.command))
    1.34 +  if not process then return nil, errmsg end
    1.35 +
    1.36 +  local read_fds = {[process.stdout] = true, [process.stderr] = true}
    1.37 +  local write_fds = {[process.stdin] = true}
    1.38 +  if args.db then
    1.39 +    read_fds[args.db.fd] = true
    1.40 +  end
    1.41 +
    1.42    local function write(...)
    1.43      if write_fds[process.stdin] then
    1.44        local buffered = process.stdin:flush_nb(...)
    1.45 @@ -57,9 +66,9 @@
    1.46      write_fds[process.stdin]
    1.47    do
    1.48      local timeout = args.timeout and args.timeout-moonbridge_io.timeref(start)
    1.49 -    local pollstatus, pollmsg, pollterm =
    1.50 +    local pollready, pollmsg, pollterm =
    1.51        poll(read_fds, write_fds, timeout, args.abortable)
    1.52 -    if not pollstatus then
    1.53 +    if not pollready then
    1.54        process:kill():wait()
    1.55        if pollterm then
    1.56          if args.abort_handler then args.abort_handler() end

Impressum / About Us