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
This commit is contained in:
Ayush Ranjan
2023-06-23 09:50:29 -07:00
committed by gVisor bot
parent fedbf08401
commit 6422ef4095
+11 -5
View File
@@ -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.