Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Feb 2012 07:53:38 +0000 (UTC)
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r231552 - stable/7/lib/libkvm
Message-ID:  <201202120753.q1C7rcfd071479@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trociny
Date: Sun Feb 12 07:53:37 2012
New Revision: 231552
URL: http://svn.freebsd.org/changeset/base/231552

Log:
  MFC r230873:
  
  Try to avoid ambiguity when sysctl returns ENOMEM additionally
  checking the returned oldlen: when ENOMEM is due to the supplied
  buffer being too short the return oldlen is equal to buffer size.
  
  Without this additional check kvm_getprocs() gets stuck in loop if the
  returned ENOMEM was due the exceeded memorylocked limit. This is
  easily can be observed running `limits -l 1k top'.
  
  Submitted by:	Andrey Zonov <andrey zonov org>

Modified:
  stable/7/lib/libkvm/kvm_proc.c
Directory Properties:
  stable/7/lib/libkvm/   (props changed)

Modified: stable/7/lib/libkvm/kvm_proc.c
==============================================================================
--- stable/7/lib/libkvm/kvm_proc.c	Sun Feb 12 07:53:02 2012	(r231551)
+++ stable/7/lib/libkvm/kvm_proc.c	Sun Feb 12 07:53:37 2012	(r231552)
@@ -464,7 +464,7 @@ kvm_getprocs(kd, op, arg, cnt)
 	int *cnt;
 {
 	int mib[4], st, nprocs;
-	size_t size;
+	size_t size, osize;
 	int temp_op;
 
 	if (kd->procbase != 0) {
@@ -514,10 +514,11 @@ kvm_getprocs(kd, op, arg, cnt)
 			    _kvm_realloc(kd, kd->procbase, size);
 			if (kd->procbase == 0)
 				return (0);
+			osize = size;
 			st = sysctl(mib, temp_op == KERN_PROC_ALL ||
 			    temp_op == KERN_PROC_PROC ? 3 : 4,
 			    kd->procbase, &size, NULL, 0);
-		} while (st == -1 && errno == ENOMEM);
+		} while (st == -1 && errno == ENOMEM && size == osize);
 		if (st == -1) {
 			_kvm_syserr(kd, kd->program, "kvm_getprocs");
 			return (0);



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