Verified Commit 91248c97 authored by Karel Koci's avatar Karel Koci 🤘 Committed by Karel Koci
Browse files

Remove log files

The Changelog replaces previous logs that are right now pretty much no
longer relevant and in case of state log not even used.
parent d5d847cf
Pipeline #83507 passed with stages
in 4 minutes and 29 seconds
......@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `FilesSignature` field in packages. On mismatch it trigger
reinstall.
### Removed
- `--state-log` argument
- `--task-log` argument
## [69.1.2] - 2021-05-28
### Fixed
- Immediate reboot not being performed when combined with replan that actually
......
......@@ -171,12 +171,6 @@ static int lua_log(lua_State *L) {
return 0;
}
static int lua_update_state(lua_State *L) {
enum log_state state = luaL_checkint(L, 1);
update_state(state);
return 0;
}
/*
* Put a value from the stack (at index) into our own table in the registry.
* Return the index under which it is stored in there. The returned value allocated
......@@ -845,13 +839,6 @@ static int lua_get_updater_version(lua_State *L) {
return 1;
}
extern bool state_log_enabled; // defined in util.c
static int lua_state_log_enabled(lua_State *L) {
lua_pushboolean(L, state_log_enabled);
return 1;
}
struct injected_func {
int (*func)(lua_State *);
const char *name;
......@@ -859,8 +846,6 @@ struct injected_func {
static const struct injected_func injected_funcs[] = {
{ lua_log, "log" },
{ lua_state_log_enabled, "state_log_enabled" },
{ lua_update_state, "update_state" },
{ lua_cleanup_register_handle, "cleanup_register_handle" },
{ lua_cleanup_unregister_handle, "cleanup_unregister_handle" },
{ lua_run_command, "run_command" },
......@@ -897,20 +882,6 @@ struct {
int cnst;
const char *name;
} injected_const[] = {
{ LS_INIT, "LS_INIT"},
{ LS_CONF, "LS_CONF"},
{ LS_PLAN, "LS_PLAN"},
{ LS_DOWN, "LS_DOWN"},
{ LS_PREUPD, "LS_PREUPD"},
{ LS_UNPACK, "LS_UNPACK"},
{ LS_CHECK, "LS_CHECK"},
{ LS_INST, "LS_INST"},
{ LS_POST, "LS_POST"},
{ LS_REM, "LS_REM"},
{ LS_CLEANUP, "LS_CLEANUP"},
{ LS_POSTUPD, "LS_POSTUPD"},
{ LS_EXIT, "LS_EXIT"},
{ LS_FAIL, "LS_FAIL"},
{ LST_PKG_SCRIPT, "LST_PKG_SCRIPT"},
{ LST_HOOK, "LST_HOOK"},
};
......
......@@ -23,23 +23,6 @@
#include <stdarg.h>
#include <string.h>
const char* log_state_str[] = {
[LS_INIT] = "initialize",
[LS_CONF] = "configuration",
[LS_PLAN] = "planning",
[LS_DOWN] = "downloading",
[LS_PREUPD] = "preupdate-hooks",
[LS_UNPACK] = "unpacking",
[LS_CHECK] = "checking",
[LS_INST] = "install",
[LS_POST] = "post-install",
[LS_REM] = "removals",
[LS_CLEANUP] = "cleanup",
[LS_POSTUPD] = "postupdate-hooks",
[LS_EXIT] = "exit",
[LS_FAIL] = "failure"
};
struct level_info {
const char *prefix;
const char *name;
......@@ -62,32 +45,6 @@ static enum log_level stderr_level = LL_WARN;
static bool syslog_opened = false;
bool state_log_enabled = false;
void set_state_log(bool state_log) {
state_log_enabled = state_log;
}
void update_state(enum log_state state) {
if (state_log_enabled) {
FILE *f = fopen("/tmp/update-state/state", "w");
if (f) {
fprintf(f, "%s\n", log_state_str[state]);
fclose(f);
} else {
WARN("Could not dump state: %s", strerror(errno));
}
}
}
void err_dump(const char *msg) {
if (state_log_enabled) {
FILE *f = fopen("/tmp/update-state/last_error", "w");
if (f) {
fprintf(f, "%s\n", msg);
fclose(f);
}
}
}
void log_internal(enum log_level level, const char *file, size_t line, const char *func, const char *format, ...) {
bool do_syslog = (level <= syslog_level);
bool do_stderr = (level <= stderr_level);
......@@ -112,10 +69,6 @@ void log_internal(enum log_level level, const char *file, size_t line, const cha
else
fprintf(stderr, "%s:%s:%zu (%s):%s\n", levels[level].prefix, file, line, func, msg);
}
if (level == LL_DIE) {
update_state(LS_FAIL);
err_dump(msg);
}
}
bool would_log(enum log_level level) {
......
......@@ -24,25 +24,6 @@
#include <stdlib.h>
#include "util.h"
enum log_state {
LS_INIT, // Initial state
LS_CONF, // Running configuration scripts
LS_PLAN, // Generating plan
LS_DOWN, // Downloading needed packages
LS_PREUPD, // Running updater's preupdate hooks
// These are states in critical section
LS_UNPACK, // Unpacking downloaded packages
LS_CHECK, // Checking for files collisions and more
LS_INST, // Running preinst scripts and merging files to filesystem
LS_POST, // Running postinst scripts
LS_REM, // Removing leftover files
LS_CLEANUP, // Cleaning up control files
// End of critical section
LS_POSTUPD, // Running updater's postupdate hooks
LS_EXIT, // Updater exit
LS_FAIL, // Detected failure, exiting.
};
enum log_level {
LL_DISABLE,
LL_DIE,
......@@ -88,13 +69,6 @@ struct log_buffer {
// Initialize log buffer (if would_log(level)
void log_buffer_init(struct log_buffer *buf, enum log_level level) __attribute__((nonnull));
// Sets if state and error should be dumped into files in /tmp/updater-state directory
void set_state_log(bool state_log);
// Log state change of updater
void update_state(enum log_state);
// In the full updater mode, dump the error into /tmp/update-state/error
void err_dump(const char *msg) __attribute__((nonnull));
void log_syslog_level(enum log_level level);
void log_syslog_name(const char *name);
void log_stderr_level(enum log_level level);
......
......@@ -33,16 +33,6 @@ function DIE(...)
os.exit(1)
end
function log_event(action, package)
if state_log_enabled() then
local f = io.open("/tmp/update-state/log2", "a")
if f then
f:write(action, " ", package, "\n")
f:close()
end
end
end
-- Function used from C to generate message from error
function c_pcall_error_handler(err)
local function err2string(msg, err)
......
......@@ -42,16 +42,7 @@ local changelog = require "changelog"
local DBG = DBG
local WARN = WARN
local INFO = INFO
local LS_UNPACK = LS_UNPACK
local LS_INST = LS_INST
local LS_CHECK = LS_CHECK
local LS_INST = LS_INST
local LS_POST = LS_POST
local LS_REM = LS_REM
local LS_CLEANUP = LS_CLEANUP
local update_state = update_state
local sync = sync
local log_event = log_event
module "transaction"
......@@ -69,7 +60,6 @@ end
-- Stages of the transaction. Each one is written into the journal, with its results.
local function pkg_unpack(operations, status)
update_state(LS_UNPACK)
INFO("Unpacking download packages")
local dir_cleanups = {}
--[[
......@@ -141,7 +131,6 @@ local function pkg_unpack(operations, status)
end
local function pkg_collision_check(status, to_remove, to_install)
update_state(LS_CHECK)
INFO("Checking for file collisions between packages")
local collisions, early_remove, removes = backend.collision_check(status, to_remove, to_install)
if next(collisions) then
......@@ -176,7 +165,6 @@ local function changelog_end(curchangelog)
end
local function pkg_move(status, plan, early_remove, errors_collected, curchangelog)
update_state(LS_INST)
INFO("Running pre-install and pre-rm scripts and merging packages to root file system")
-- Prepare table of not installed confs for config stealing
local installed_confs = backend.installed_confs(status)
......@@ -194,7 +182,6 @@ local function pkg_move(status, plan, early_remove, errors_collected, curchangel
local upgraded_packages = {}
for _, op in ipairs(plan) do
if op.op == "install" then
log_event("I", op.control.Package .. " " .. op.control.Version)
-- Unfortunately, we need to merge the control files first, otherwise the maintainer scripts won't run. They expect to live in the info dir when they are run. And we need to run the preinst script before merging the files.
backend.pkg_merge_control(op.dir .. "/control", op.control.Package, op.control.files)
if utils.multi_index(status, op.control.Package, "Status", 3) == "installed" then
......@@ -214,7 +201,6 @@ local function pkg_move(status, plan, early_remove, errors_collected, curchangel
status[op.control.Package] = op.control
backend.pkg_update_alternatives(status, op.control.Package)
elseif op.op == "remove" and utils.arr2set(utils.multi_index(status, op.name, 'Status') or {})['installed'] then
log_event("R", op.name)
utils.table_merge(all_configs, status[op.name].Conffiles or {})
local cfiles = status[op.name].Conffiles or {}
for f in pairs(cfiles) do
......@@ -246,10 +232,8 @@ end
local function pkg_scripts(status, plan, removes, to_install, errors_collected, all_configs, upgraded_packages, curchangelog)
-- Clean up the files from removed or upgraded packages
INFO("Removing packages and leftover files")
update_state(LS_REM)
backend.pkg_cleanup_files(removes, all_configs)
-- Run post install and remove scripts
update_state(LS_POST)
INFO("Running post-install and post-rm scripts")
for _, op in ipairs(plan) do
if op.op == "install" then
......@@ -262,7 +246,6 @@ local function pkg_scripts(status, plan, removes, to_install, errors_collected,
end
local function pkg_cleanup(status)
update_state(LS_CLEANUP)
INFO("Cleaning up control files")
backend.control_cleanup(status)
backend.status_dump(status)
......
......@@ -28,10 +28,6 @@ local md5_file = md5_file
local sha256_file = sha256_file
local sha256 = sha256
local reexec = reexec
local LS_CONF = LS_CONF
local LS_PLAN = LS_PLAN
local LS_DOWN = LS_DOWN
local update_state = update_state
local utils = require "utils"
local syscnf = require "syscnf"
local sandbox = require "sandbox"
......@@ -61,10 +57,8 @@ local function required_pkgs(entrypoint)
-- Note: See requests.script for usage of this value
["parent_script_uri"] = entry_uri
}
update_state(LS_CONF)
local err = sandbox.run_sandboxed(entry_chunk, entrypoint, 'Full', nil, merge)
if err and err.tp == 'error' then error(err) end
update_state(LS_PLAN)
-- Go through all the requirements and decide what we need
postprocess.run()
return planner.required_pkgs(postprocess.available_packages, requests.content_requests)
......@@ -136,7 +130,6 @@ end
-- Download all packages and push tasks to transaction
function tasks_to_transaction()
INFO("Downloading packages")
update_state(LS_DOWN)
utils.mkdirp(syscnf.pkg_download_dir)
-- Start packages download
local uri_master = uri:new()
......@@ -145,7 +138,6 @@ function tasks_to_transaction()
task.file = syscnf.pkg_download_dir .. task.name .. '-' .. task.package.Version .. '.ipk'
task.real_uri = uri_master:to_file(task.package.Filename, task.file, task.package.repo.index_uri)
task.real_uri:add_pubkey() -- do not verify signatures (there are none)
-- TODO on failure: log_event('D', task.name .. " " .. task.package.Version)
end
end
local failed_uri = uri_master:download()
......
......@@ -7,20 +7,17 @@ redefined = false
max_line_length = false
globals = {
-- lua51 doesn't contains?
"_M",
"_M", -- lua51 doesn't contains it?
-- From interpreter.c
"log", "state_log_enabled", "update_state", "cleanup_register_handle",
"log", "cleanup_register_handle",
"cleanup_unregister_handle", "run_command", "run_util", "download",
"events_wait", "mkdtemp", "chdir", "getcwd", "mkdir", "move", "copy",
"symlink", "ls", "stat", "lstat", "sync", "setenv", "md5", "sha256",
"md5_file", "sha256_file", "reexec", "uri_internal_get", "system_reboot",
"get_updater_version", "subprocess", "subprocess_kill_timeout",
"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",
"LST_PKG_SCRIPT", "PST_HOOK",
-- From logging
"ERROR", "WARN", "INFO", "DBG", "TRACE", "DIE", "log_event", "c_pcall_error_handler",
"ERROR", "WARN", "INFO", "DBG", "TRACE", "DIE", "c_pcall_error_handler",
-- URI
"uri",
-- Picosat
......
......@@ -43,7 +43,6 @@ int main(int argc, char *argv[]) {
// Some setup of the machinery
log_stderr_level(LL_INFO);
log_syslog_level(LL_INFO);
set_state_log(false);
args_backup(argc, (const char **)argv);
struct events *events = events_new();
// Parse the arguments
......
......@@ -31,7 +31,6 @@ static struct argp_option options[] = {
{"no-immediate-reboot", OPT_NO_IMMEDIATE_REBOOT, NULL, 0, "Don't reboot immediately. Just ignore immediate reboots. This is usable if you are not running on target machine.", 2},
{"out-of-root", OPT_OUT_OF_ROOT, NULL, 0, "We are running updater out of root filesystem. This implies --no-replan and --no-immediate-reboot and is suggested to be used with --root option.", 2},
{"task-log", OPT_TASK_LOG, "FILE", 0, "Append list of executed tasks into a log file.", 3},
{"state-log", OPT_STATE_LOG, NULL, 0, "Dump state to files in /tmp/updater-state directory", 3},
// Following options are internal
{"reexec", OPT_REEXEC, NULL, OPTION_HIDDEN, "", 0},
{"reboot-finished", OPT_REBOOT_FINISHED, NULL, OPTION_HIDDEN, "", 0},
......@@ -68,9 +67,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPT_TASK_LOG:
opts->task_log = arg;
break;
case OPT_STATE_LOG:
set_state_log(true);
break;
case OPT_REEXEC:
opts->reexec = true;
break;
......
......@@ -38,7 +38,6 @@ static bool results_interpret(struct interpreter *interpreter, size_t result_cou
char *msg;
ASSERT(interpreter_collect_results(interpreter, "-s", &msg) == -1);
ERROR("%s", msg);
err_dump(msg);
}
if (result_count >= 1)
ASSERT(interpreter_collect_results(interpreter, "b", &result) == -1);
......@@ -125,7 +124,6 @@ int main(int argc, char *argv[]) {
system_detect();
update_state(LS_INIT);
struct events *events = events_new();
// Prepare the interpreter and load it with the embedded lua scripts
struct interpreter *interpreter = interpreter_create(events);
......@@ -152,7 +150,6 @@ int main(int argc, char *argv[]) {
if (err) {
trans_ok = false;
ERROR("%s", err);
err_dump(err);
GOTO_CLEANUP;
goto CLEANUP; // This is to suppress cppcheck redundant assigment warning
}
......@@ -178,26 +175,10 @@ int main(int argc, char *argv[]) {
err = interpreter_call(interpreter, "updater.tasks_to_transaction", NULL, "");
ASSERT_MSG(!err, "%s", err);
if (!opts.reexec) {
update_state(LS_PREUPD);
const char *hook_path = aprintf("%s%s", root_dir(), hook_preupdate);
setenv("ROOT_DIR", root_dir(), true);
exec_hook(hook_path, "Executing preupdate hook");
}
if (opts.task_log) {
FILE *log = fopen(opts.task_log, "a");
if (log) {
const char *timebuf = time_load();
fprintf(log, "%sTRANSACTION START\n", timebuf);
err = interpreter_call(interpreter, "updater.task_report", &result_count, "s", timebuf);
ASSERT_MSG(!err, "%s", err);
const char *content;
ASSERT_MSG(result_count == 1, "Wrong number of results of updater.task_report (%zu)", result_count);
ASSERT_MSG(interpreter_collect_results(interpreter, "s", &content) == -1, "The result of updater.task_report is not string");
fputs(content, log);
fclose(log);
} else
WARN("Couldn't store task log %s: %s", opts.task_log, strerror(errno));
}
err = interpreter_call(interpreter, "transaction.perform_queue", &result_count, "");
ASSERT_MSG(!err, "%s", err);
trans_ok = results_interpret(interpreter, result_count);
......@@ -214,20 +195,12 @@ int main(int argc, char *argv[]) {
}
err = interpreter_call(interpreter, "updater.cleanup", NULL, "bb", opts.reboot_finished);
ASSERT_MSG(!err, "%s", err);
if (opts.task_log) {
FILE *log = fopen(opts.task_log, "a");
if (log) {
fprintf(log, "%sTRANSACTION END\n", time_load());
fclose(log);
} else
WARN("Could not store task log end %s: %s", opts.task_log, strerror(errno));
}
REPLAN_CLEANUP:
update_state(LS_POSTUPD);
REPLAN_CLEANUP: {
const char *hook_path = aprintf("%s%s", root_dir(), hook_postupdate);
setenv("ROOT_DIR", root_dir(), true);
setenv("SUCCESS", trans_ok ? "true" : "false", true);
exec_hook(hook_path, "Executing postupdate hook");
}
CLEANUP:
free(opts.approve);
interpreter_destroy(interpreter);
......@@ -235,11 +208,5 @@ CLEANUP:
arg_backup_clear();
if (opts.reboot_finished)
system_reboot(false);
if (trans_ok) {
update_state(LS_EXIT);
return 0;
} else {
update_state(LS_FAIL);
return 1;
}
return trans_ok ? 0 : 1;
}
file://$ROOT_DIR/config --batch -R "$ROOT_DIR" --ask-approval=$ROOT_DIR/action_plan --task-log="$ROOT_DIR/task-log"
file://$ROOT_DIR/config --batch -R "$ROOT_DIR" --ask-approval=$ROOT_DIR/action_plan
sed -i -e 's/^Installed-Time: .*/Installed-Time: 0/' "$ROOT_DIR"/usr/lib/opkg/status
sed -i -e 's/^START .*/START 0/;s/^STOP .*/STOP 0/' "$ROOT_DIR"/usr/share/updater/changelog
sed -i -e 's/^[0-9: -]*//' "$ROOT_DIR"/task-log
rm "$ROOT_DIR"/config
rm -r "$ROOT_DIR"/repo
TRANSACTION START
install 4.8-linaro-3 libgcc
remove - pkg
TRANSACTION END
file://$ROOT_DIR/config --batch -R "$ROOT_DIR" --ask-approval=$ROOT_DIR/action_plan --approve=1c500dac2aed686288f9c949dcd4cbd621c9cd255c54c45d5136f56b6f79b220 --task-log="$ROOT_DIR/task-log"
file://$ROOT_DIR/config --batch -R "$ROOT_DIR" --ask-approval=$ROOT_DIR/action_plan --approve=1c500dac2aed686288f9c949dcd4cbd621c9cd255c54c45d5136f56b6f79b220
sed -i -e 's/^Installed-Time: .*/Installed-Time: 0/' "$ROOT_DIR"/usr/lib/opkg/status
sed -i -e 's/^START .*/START 0/;s/^STOP .*/STOP 0/' "$ROOT_DIR"/usr/share/updater/changelog
sed -i -e 's/^[^\t]*/0/' "$ROOT_DIR"/task-log
rm "$ROOT_DIR"/config
rm -r "$ROOT_DIR"/repo
0 TRANSACTION START
0 install 1 package
0 TRANSACTION END
file://$ROOT_DIR/config --batch -R "$ROOT_DIR" --task-log="$ROOT_DIR/task-log"
file://$ROOT_DIR/config --batch -R "$ROOT_DIR"
sed -i -e 's/^Installed-Time: .*/Installed-Time: 0/' "$ROOT_DIR"/usr/lib/opkg/status
sed -i -e 's/^START .*/START 0/;s/^STOP .*/STOP 0/' "$ROOT_DIR"/usr/share/updater/changelog
sed -i -e 's/^[^\t]*/0/' "$ROOT_DIR"/task-log
rm "$ROOT_DIR"/config
rm -r "$ROOT_DIR"/repo
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