Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jul 2018 13:22:48 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335935 - head/sys/kern
Message-ID:  <201807041322.w64DMmgv002552@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



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