f31522130f
Build system (5 gaps hardened): - COOKBOOK_OFFLINE defaults to true (fork-mode) - normalize_patch handles diff -ruN format - New 'repo validate-patches' command (25/25 relibc patches) - 14 patched Qt/Wayland/display recipes added to protected list - relibc archive regenerated with current patch chain Boot fixes (fixable): - Full ISO EFI partition: 16 MiB → 1 MiB (matches mini, BIOS hardcoded 2 MiB offset) - D-Bus system bus: absolute /usr/bin/dbus-daemon path (was skipped) - redbear-sessiond: absolute /usr/bin/redbear-sessiond path (was skipped) - daemon framework: silenced spurious INIT_NOTIFY warnings for oneshot_async services (P0-daemon-silence-init-notify.patch) - udev-shim: demoted INIT_NOTIFY warning to INFO (expected for oneshot_async) - relibc: comprehensive named semaphores (sem_open/close/unlink) replacing upstream todo!() stubs - greeterd: Wayland socket timeout 15s → 30s (compositor DRM wait) - greeter-ui: built and linked (header guard unification, sem_compat stubs removed) - mc: un-ignored in both configs, fixed glib/libiconv/pcre2 transitive deps - greeter config: removed stale keymapd dependency from display/greeter services - prefix toolchain: relibc headers synced, _RELIBC_STDLIB_H guard unified Unfixable (diagnosed, upstream): - i2c-hidd: abort on no-I2C-hardware (QEMU) — process::exit → relibc abort - kded6/greeter-ui: page fault 0x8 — Qt library null deref - Thread panics fd != -1 — Rust std library on Redox - DHCP timeout / eth0 MAC — QEMU user-mode networking - hwrngd/thermald — no hardware RNG/thermal in VM - live preload allocation — BIOS memory fragmentation, continues on demand
99 lines
2.4 KiB
C
99 lines
2.4 KiB
C
#include <errno.h>
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "log.h"
|
|
|
|
const long NSEC_PER_SEC = 1000000000;
|
|
|
|
static void log_stderr(enum libseat_log_level level, const char *fmt, va_list args);
|
|
|
|
static enum libseat_log_level current_log_level = LIBSEAT_LOG_LEVEL_SILENT;
|
|
static libseat_log_func current_log_handler = log_stderr;
|
|
static struct timespec start_time = {-1, -1};
|
|
static bool colored = false;
|
|
|
|
static const char *verbosity_colors[] = {
|
|
[LIBSEAT_LOG_LEVEL_SILENT] = "",
|
|
[LIBSEAT_LOG_LEVEL_ERROR] = "\x1B[1;31m",
|
|
[LIBSEAT_LOG_LEVEL_INFO] = "\x1B[1;34m",
|
|
[LIBSEAT_LOG_LEVEL_DEBUG] = "\x1B[1;90m",
|
|
};
|
|
|
|
static const char *verbosity_headers[] = {
|
|
[LIBSEAT_LOG_LEVEL_SILENT] = "",
|
|
[LIBSEAT_LOG_LEVEL_ERROR] = "[ERROR]",
|
|
[LIBSEAT_LOG_LEVEL_INFO] = "[INFO]",
|
|
[LIBSEAT_LOG_LEVEL_DEBUG] = "[DEBUG]",
|
|
};
|
|
|
|
static void timespec_sub(struct timespec *r, const struct timespec *a, const struct timespec *b) {
|
|
r->tv_sec = a->tv_sec - b->tv_sec;
|
|
r->tv_nsec = a->tv_nsec - b->tv_nsec;
|
|
if (r->tv_nsec < 0) {
|
|
r->tv_sec--;
|
|
r->tv_nsec += NSEC_PER_SEC;
|
|
}
|
|
}
|
|
|
|
static void log_stderr(enum libseat_log_level level, const char *fmt, va_list args) {
|
|
struct timespec ts = {0};
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
timespec_sub(&ts, &ts, &start_time);
|
|
unsigned c = (level < LIBSEAT_LOG_LEVEL_LAST) ? level : LIBSEAT_LOG_LEVEL_LAST - 1;
|
|
|
|
const char *prefix, *postfix;
|
|
|
|
if (colored) {
|
|
prefix = verbosity_colors[c];
|
|
postfix = "\x1B[0m\n";
|
|
} else {
|
|
prefix = verbosity_headers[c];
|
|
postfix = "\n";
|
|
}
|
|
|
|
fprintf(stderr, "%02d:%02d:%02d.%03ld %s ", (int)(ts.tv_sec / 60 / 60),
|
|
(int)(ts.tv_sec / 60 % 60), (int)(ts.tv_sec % 60), ts.tv_nsec / 1000000, prefix);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fprintf(stderr, "%s", postfix);
|
|
}
|
|
|
|
void log_init(void) {
|
|
if (start_time.tv_sec >= 0) {
|
|
return;
|
|
}
|
|
clock_gettime(CLOCK_MONOTONIC, &start_time);
|
|
colored = isatty(STDERR_FILENO);
|
|
}
|
|
|
|
void _logf(enum libseat_log_level level, const char *fmt, ...) {
|
|
int stored_errno = errno;
|
|
va_list args;
|
|
if (level > current_log_level) {
|
|
return;
|
|
}
|
|
|
|
va_start(args, fmt);
|
|
current_log_handler(level, fmt, args);
|
|
va_end(args);
|
|
|
|
errno = stored_errno;
|
|
}
|
|
|
|
void libseat_set_log_handler(libseat_log_func handler) {
|
|
if (handler == NULL) {
|
|
handler = log_stderr;
|
|
}
|
|
current_log_handler = handler;
|
|
}
|
|
|
|
void libseat_set_log_level(enum libseat_log_level level) {
|
|
current_log_level = level;
|
|
}
|