lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Enhanced test program to exercise more cases including death by signal for
both the child process and the shell/exec'd-command.

==== 5.2.0-alpha first patch output: ====

Lua version: Lua 5.2

sh: foobarbaz: not found
cmd: foobarbaz
  rc1: 127
  rc2: e

cmd: cat>/dev/null
  rc1: 0
  rc2: e

cmd: exit 3
  rc1: 3
  rc2: e

cmd: kill -HUP $$
  rc1: 1
  rc2: s

Hangup
cmd: sh -c 'kill -HUP $$'
  rc1: 129
  rc2: e


==== 5.2.0-alpha second patch output: ====

Lua version: Lua 5.2

sh: foobarbaz: not found
cmd: foobarbaz
  rc1: 127
  rc2: nil

cmd: cat>/dev/null
  rc1: 0
  rc2: nil

cmd: exit 3
  rc1: 3
  rc2: nil

cmd: kill -HUP $$
  rc1: nil
  rc2: 1

Hangup
cmd: sh -c 'kill -HUP $$'
  rc1: 129
  rc2: nil


==== 5.2.0-alpha unpatched output: ====

Lua version: Lua 5.2

sh: foobarbaz: not found
cmd: foobarbaz
  rc1: 32512
  rc2: nil

cmd: cat>/dev/null
  rc1: 0
  rc2: nil

cmd: exit 3
  rc1: 768
  rc2: nil

cmd: kill -HUP $$
  rc1: 1
  rc2: nil

Hangup
cmd: sh -c 'kill -HUP $$'
  rc1: 33024
  rc2: nil


==== 5.1 output: ====

Lua version: Lua 5.1

sh: foobarbaz: not found
cmd: foobarbaz
  rc1: true
  rc2: nil

cmd: cat>/dev/null
  rc1: true
  rc2: nil

cmd: exit 3
  rc1: true
  rc2: nil

cmd: kill -HUP $$
  rc1: true
  rc2: nil

Hangup
cmd: sh -c 'kill -HUP $$'
  rc1: true
  rc2: nil
-- Test the behavior of file:close() on pipes.
-- This may only work on POSIX systems.


local cmds =
        {
        "foobarbaz"             , -- No such command
        "cat>/dev/null"         , -- Normal exit
        "exit 3"                , -- Non-zero exit
        "kill -HUP $$"          , -- shell or exec'd command dies with signal
        "sh -c 'kill -HUP $$'"  , -- subprocess dies with signal
        };


function debug_out( val )
    if type(val) == "boolean" then -- Lua 5.1 returned boolean
        val = val and "true" or "false";
    else
        val = val or "nil";
        end
    return val;
    end


io.write( "\nLua version: ", _VERSION, "\n\n" );


for _, cmd in ipairs(cmds)
    do

    local file = assert( io.popen( cmd, "w" ) );

    file:write( "Hello.\n" );

    local rc1, rc2 = file:close();

    io.write( "cmd: ", cmd,
                "\n  rc1: ", debug_out(rc1),
                "\n  rc2: ", debug_out(rc2), "\n\n" );

    end