svn commit: r335935 - head/sys/kern

Konstantin Belousov kib at FreeBSD.org
Wed Jul 4 13:22:49 UTC 2018


Author: kib
Date: Wed Jul  4 13:22:48 2018
New Revision: 335935
URL: https://svnweb.freebsd.org/changeset/base/335935

Log:
  Add a way for the process to request cleanup of the kernel cache of
  the process arguments.  New arguments length zero causes the drop of
  the pargs instead of allocation of useless zero-length buffer.
  
  Submitted by:	Thomas Munro
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D16111

Modified:
  head/sys/kern/kern_proc.c

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Wed Jul  4 09:07:18 2018	(r335934)
+++ head/sys/kern/kern_proc.c	Wed Jul  4 13:22:48 2018	(r335935)
@@ -1988,11 +1988,20 @@ sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
 
 	if (req->newlen > ps_arg_cache_limit - sizeof(struct pargs))
 		return (ENOMEM);
-	newpa = pargs_alloc(req->newlen);
-	error = SYSCTL_IN(req, newpa->ar_args, req->newlen);
-	if (error != 0) {
-		pargs_free(newpa);
-		return (error);
+
+	if (req->newlen == 0) {
+		/*
+		 * Clear the argument pointer, so that we'll fetch arguments
+		 * with proc_getargv() until further notice.
+		 */
+		newpa = NULL;
+	} else {
+		newpa = pargs_alloc(req->newlen);
+		error = SYSCTL_IN(req, newpa->ar_args, req->newlen);
+		if (error != 0) {
+			pargs_free(newpa);
+			return (error);
+		}
 	}
 	PROC_LOCK(p);
 	pa = p->p_args;


More information about the svn-src-head mailing list