Verified Commit 750fde64 authored by Karel Koci's avatar Karel Koci 🤘

Use subprocess in backend.script_run instead of events

parent 0ae9c06a
......@@ -35,8 +35,9 @@ local setenv = setenv
local getcwd = getcwd
local mkdtemp = mkdtemp
local chdir = chdir
local run_command = run_command
local run_util = run_util
local subprocess = subprocess
local LST_PKG_SCRIPT = LST_PKG_SCRIPT
local events_wait = events_wait
local stat = stat
local lstat = lstat
......@@ -1006,21 +1007,19 @@ function script_run(pkg_name, script_name, ...)
local fname_full = syscnf.info_dir:gsub('^../', getcwd() .. "/../"):gsub('^./', getcwd() .. "/") .. "/" .. fname
local ftype, perm = stat(fname_full)
if ftype == 'r' and perm:match("^r.[xs]") then
DBG("Running " .. script_name .. " of " .. pkg_name)
local s_ecode, s_stderr
events_wait(run_command(function (ecode, killed, _, stderr)
DBG("Terminated: " .. killed)
s_ecode = ecode
s_stderr = stderr
end, function ()
-- If root is / then variable is empty otherwise absolute path is used
local dir = syscnf.root_dir:gsub('^/+$', '')
setenv("PKG_ROOT", dir)
setenv("IPKG_INSTROOT", dir)
chdir(syscnf.root_dir)
end, nil, cmd_timeout, cmd_kill_timeout, fname_full, ...))
DBG(s_stderr)
return s_ecode == 0, s_stderr
local ecode, output = subprocess(
LST_PKG_SCRIPT,
"Running " .. script_name .. " of " .. pkg_name,
cmd_timeout/1000,
function()
-- If root is / then variable is empty otherwise absolute path is used
local dir = syscnf.root_dir:gsub('^/+$', '')
setenv("PKG_ROOT", dir)
setenv("IPKG_INSTROOT", dir)
chdir(syscnf.root_dir)
end,
fname_full, ...)
return ecode == 0, output
elseif ftype == 'r' then
WARN(fname .. " has wrong permissions " .. perm .. "(not running)")
elseif ftype then
......
......@@ -11,6 +11,7 @@ globals = {
"_M",
-- From interpreter.c
"log", "state_log_enabled", "update_state", "cleanup_register_handle", "cleanup_unregister_handle", "run_command", "run_util", "download", "events_wait", "mkdtemp", "chdir", "getcwd", "mkdir", "move", "copy", "ls", "stat", "lstat", "sync", "setenv", "md5", "sha256", "md5_file", "sha256_file", "reexec", "uri_internal_get", "system_reboot", "get_updater_version",
"subprocess", "LST_PKG_SCRIPT", "PST_HOOK",
"LS_INIT", "LS_CONF", "LS_PLAN", "LS_DOWN", "LS_PREUPD", "LS_UNPACK", "LS_CHECK", "LS_INST", "LS_POST", "LS_REM", "LS_CLEANUP", "LS_POSTUPD", "LS_EXIT", "LS_FAIL",
-- From logging
"ERROR", "WARN", "INFO", "DBG", "TRACE", "DIE", "log_event", "c_pcall_error_handler",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment