From 6422ef409527ebe71e0005910a79c4b1830135b9 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Fri, 23 Jun 2023 09:47:08 -0700 Subject: [PATCH] Log the PID/TID in root pidns and caller's pidns. This is to aid debugging. The application logs make more sense wrt caller pidns because the application uses PID numbers from its pidns. Logs like `stat(/pid/PID/status)` are understandable. PiperOrigin-RevId: 542884517 --- pkg/sentry/kernel/task_log.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/sentry/kernel/task_log.go b/pkg/sentry/kernel/task_log.go index 35e548706..16500ac8b 100644 --- a/pkg/sentry/kernel/task_log.go +++ b/pkg/sentry/kernel/task_log.go @@ -190,12 +190,18 @@ const ( // // Preconditions: The task's owning TaskSet.mu must be locked. func (t *Task) updateInfoLocked() { - // Use the task's TID and PID in the root PID namespace for logging. - pid := t.tg.pidns.owner.Root.tgids[t.tg] - tid := t.tg.pidns.owner.Root.tids[t] - t.logPrefix.Store(fmt.Sprintf("[% 4d:% 4d] ", pid, tid)) + // Log the TID and PID in root pidns and t's pidns. + rootPID := t.tg.pidns.owner.Root.tgids[t.tg] + rootTID := t.tg.pidns.owner.Root.tids[t] + pid := t.tg.pidns.tgids[t.tg] + tid := t.tg.pidns.tids[t] + if rootPID == pid && rootTID == tid { + t.logPrefix.Store(fmt.Sprintf("[% 4d:% 4d] ", pid, tid)) + } else { + t.logPrefix.Store(fmt.Sprintf("[% 4d(%4d):% 4d(%4d)] ", rootPID, pid, rootTID, tid)) + } - t.rebuildTraceContext(tid) + t.rebuildTraceContext(rootTID) } // rebuildTraceContext rebuilds the trace context.