feat: identify userspace logs by user and image

This commit is contained in:
2026-08-22 18:48:38 +02:00
parent 8a74b771e1
commit ffc9756e67
7 changed files with 24 additions and 18 deletions
+11 -7
View File
@@ -53,7 +53,6 @@ namespace montauk::abi {
static constexpr uint64_t kMaxWindowTitleBytes = 256;
static constexpr uint64_t kMaxHostnameBytes = 256;
static constexpr uint64_t kMaxUserNameBytes = 32;
static constexpr uint64_t kMaxUserspaceLogComponentNameBytes = 32;
static constexpr uint64_t kMaxUserspaceLogEntryBytes = 1024;
// ---- Dispatch ----
@@ -611,14 +610,19 @@ namespace montauk::abi {
return Sys_ClipboardClear();
case SYS_INPUT_WAIT:
return (int64_t)Sys_InputWait(frame->arg1, frame->arg2);
case SYS_LOG_WRITE: { // "init" <---- component name (arg1)
// "started service ..." <---- log message (arg2)
case SYS_LOG_WRITE: {
if (!UserMemory::String(frame->arg1, kMaxUserspaceLogEntryBytes)) return -1;
if (!UserMemory::String(frame->arg1, kMaxUserspaceLogComponentNameBytes)
|| !UserMemory::String(frame->arg2, kMaxUserspaceLogEntryBytes)
) return -1;
auto* process = Sched::GetCurrentProcessPtr();
const char* username = process != nullptr && process->user[0] != '\0'
? process->user
: "unknown";
const char* imageName = process != nullptr && process->name[0] != '\0'
? process->name
: "unknown";
Kt::UserspaceLogStream((const char*)frame->arg1) << (const char*)frame->arg2;
Kt::UserspaceLogStream(imageName, username)
<< (const char*)frame->arg1;
return 0;
}
+6 -4
View File
@@ -170,16 +170,18 @@ public:
class UserspaceLogStream {
KernelOutStream localStream{};
const char* componentName = "";
const char* imageName = "";
const char* username = "";
public:
UserspaceLogStream(const char* desiredComponentName) {
UserspaceLogStream(const char* desiredImageName, const char* desiredUsername) {
g_termLock.Acquire();
g_kernelLogDepth++;
componentName = desiredComponentName;
imageName = desiredImageName;
username = desiredUsername;
localStream << "[userspace/" << componentName << "]" << ": ";
localStream << "[user " << username << "@" << imageName << "] ";
}
~UserspaceLogStream() {
+1 -1
View File
@@ -239,7 +239,7 @@ namespace montauk::abi {
static constexpr uint64_t SYS_SETENVIRON = 172;
static constexpr uint64_t SYS_SPAWN_ENV = 173;
static constexpr uint64_t SYS_LOG_WRITE = 176; // (componentName, logMessage) -> 0
static constexpr uint64_t SYS_LOG_WRITE = 176; // (logMessage) -> 0
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
+2 -2
View File
@@ -434,8 +434,8 @@ namespace montauk {
return syscall2(montauk::abi::SYS_LOG, (uint64_t)buf, size);
}
inline int64_t write_log(const char* userspaceComponent, const char* logMessage) {
return syscall2(montauk::abi::SYS_LOG_WRITE, (uint64_t)userspaceComponent, (uint64_t)logMessage);
inline int64_t write_log(const char* logMessage) {
return syscall1(montauk::abi::SYS_LOG_WRITE, (uint64_t)logMessage);
}
// I/O redirection
+1 -1
View File
@@ -57,7 +57,7 @@ static void log(LogLevel level, const char* msg) {
snprintf(line, sizeof(line),
C_DIM "%s" C_RESET " %s%s" C_RESET " %s",
ts, color, tag, msg);
montauk::write_log("init", line);
montauk::write_log(line);
}
static void log_ok(const char* msg) { log(LOG_OK, msg); }
+1 -1
View File
@@ -239,7 +239,7 @@ namespace montauk::abi {
static constexpr uint64_t SYS_SETENVIRON = 172;
static constexpr uint64_t SYS_SPAWN_ENV = 173;
static constexpr uint64_t SYS_LOG_WRITE = 176; // (componentName, logMessage) -> 0
static constexpr uint64_t SYS_LOG_WRITE = 176; // (logMessage) -> 0
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
+2 -2
View File
@@ -434,8 +434,8 @@ namespace montauk {
return syscall2(montauk::abi::SYS_LOG, (uint64_t)buf, size);
}
inline int64_t write_log(const char* userspaceComponent, const char* logMessage) {
return syscall2(montauk::abi::SYS_LOG_WRITE, (uint64_t)userspaceComponent, (uint64_t)logMessage);
inline int64_t write_log(const char* logMessage) {
return syscall1(montauk::abi::SYS_LOG_WRITE, (uint64_t)logMessage);
}
// I/O redirection