Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Dec 2018 14:48:51 +0000 (UTC)
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r342591 - head/sys/kern
Message-ID:  <201812291448.wBTEmpmt056171@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kp
Date: Sat Dec 29 14:48:51 2018
New Revision: 342591
URL: https://svnweb.freebsd.org/changeset/base/342591

Log:
  Make kernel print jail ID when logging a process exit
  
  Kernel now includes jail ID when logging a process exit. jid is 0 for unjailed
  processes.
  
  Submitted by:	Marie Helene Kvello-Aune <freebsd@mhka.no>
  Relnotes:	yes
  Sponsored by:	Modirum MDPay
  Differential Revision:	https://reviews.freebsd.org/D18618

Modified:
  head/sys/kern/kern_sig.c

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Sat Dec 29 06:52:52 2018	(r342590)
+++ head/sys/kern/kern_sig.c	Sat Dec 29 14:48:51 2018	(r342591)
@@ -3094,12 +3094,17 @@ proc_wkilled(struct proc *p)
 void
 killproc(struct proc *p, char *why)
 {
+	int jid = -1;
 
+	if (p->p_ucred && p->p_ucred->cr_prison)
+		jid = p->p_ucred->cr_prison->pr_id;
+
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	CTR3(KTR_PROC, "killproc: proc %p (pid %d, %s)", p, p->p_pid,
 	    p->p_comm);
-	log(LOG_ERR, "pid %d (%s), uid %d, was killed: %s\n", p->p_pid,
-	    p->p_comm, p->p_ucred ? p->p_ucred->cr_uid : -1, why);
+	log(LOG_ERR, "pid %d (%s), jid %d, uid %d, was killed: %s\n",
+	    p->p_pid, p->p_comm, jid,
+	    p->p_ucred ? p->p_ucred->cr_uid : -1, why);
 	proc_wkilled(p);
 	kern_psignal(p, SIGKILL);
 }
@@ -3116,7 +3121,11 @@ void
 sigexit(struct thread *td, int sig)
 {
 	struct proc *p = td->td_proc;
+	int jid = -1;
 
+	if (p->p_ucred && p->p_ucred->cr_prison)
+		jid = p->p_ucred->cr_prison->pr_id;
+
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	p->p_acflag |= AXSIG;
 	/*
@@ -3142,8 +3151,8 @@ sigexit(struct thread *td, int sig)
 			sig |= WCOREFLAG;
 		if (kern_logsigexit)
 			log(LOG_INFO,
-			    "pid %d (%s), uid %d: exited on signal %d%s\n",
-			    p->p_pid, p->p_comm,
+			    "pid %d (%s), jid %d, uid %d: exited on "
+			    "signal %d%s\n", p->p_pid, p->p_comm, jid,
 			    td->td_ucred ? td->td_ucred->cr_uid : -1,
 			    sig &~ WCOREFLAG,
 			    sig & WCOREFLAG ? " (core dumped)" : "");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812291448.wBTEmpmt056171>