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