diff options
author | Richard Ipsum <richardipsum@fastmail.co.uk> | 2018-06-22 21:36:16 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2018-06-26 16:55:46 +0100 |
commit | 02310d93633328328e08323066fd0675fd59e25f (patch) | |
tree | a56e53ae6125ae41b074729e30ea628d3dda4610 | |
parent | 08368ce62527d2adfb7d77fb014bff7c3f966759 (diff) | |
download | luxio-02310d93633328328e08323066fd0675fd59e25f.tar.gz |
subprocess: convert to 3space indents
-rw-r--r-- | luxio/subprocess.lua | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/luxio/subprocess.lua b/luxio/subprocess.lua index 617d20b..cf89561 100644 --- a/luxio/subprocess.lua +++ b/luxio/subprocess.lua @@ -158,12 +158,12 @@ local function _spawn(t) if proc.args[0] == nil then if proc.args.exe then - proc.args[0] = proc.args.exe + proc.args[0] = proc.args.exe else - proc.args[0] = proc.args[1] - if proc.args[0]:match("^/") then - proc.args.exe = proc.args[0] - end + proc.args[0] = proc.args[1] + if proc.args[0]:match("^/") then + proc.args.exe = proc.args[0] + end end end @@ -178,17 +178,17 @@ local function _spawn(t) -- Simple verification of the FDs. local function check(v) if proc.args[v] then - -- Something to do for handle - if proc.args[v] == _PIPE then - -- For now, nothing, later we'll handle this - elseif type(proc.args[v]) == "table" then - -- Simple handle, extract the FD - proc.args[v] = proc.args[v].fd - elseif type(proc.args[v]) == "number" then - -- FD, nothing to do for now - else - assert(false, v .. " isn't a PIPE, Simple Handle or FD") - end + -- Something to do for handle + if proc.args[v] == _PIPE then + -- For now, nothing, later we'll handle this + elseif type(proc.args[v]) == "table" then + -- Simple handle, extract the FD + proc.args[v] = proc.args[v].fd + elseif type(proc.args[v]) == "number" then + -- FD, nothing to do for now + else + assert(false, v .. " isn't a PIPE, Simple Handle or FD") + end end end @@ -204,25 +204,25 @@ local function _spawn(t) local function _assert(m,v) if not m then - for fd in pairs(parent_close) do - close(fd) - end - for fd in pairs(child_close) do - close(fd) - end - error(v) + for fd in pairs(parent_close) do + close(fd) + end + for fd in pairs(child_close) do + close(fd) + end + error(v) end end local function do_pipe(v) if proc.args[v] == _PIPE then - local fds = {} - local res, errno = pipe(fds) - _assert(res == 0, "Unable to pipe()") - proc.args[v] = fds[2] - proc[v] = fds[1] - parent_close[proc.args[v]] = true - child_close[proc[v]] = true + local fds = {} + local res, errno = pipe(fds) + _assert(res == 0, "Unable to pipe()") + proc.args[v] = fds[2] + proc[v] = fds[1] + parent_close[proc.args[v]] = true + child_close[proc[v]] = true end end do_pipe "stdin" @@ -246,16 +246,16 @@ local function _spawn(t) if proc.args.prefork then local ok, msg = xpcall(proc.args.prefork, function(...) - for fd in pairs(parent_close) do - close(fd) - end - for fd in pairs(child_close) do - close(fd) - end - return _TRACEBACK(...) + for fd in pairs(parent_close) do + close(fd) + end + for fd in pairs(child_close) do + close(fd) + end + return _TRACEBACK(...) end) if not ok then - error(msg) + error(msg) end end @@ -265,37 +265,37 @@ local function _spawn(t) if pid == 0 then local function check(m) - if m == -1 then - _exit(1) - end - return m + if m == -1 then + _exit(1) + end + return m end -- Set up the FDs. if proc.args.stdin == -1 then - close(0) + close(0) elseif proc.args.stdin ~= 0 then - check(dup2(proc.args.stdin, 0)) + check(dup2(proc.args.stdin, 0)) end if proc.args.stdout == -1 then - close(1) + close(1) elseif proc.args.stdout ~= 1 then - if proc.args.stderr == 1 then - proc.args.old_stdout = check(dup(1)) - end - check(dup2(proc.args.stdout, 1)) + if proc.args.stderr == 1 then + proc.args.old_stdout = check(dup(1)) + end + check(dup2(proc.args.stdout, 1)) end if proc.args.stderr == -1 then - close(2) + close(2) elseif proc.args.stderr ~= 2 then - if proc.args.stderr == 1 and proc.args.old_stdout then - check(dup2(proc.args.old_stdout, 2)) - else - check(dup2(proc.args.stderr, 2)) - end + if proc.args.stderr == 1 and proc.args.old_stdout then + check(dup2(proc.args.old_stdout, 2)) + else + check(dup2(proc.args.stderr, 2)) + end end if proc.args.old_stdout then - close(proc.args.old_stdout) + close(proc.args.old_stdout) end -- FDs 0, 1, 2 initialised, ensure they won't close on exec fcntl(0, F_SETFD, bclear(fcntl(0, F_GETFD), 1)) @@ -304,41 +304,41 @@ local function _spawn(t) -- Close any FDs left which we were asked to for _, fd in ipairs(proc.args.close_in_child or {}) do - close(fd) + close(fd) end -- Finally, close the parent halves of any pipes for fd in pairs(child_close) do - close(fd) + close(fd) end -- perform environment twiddling if proc.args.env then - for k, v in pairs(proc.args.env) do - if not v then - unsetenv(tostring(k)) - else - check(setenv(tostring(k), tostring(v))) - end - end + for k, v in pairs(proc.args.env) do + if not v then + unsetenv(tostring(k)) + else + check(setenv(tostring(k), tostring(v))) + end + end end -- Change directory if needed if proc.args.cwd then - local cwd = tostring(proc.args.cwd) - local ret, err = chdir(cwd) - if ret ~= 0 then - stderr_fh:write("chdir(" .. cwd .. "): " .. err .. "\n") - _exit(1) - end + local cwd = tostring(proc.args.cwd) + local ret, err = chdir(cwd) + if ret ~= 0 then + stderr_fh:write("chdir(" .. cwd .. "): " .. err .. "\n") + _exit(1) + end end if proc.args.preexec then - local ok, msg = xpcall(proc.args.preexec, _TRACEBACK) - if not ok then - stderr_fh:write(msg .. "\n") - _exit(1) - end + local ok, msg = xpcall(proc.args.preexec, _TRACEBACK) + if not ok then + stderr_fh:write(msg .. "\n") + _exit(1) + end end -- Run the child process @@ -377,7 +377,7 @@ local function _spawn_simple(t) local function doit(v) if proc[v] then - proc[v] = wrap_fd(proc[v]) + proc[v] = wrap_fd(proc[v]) end end doit "stdin" |