From nobody@FreeBSD.org  Mon Oct  3 13:53:19 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B7683106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  3 Oct 2011 13:53:19 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 8EE818FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  3 Oct 2011 13:53:19 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p93DrJfl096187
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 3 Oct 2011 13:53:19 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p93DrJb8096179;
	Mon, 3 Oct 2011 13:53:19 GMT
	(envelope-from nobody)
Message-Id: <201110031353.p93DrJb8096179@red.freebsd.org>
Date: Mon, 3 Oct 2011 13:53:19 GMT
From: John Baldwin <jhb@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: procstat should grow a -l flag to display resource limits
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161257
>Category:       bin
>Synopsis:       procstat(1): procstat should grow a -l flag to display resource limits
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 03 14:00:03 UTC 2011
>Closed-Date:    Wed May 15 16:57:12 UTC 2013
>Last-Modified:  Wed May 15 16:57:12 UTC 2013
>Originator:     John Baldwin
>Release:        HEAD
>Organization:
FreeBSD
>Environment:
>Description:
Currently the only way to determine the limits of a running process is
to cat /proc/<pid>/rlimit.  It would be nice to have this information
available via procstat instead.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Mikolaj Golub <trociny@freebsd.org>
To: John Baldwin <jhb@FreeBSD.org>
Cc: bug-followup@FreeBSD.org, Kostik Belousov <kib@FreeBSD.org>, Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sat, 05 Nov 2011 14:45:03 +0200

 --=-=-=
 
 Hi,
 
 Here is the patch that does 'procstat -l'. 
 
 Note, I had to change rlimit_ident[] from char * to const char * to make
 procstat compile without warnings.
 
 -- 
 Mikolaj Golub
 
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=rlimit.patch
 
 diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
 index 998e7ca..77cbd4e 100644
 --- a/sys/kern/kern_proc.c
 +++ b/sys/kern/kern_proc.c
 @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/mutex.h>
  #include <sys/proc.h>
  #include <sys/refcount.h>
 +#include <sys/resourcevar.h>
  #include <sys/sbuf.h>
  #include <sys/sysent.h>
  #include <sys/sched.h>
 @@ -1989,6 +1990,38 @@ sysctl_kern_proc_groups(SYSCTL_HANDLER_ARGS)
  	return (error);
  }
  
 +/*
 + * This sysctl allows a process to retrieve the resource limits for
 + * another process.
 + */
 +static int
 +sysctl_kern_proc_rlimit(SYSCTL_HANDLER_ARGS)
 +{
 +	int *name = (int*) arg1;
 +	u_int namelen = arg2;
 +        struct plimit *limp;
 +	struct proc *p;
 +	int error = 0;
 +
 +	if (namelen != 1)
 +		return (EINVAL);
 +
 +	p = pfind((pid_t)name[0]);
 +	if (p == NULL)
 +		return (ESRCH);
 +
 +	if ((error = p_cansee(curthread, p)) != 0) {
 +		PROC_UNLOCK(p);
 +		return (error);
 +	}
 +
 +	limp = lim_hold(p->p_limit);
 +	PROC_UNLOCK(p);
 +	error = SYSCTL_OUT(req, limp->pl_rlimit, sizeof(limp->pl_rlimit));
 +        lim_free(limp);
 +        return (error);
 +}
 +
  SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD,  0, "Process table");
  
  SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
 @@ -2076,3 +2109,6 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_KSTACK, kstack, CTLFLAG_RD |
  
  static SYSCTL_NODE(_kern_proc, KERN_PROC_GROUPS, groups, CTLFLAG_RD |
  	CTLFLAG_MPSAFE, sysctl_kern_proc_groups, "Process groups");
 +
 +static SYSCTL_NODE(_kern_proc, KERN_PROC_RLIMIT, rlimit, CTLFLAG_RD |
 +	CTLFLAG_MPSAFE, sysctl_kern_proc_rlimit, "Process resource limits");
 diff --git a/sys/sys/resource.h b/sys/sys/resource.h
 index 7d0b4ee..c5e912bd 100644
 --- a/sys/sys/resource.h
 +++ b/sys/sys/resource.h
 @@ -108,7 +108,7 @@ struct rusage {
   */
  
  #ifdef _RLIMIT_IDENT
 -static char *rlimit_ident[RLIM_NLIMITS] = {
 +static const char *rlimit_ident[RLIM_NLIMITS] = {
  	"cpu",
  	"fsize",
  	"data",
 diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
 index 1e879f5..98b253b 100644
 --- a/sys/sys/sysctl.h
 +++ b/sys/sys/sysctl.h
 @@ -559,6 +559,7 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; );
  #define	KERN_PROC_VMMAP		32	/* VM map entries for process */
  #define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
  #define	KERN_PROC_GROUPS	34	/* process groups */
 +#define	KERN_PROC_RLIMIT	35	/* process resource limits */
  
  /*
   * KERN_IPC identifiers
 diff --git a/usr.bin/procstat/Makefile b/usr.bin/procstat/Makefile
 index e8e35ed..5aa683c 100644
 --- a/usr.bin/procstat/Makefile
 +++ b/usr.bin/procstat/Makefile
 @@ -9,6 +9,7 @@ SRCS=	procstat.c		\
  	procstat_cred.c		\
  	procstat_files.c	\
  	procstat_kstack.c	\
 +	procstat_rlimit.c	\
  	procstat_sigs.c		\
  	procstat_threads.c	\
  	procstat_vm.c
 diff --git a/usr.bin/procstat/procstat.1 b/usr.bin/procstat/procstat.1
 index 35fab1f..1b3b8c1 100644
 --- a/usr.bin/procstat/procstat.1
 +++ b/usr.bin/procstat/procstat.1
 @@ -25,7 +25,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd August 14, 2011
 +.Dd November 5, 2011
  .Dt PROCSTAT 1
  .Os
  .Sh NAME
 @@ -67,6 +67,8 @@ Display the stacks of kernel threads in the process, excluding stacks of
  threads currently running on a CPU and threads with stacks swapped to disk.
  If the flag is repeated, function offsets as well as function names are
  printed.
 +.It Fl l
 +Display resource limits for the process.
  .It Fl s
  Display security credential information for the process.
  .It Fl t
 diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
 index 97ff879..c79bb39 100644
 --- a/usr.bin/procstat/procstat.c
 +++ b/usr.bin/procstat/procstat.c
 @@ -39,7 +39,8 @@
  
  #include "procstat.h"
  
 -static int aflag, bflag, cflag, fflag, iflag, jflag, kflag, sflag, tflag, vflag;
 +static int aflag, bflag, cflag, fflag, iflag, jflag, kflag, lflag, sflag, tflag;
 +static int vflag;
  int	hflag, nflag, Cflag;
  
  static void
 @@ -47,7 +48,7 @@ usage(void)
  {
  
  	fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] "
 -	    "[-w interval] [-b | -c | -f | -i | -j | -k | -s | -t | -v]\n");
 +	    "[-w interval] [-b | -c | -f | -i | -j | -k | -l | -s | -t | -v]\n");
  	fprintf(stderr, "                [-a | pid ...]\n");
  	exit(EX_USAGE);
  }
 @@ -68,6 +69,8 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
  		procstat_threads_sigs(prstat, kipp);
  	else if (kflag)
  		procstat_kstack(kipp, kflag);
 +	else if (lflag)
 +		procstat_rlimit(kipp);
  	else if (sflag)
  		procstat_cred(kipp);
  	else if (tflag)
 @@ -117,7 +120,7 @@ main(int argc, char *argv[])
  
  	interval = 0;
  	memf = nlistf = NULL;
 -	while ((ch = getopt(argc, argv, "CN:M:abcfijkhstvw:")) != -1) {
 +	while ((ch = getopt(argc, argv, "CN:M:abcfijklhstvw:")) != -1) {
  		switch (ch) {
  		case 'C':
  			Cflag++;
 @@ -157,6 +160,10 @@ main(int argc, char *argv[])
  			kflag++;
  			break;
  
 +		case 'l':
 +			lflag++;
 +			break;
 +
  		case 'n':
  			nflag++;
  			break;
 @@ -196,7 +203,8 @@ main(int argc, char *argv[])
  	argv += optind;
  
  	/* We require that either 0 or 1 mode flags be set. */
 -	tmp = bflag + cflag + fflag + (kflag ? 1 : 0) + sflag + tflag + vflag;
 +	tmp = bflag + cflag + fflag + (kflag ? 1 : 0) + lflag + sflag + tflag +
 +	    vflag;
  	if (!(tmp == 0 || tmp == 1))
  		usage();
  
 diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
 index 71e3ca7..5994feb 100644
 --- a/usr.bin/procstat/procstat.h
 +++ b/usr.bin/procstat/procstat.h
 @@ -40,6 +40,7 @@ void	procstat_bin(struct kinfo_proc *kipp);
  void	procstat_cred(struct kinfo_proc *kipp);
  void	procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_kstack(struct kinfo_proc *kipp, int kflag);
 +void	procstat_rlimit(struct kinfo_proc *kipp);
  void	procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_threads(struct kinfo_proc *kipp);
  void	procstat_threads_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
 diff --git a/usr.bin/procstat/procstat_rlimit.c b/usr.bin/procstat/procstat_rlimit.c
 new file mode 100644
 index 0000000..59d2323
 --- /dev/null
 +++ b/usr.bin/procstat/procstat_rlimit.c
 @@ -0,0 +1,83 @@
 +/*-
 + * Copyright (c) 2011 Mikolaj Golub
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 + * SUCH DAMAGE.
 + *
 + * $FreeBSD$
 + */
 +
 +#include <sys/param.h>
 +#include <sys/time.h>
 +#define _RLIMIT_IDENT
 +#include <sys/resourcevar.h>
 +#include <sys/sysctl.h>
 +#include <sys/user.h>
 +
 +#include <err.h>
 +#include <errno.h>
 +#include <libprocstat.h>
 +#include <limits.h>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
 +#include "procstat.h"
 +
 +static struct rlimit rlimit[RLIM_NLIMITS];
 +
 +void
 +procstat_rlimit(struct kinfo_proc *kipp)
 +{
 +	int error, i, name[4];
 +	size_t len;
 +
 +	if (!hflag)
 +		printf("%5s %-16s %-53s\n", "PID", "COMM", "RLIMIT");
 +
 +	name[0] = CTL_KERN;
 +	name[1] = KERN_PROC;
 +	name[2] = KERN_PROC_RLIMIT;
 +	name[3] = kipp->ki_pid;
 +	len = sizeof(rlimit);
 +	error = sysctl(name, 4, rlimit, &len, NULL, 0);
 +	if (error < 0 && errno != ESRCH) {
 +		warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
 +		return;
 +	}
 +	if (error < 0)
 +		return;
 +
 +	printf("%5d %-16s", kipp->ki_pid, kipp->ki_comm);
 +	if (len != sizeof(rlimit)) {
 +		printf("-\n");
 +		return;
 +	}
 +	for (i = 0; i < RLIM_NLIMITS; i++) {
 +		printf(" %s:%jd/%jd", rlimit_ident[i],
 +		    rlimit[i].rlim_cur == RLIM_INFINITY ?
 +		    -1 : rlimit[i].rlim_cur,
 +		    rlimit[i].rlim_max == RLIM_INFINITY ?
 +		    -1 : rlimit[i].rlim_max);
 +        }
 +	printf("\n");
 +}
 
 --=-=-=--

From: Kostik Belousov <kostikbel@gmail.com>
To: Mikolaj Golub <trociny@freebsd.org>
Cc: John Baldwin <jhb@freebsd.org>, bug-followup@freebsd.org,
        Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sat, 5 Nov 2011 16:08:39 +0200

 --8mza6Y2scN2dXhu9
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sat, Nov 05, 2011 at 02:45:03PM +0200, Mikolaj Golub wrote:
 > Hi,
 >=20
 > Here is the patch that does 'procstat -l'.=20
 >=20
 > Note, I had to change rlimit_ident[] from char * to const char * to make
 > procstat compile without warnings.
 Commit it as a separate change. Also, I suggest you to commit the sysctl
 kern.proc. oids in advance to avoid conflicts with argv/env patches.
 
 You just cannot stop ?
 
 The intendation in the sysctl_kern_proc_rlimit local variables block=20
 is inconsistent. Err, it is inconsistent in the whole function.
 
 Please note that we grow the count of resources supported, e.g.
 we got RLIMIT_NPTS and RLIMIT_SWAP for 8.0. At least a comment near
 RLIM_NLIMITS to point anybody adding a new resource, to the kern.proc.rlimit
 handler, is useful. For the same reason, you can restructure the handler
 to honour the sysctl oldsize (but this is not needed right now).
 
 Not related to your patch: it seems that lim_fork() wants an assert
 that processes locks are held. Also you can add a blank line after '{'
 there too.
 
 For the output format, I much prefer to have current and maximum
 values be tab-separated, instead of slash.
 
 --8mza6Y2scN2dXhu9
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (FreeBSD)
 
 iEUEARECAAYFAk61Q2YACgkQC3+MBN1Mb4gJxgCY/s7sooJttBO9LIlmURRXpsWd
 xgCfQoy09PMpiWZQ+QsGPu2nFQ81+nY=
 =UH8N
 -----END PGP SIGNATURE-----
 
 --8mza6Y2scN2dXhu9--

From: Mikolaj Golub <trociny@freebsd.org>
To: Kostik Belousov <kostikbel@gmail.com>
Cc: John Baldwin <jhb@freebsd.org>,  bug-followup@freebsd.org,  Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sat, 05 Nov 2011 18:06:10 +0200

 On Sat, 5 Nov 2011 16:08:39 +0200 Kostik Belousov wrote:
 
  KB> On Sat, Nov 05, 2011 at 02:45:03PM +0200, Mikolaj Golub wrote:
  >> Hi,
  >> 
  >> Here is the patch that does 'procstat -l'. 
  >> 
  >> Note, I had to change rlimit_ident[] from char * to const char * to make
  >> procstat compile without warnings.
  KB> Commit it as a separate change. Also, I suggest you to commit the sysctl
  KB> kern.proc. oids in advance to avoid conflicts with argv/env patches.
 
  KB> You just cannot stop ?
 
  KB> The intendation in the sysctl_kern_proc_rlimit local variables block 
  KB> is inconsistent. Err, it is inconsistent in the whole function.
 
  KB> Please note that we grow the count of resources supported, e.g.
  KB> we got RLIMIT_NPTS and RLIMIT_SWAP for 8.0. At least a comment near
  KB> RLIM_NLIMITS to point anybody adding a new resource, to the kern.proc.rlimit
  KB> handler, is useful. For the same reason, you can restructure the handler
  KB> to honour the sysctl oldsize (but this is not needed right now).
 
  KB> Not related to your patch: it seems that lim_fork() wants an assert
  KB> that processes locks are held. Also you can add a blank line after '{'
  KB> there too.
 
  KB> For the output format, I much prefer to have current and maximum
  KB> values be tab-separated, instead of slash.
 
 Thank you for your comments. Concerning this last one, all limits for a
 process are printed on the same line, as it is done for other stats (to have
 it readable when procstat is run with -a flag). So as for me having current
 and maximum values be tab-separated will make output less readable. Don't you
 agree?
 
 -- 
 Mikolaj Golub

From: Kostik Belousov <kostikbel@gmail.com>
To: Mikolaj Golub <trociny@freebsd.org>
Cc: John Baldwin <jhb@freebsd.org>, bug-followup@freebsd.org,
        Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sat, 5 Nov 2011 18:15:38 +0200

 --N7cqGfFtEgKFZnsX
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sat, Nov 05, 2011 at 06:06:10PM +0200, Mikolaj Golub wrote:
 >=20
 > On Sat, 5 Nov 2011 16:08:39 +0200 Kostik Belousov wrote:
 >=20
 >  KB> For the output format, I much prefer to have current and maximum
 >  KB> values be tab-separated, instead of slash.
 >=20
 > Thank you for your comments. Concerning this last one, all limits for a
 > process are printed on the same line, as it is done for other stats (to h=
 ave
 > it readable when procstat is run with -a flag). So as for me having curre=
 nt
 > and maximum values be tab-separated will make output less readable. Don't=
  you
 > agree?
 No, please look at the procstat -i -a output.
 It is easier to parse this way.
 
 --N7cqGfFtEgKFZnsX
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (FreeBSD)
 
 iEYEARECAAYFAk61YSoACgkQC3+MBN1Mb4jXoQCg749zz67kGPBB+uj4mpCdcIBh
 Ni8AnRclqww6BPNob34i4td7Cy6xsZ4t
 =VAMC
 -----END PGP SIGNATURE-----
 
 --N7cqGfFtEgKFZnsX--

From: Mikolaj Golub <to.my.trociny@gmail.com>
To: Kostik Belousov <kostikbel@gmail.com>
Cc: John Baldwin <jhb@freebsd.org>,  bug-followup@freebsd.org, Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sun, 06 Nov 2011 00:21:29 +0200

 On Sat, 5 Nov 2011 16:08:39 +0200 Kostik Belousov wrote:
 
  KB> Please note that we grow the count of resources supported, e.g.
  KB> we got RLIMIT_NPTS and RLIMIT_SWAP for 8.0. At least a comment near
  KB> RLIM_NLIMITS to point anybody adding a new resource, to the kern.proc.rlimit
  KB> handler, is useful.
 
 Does this look ok?
 
 http://people.freebsd.org/~trociny/resource.h.patch
 
 The update rlimit patch:
 
 http://people.freebsd.org/~trociny/rlimit.1.patch
 
 -- 
 Mikolaj Golub

From: Kostik Belousov <kostikbel@gmail.com>
To: Mikolaj Golub <to.my.trociny@gmail.com>
Cc: John Baldwin <jhb@freebsd.org>, bug-followup@freebsd.org,
        Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sun, 6 Nov 2011 20:13:14 +0200

 --7BqLQYFz2JFDkkGf
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sun, Nov 06, 2011 at 12:21:29AM +0200, Mikolaj Golub wrote:
 >=20
 > On Sat, 5 Nov 2011 16:08:39 +0200 Kostik Belousov wrote:
 >=20
 >  KB> Please note that we grow the count of resources supported, e.g.
 >  KB> we got RLIMIT_NPTS and RLIMIT_SWAP for 8.0. At least a comment near
 >  KB> RLIM_NLIMITS to point anybody adding a new resource, to the kern.pro=
 c.rlimit
 >  KB> handler, is useful.
 >=20
 > Does this look ok?
 >=20
 > http://people.freebsd.org/~trociny/resource.h.patch
 No, it completely misses my point. You should request the person to handle
 binary compatibility for sysctl, not for the array of names.
 It should be done in the course of rlimit.patch.
 
 >=20
 > The update rlimit patch:
 >=20
 > http://people.freebsd.org/~trociny/rlimit.1.patch
 I have no further comments.
 
 --7BqLQYFz2JFDkkGf
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (FreeBSD)
 
 iEYEARECAAYFAk62zjkACgkQC3+MBN1Mb4jBdwCgyHAvgXGzI7syQIAJWSrVUeO9
 nWgAnRr89MWz9nPw64y75GpvZdwcT/Zu
 =NdFL
 -----END PGP SIGNATURE-----
 
 --7BqLQYFz2JFDkkGf--

From: Kostik Belousov <kostikbel@gmail.com>
To: Mikolaj Golub <to.my.trociny@gmail.com>
Cc: John Baldwin <jhb@freebsd.org>, bug-followup@freebsd.org,
        Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sun, 6 Nov 2011 20:42:34 +0200

 --z4ZopSbJjk0xfBpb
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sun, Nov 06, 2011 at 08:13:14PM +0200, Kostik Belousov wrote:
 > On Sun, Nov 06, 2011 at 12:21:29AM +0200, Mikolaj Golub wrote:
 > >=20
 > > On Sat, 5 Nov 2011 16:08:39 +0200 Kostik Belousov wrote:
 > >=20
 > >  KB> Please note that we grow the count of resources supported, e.g.
 > >  KB> we got RLIMIT_NPTS and RLIMIT_SWAP for 8.0. At least a comment near
 > >  KB> RLIM_NLIMITS to point anybody adding a new resource, to the kern.p=
 roc.rlimit
 > >  KB> handler, is useful.
 > >=20
 > > Does this look ok?
 > >=20
 > > http://people.freebsd.org/~trociny/resource.h.patch
 > No, it completely misses my point. You should request the person to handle
 > binary compatibility for sysctl, not for the array of names.
 > It should be done in the course of rlimit.patch.
 And you can already handle the future structure grow by doing the following:
 
 	size_t len;
 
 	len =3D req->oldlen;
 	if (sizeof(limp->pl_rlimit) < len)
 		return (EINVAL);
 	error =3D SYSCTL_OUT(req, limp->pl_rlimit, req->oldlen);
 >=20
 > >=20
 > > The update rlimit patch:
 > >=20
 > > http://people.freebsd.org/~trociny/rlimit.1.patch
 > I have no further comments.
 
 
 
 --z4ZopSbJjk0xfBpb
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (FreeBSD)
 
 iEYEARECAAYFAk621RoACgkQC3+MBN1Mb4iU7gCeLWHCiUWbqKkRRBl9vpl8VnFs
 4QgAoKhuRYBOUNzFxsWqzmsOkOYhuzuv
 =dN5n
 -----END PGP SIGNATURE-----
 
 --z4ZopSbJjk0xfBpb--

From: Mikolaj Golub <to.my.trociny@gmail.com>
To: Kostik Belousov <kostikbel@gmail.com>
Cc: John Baldwin <jhb@freebsd.org>,  bug-followup@freebsd.org,  Robert Watson <rwatson@freebsd.org>
Subject: Re: bin/161257: procstat(1): procstat should grow a -l flag to display resource limits
Date: Sun, 06 Nov 2011 22:44:43 +0200

 On Sun, 6 Nov 2011 20:42:34 +0200 Kostik Belousov wrote:
 
  KB> And you can already handle the future structure grow by doing the following:
 
  KB>         size_t len;
 
  KB>         len = req->oldlen;
  KB>         if (sizeof(limp->pl_rlimit) < len)
  KB>                 return (EINVAL);
  KB>         error = SYSCTL_OUT(req, limp->pl_rlimit, req->oldlen);
 
 Thank you. The updated patch:
 
 http://people.freebsd.org/~trociny/rlimit.2.patch
 
 -- 
 Mikolaj Golub

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161257: commit references a PR
Date: Thu, 24 Nov 2011 20:54:15 +0000 (UTC)

 Author: trociny
 Date: Thu Nov 24 20:54:06 2011
 New Revision: 227956
 URL: http://svn.freebsd.org/changeset/base/227956
 
 Log:
   usr.bin/procstat
   
   Add -l flag to display resource limits.
   
   PR:		bin/161257
   Reviewed by:	kib
   MFC after:	2 weeks
 
 Added:
   head/usr.bin/procstat/procstat_rlimit.c   (contents, props changed)
 Modified:
   head/usr.bin/procstat/Makefile
   head/usr.bin/procstat/procstat.1
   head/usr.bin/procstat/procstat.c
   head/usr.bin/procstat/procstat.h
 
 Modified: head/usr.bin/procstat/Makefile
 ==============================================================================
 --- head/usr.bin/procstat/Makefile	Thu Nov 24 20:43:37 2011	(r227955)
 +++ head/usr.bin/procstat/Makefile	Thu Nov 24 20:54:06 2011	(r227956)
 @@ -10,6 +10,7 @@ SRCS=	procstat.c		\
  	procstat_cred.c		\
  	procstat_files.c	\
  	procstat_kstack.c	\
 +	procstat_rlimit.c	\
  	procstat_sigs.c		\
  	procstat_threads.c	\
  	procstat_vm.c
 
 Modified: head/usr.bin/procstat/procstat.1
 ==============================================================================
 --- head/usr.bin/procstat/procstat.1	Thu Nov 24 20:43:37 2011	(r227955)
 +++ head/usr.bin/procstat/procstat.1	Thu Nov 24 20:54:06 2011	(r227956)
 @@ -25,7 +25,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd November 22, 2011
 +.Dd November 24, 2011
  .Dt PROCSTAT 1
  .Os
  .Sh NAME
 @@ -69,6 +69,8 @@ Display the stacks of kernel threads in 
  threads currently running on a CPU and threads with stacks swapped to disk.
  If the flag is repeated, function offsets as well as function names are
  printed.
 +.It Fl l
 +Display resource limits for the process.
  .It Fl s
  Display security credential information for the process.
  .It Fl t
 
 Modified: head/usr.bin/procstat/procstat.c
 ==============================================================================
 --- head/usr.bin/procstat/procstat.c	Thu Nov 24 20:43:37 2011	(r227955)
 +++ head/usr.bin/procstat/procstat.c	Thu Nov 24 20:54:06 2011	(r227956)
 @@ -39,8 +39,8 @@
  
  #include "procstat.h"
  
 -static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, sflag, tflag;
 -static int vflag, xflag;
 +static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, lflag, sflag;
 +static int tflag, vflag, xflag;
  int	hflag, nflag, Cflag;
  
  static void
 @@ -50,7 +50,7 @@ usage(void)
  	fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] "
  	    "[-w interval] \n");
  	fprintf(stderr, "                [-b | -c | -e | -f | -i | -j | -k | "
 -	    "-s | -t | -v | -x] [-a | pid ...]\n");
 +	    "-l | -s | -t | -v | -x] [-a | pid ...]\n");
  	exit(EX_USAGE);
  }
  
 @@ -72,6 +72,8 @@ procstat(struct procstat *prstat, struct
  		procstat_threads_sigs(prstat, kipp);
  	else if (kflag)
  		procstat_kstack(kipp, kflag);
 +	else if (lflag)
 +		procstat_rlimit(kipp);
  	else if (sflag)
  		procstat_cred(kipp);
  	else if (tflag)
 @@ -123,7 +125,7 @@ main(int argc, char *argv[])
  
  	interval = 0;
  	memf = nlistf = NULL;
 -	while ((ch = getopt(argc, argv, "CN:M:abcefijkhstvw:x")) != -1) {
 +	while ((ch = getopt(argc, argv, "CN:M:abcefijklhstvw:x")) != -1) {
  		switch (ch) {
  		case 'C':
  			Cflag++;
 @@ -167,6 +169,10 @@ main(int argc, char *argv[])
  			kflag++;
  			break;
  
 +		case 'l':
 +			lflag++;
 +			break;
 +
  		case 'n':
  			nflag++;
  			break;
 @@ -210,8 +216,8 @@ main(int argc, char *argv[])
  	argv += optind;
  
  	/* We require that either 0 or 1 mode flags be set. */
 -	tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + sflag + tflag +
 -	    vflag + xflag;
 +	tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + lflag + sflag +
 +	    tflag + vflag + xflag;
  	if (!(tmp == 0 || tmp == 1))
  		usage();
  
 
 Modified: head/usr.bin/procstat/procstat.h
 ==============================================================================
 --- head/usr.bin/procstat/procstat.h	Thu Nov 24 20:43:37 2011	(r227955)
 +++ head/usr.bin/procstat/procstat.h	Thu Nov 24 20:54:06 2011	(r227956)
 @@ -42,6 +42,7 @@ void	procstat_cred(struct kinfo_proc *ki
  void	procstat_env(struct kinfo_proc *kipp);
  void	procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_kstack(struct kinfo_proc *kipp, int kflag);
 +void	procstat_rlimit(struct kinfo_proc *kipp);
  void	procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_threads(struct kinfo_proc *kipp);
  void	procstat_threads_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
 
 Added: head/usr.bin/procstat/procstat_rlimit.c
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/usr.bin/procstat/procstat_rlimit.c	Thu Nov 24 20:54:06 2011	(r227956)
 @@ -0,0 +1,78 @@
 +/*-
 + * Copyright (c) 2011 Mikolaj Golub
 + * All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 + * SUCH DAMAGE.
 + *
 + * $FreeBSD$
 + */
 +
 +#include <sys/param.h>
 +#include <sys/time.h>
 +#define _RLIMIT_IDENT
 +#include <sys/resourcevar.h>
 +#include <sys/sysctl.h>
 +#include <sys/user.h>
 +
 +#include <err.h>
 +#include <errno.h>
 +#include <libprocstat.h>
 +#include <limits.h>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
 +#include "procstat.h"
 +
 +static struct rlimit rlimit[RLIM_NLIMITS];
 +
 +void
 +procstat_rlimit(struct kinfo_proc *kipp)
 +{
 +	int error, i, name[4];
 +	size_t len;
 +
 +	if (!hflag)
 +		printf("%5s %-16s %-10s %12s %12s\n", "PID", "COMM", "RLIMIT",
 +		    "CURRENT", "MAX");
 +	name[0] = CTL_KERN;
 +	name[1] = KERN_PROC;
 +	name[2] = KERN_PROC_RLIMIT;
 +	name[3] = kipp->ki_pid;
 +	len = sizeof(rlimit);
 +	error = sysctl(name, 4, rlimit, &len, NULL, 0);
 +	if (error < 0 && errno != ESRCH) {
 +		warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
 +		return;
 +	}
 +	if (error < 0 || len != sizeof(rlimit))
 +		return;
 +
 +	for (i = 0; i < RLIM_NLIMITS; i++) {
 +		printf("%5d %-16s %-10s %12jd %12jd\n", kipp->ki_pid,
 +		    kipp->ki_comm, rlimit_ident[i],
 +		    rlimit[i].rlim_cur == RLIM_INFINITY ?
 +		    -1 : rlimit[i].rlim_cur,
 +		    rlimit[i].rlim_max == RLIM_INFINITY ?
 +		    -1 : rlimit[i].rlim_max);
 +        }
 +}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161257: commit references a PR
Date: Thu,  2 Feb 2012 18:22:40 +0000 (UTC)

 Author: trociny
 Date: Thu Feb  2 18:22:25 2012
 New Revision: 230918
 URL: http://svn.freebsd.org/changeset/base/230918
 
 Log:
   MFC r227956, r228090, r228446, r230471, r230548:
   
   r227956:
   
   Add -l flag to display resource limits.
   
   PR:		bin/161257
   Reviewed by:	kib
   
   r228090:
   
   Update SYNOPSIS to include the flags added recently.
   
   Spotted by:	jhb
   
   r228446:
   
   Make procstat -l output similar to the output of limits(1).
   
   Suggested by:	jhb
   
   r230471, r230548:
   
   Make procstat -l to work with the new version of kern.proc.rlimit.
   
   Submitted by:	Andrey Zonov <andrey at zonov.org>
 
 Added:
   stable/9/usr.bin/procstat/procstat_rlimit.c
      - copied, changed from r227956, head/usr.bin/procstat/procstat_rlimit.c
 Modified:
   stable/9/usr.bin/procstat/Makefile
   stable/9/usr.bin/procstat/procstat.1
   stable/9/usr.bin/procstat/procstat.c
   stable/9/usr.bin/procstat/procstat.h
 Directory Properties:
   stable/9/usr.bin/procstat/   (props changed)
 
 Modified: stable/9/usr.bin/procstat/Makefile
 ==============================================================================
 --- stable/9/usr.bin/procstat/Makefile	Thu Feb  2 18:17:49 2012	(r230917)
 +++ stable/9/usr.bin/procstat/Makefile	Thu Feb  2 18:22:25 2012	(r230918)
 @@ -10,6 +10,7 @@ SRCS=	procstat.c		\
  	procstat_cred.c		\
  	procstat_files.c	\
  	procstat_kstack.c	\
 +	procstat_rlimit.c	\
  	procstat_sigs.c		\
  	procstat_threads.c	\
  	procstat_vm.c
 
 Modified: stable/9/usr.bin/procstat/procstat.1
 ==============================================================================
 --- stable/9/usr.bin/procstat/procstat.1	Thu Feb  2 18:17:49 2012	(r230917)
 +++ stable/9/usr.bin/procstat/procstat.1	Thu Feb  2 18:22:25 2012	(r230918)
 @@ -25,7 +25,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd November 22, 2011
 +.Dd November 28, 2011
  .Dt PROCSTAT 1
  .Os
  .Sh NAME
 @@ -37,7 +37,7 @@
  .Op Fl n
  .Op Fl C
  .Op Fl w Ar interval
 -.Op Fl b | c | f | i | j | k | s | t | v
 +.Op Fl b | c | e | f | i | j | k | l | s | t | v | x
  .Op Fl a | Ar pid ...
  .Sh DESCRIPTION
  The
 @@ -69,6 +69,8 @@ Display the stacks of kernel threads in 
  threads currently running on a CPU and threads with stacks swapped to disk.
  If the flag is repeated, function offsets as well as function names are
  printed.
 +.It Fl l
 +Display resource limits for the process.
  .It Fl s
  Display security credential information for the process.
  .It Fl t
 
 Modified: stable/9/usr.bin/procstat/procstat.c
 ==============================================================================
 --- stable/9/usr.bin/procstat/procstat.c	Thu Feb  2 18:17:49 2012	(r230917)
 +++ stable/9/usr.bin/procstat/procstat.c	Thu Feb  2 18:22:25 2012	(r230918)
 @@ -39,8 +39,8 @@
  
  #include "procstat.h"
  
 -static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, sflag, tflag;
 -static int vflag, xflag;
 +static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, lflag, sflag;
 +static int tflag, vflag, xflag;
  int	hflag, nflag, Cflag;
  
  static void
 @@ -50,7 +50,7 @@ usage(void)
  	fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] "
  	    "[-w interval] \n");
  	fprintf(stderr, "                [-b | -c | -e | -f | -i | -j | -k | "
 -	    "-s | -t | -v | -x] [-a | pid ...]\n");
 +	    "-l | -s | -t | -v | -x] [-a | pid ...]\n");
  	exit(EX_USAGE);
  }
  
 @@ -72,6 +72,8 @@ procstat(struct procstat *prstat, struct
  		procstat_threads_sigs(prstat, kipp);
  	else if (kflag)
  		procstat_kstack(kipp, kflag);
 +	else if (lflag)
 +		procstat_rlimit(kipp);
  	else if (sflag)
  		procstat_cred(kipp);
  	else if (tflag)
 @@ -123,7 +125,7 @@ main(int argc, char *argv[])
  
  	interval = 0;
  	memf = nlistf = NULL;
 -	while ((ch = getopt(argc, argv, "CN:M:abcefijkhstvw:x")) != -1) {
 +	while ((ch = getopt(argc, argv, "CN:M:abcefijklhstvw:x")) != -1) {
  		switch (ch) {
  		case 'C':
  			Cflag++;
 @@ -167,6 +169,10 @@ main(int argc, char *argv[])
  			kflag++;
  			break;
  
 +		case 'l':
 +			lflag++;
 +			break;
 +
  		case 'n':
  			nflag++;
  			break;
 @@ -210,8 +216,8 @@ main(int argc, char *argv[])
  	argv += optind;
  
  	/* We require that either 0 or 1 mode flags be set. */
 -	tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + sflag + tflag +
 -	    vflag + xflag;
 +	tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + lflag + sflag +
 +	    tflag + vflag + xflag;
  	if (!(tmp == 0 || tmp == 1))
  		usage();
  
 
 Modified: stable/9/usr.bin/procstat/procstat.h
 ==============================================================================
 --- stable/9/usr.bin/procstat/procstat.h	Thu Feb  2 18:17:49 2012	(r230917)
 +++ stable/9/usr.bin/procstat/procstat.h	Thu Feb  2 18:22:25 2012	(r230918)
 @@ -42,6 +42,7 @@ void	procstat_cred(struct kinfo_proc *ki
  void	procstat_env(struct kinfo_proc *kipp);
  void	procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_kstack(struct kinfo_proc *kipp, int kflag);
 +void	procstat_rlimit(struct kinfo_proc *kipp);
  void	procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
  void	procstat_threads(struct kinfo_proc *kipp);
  void	procstat_threads_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
 
 Copied and modified: stable/9/usr.bin/procstat/procstat_rlimit.c (from r227956, head/usr.bin/procstat/procstat_rlimit.c)
 ==============================================================================
 --- head/usr.bin/procstat/procstat_rlimit.c	Thu Nov 24 20:54:06 2011	(r227956, copy source)
 +++ stable/9/usr.bin/procstat/procstat_rlimit.c	Thu Feb  2 18:22:25 2012	(r230918)
 @@ -28,7 +28,6 @@
  
  #include <sys/param.h>
  #include <sys/time.h>
 -#define _RLIMIT_IDENT
  #include <sys/resourcevar.h>
  #include <sys/sysctl.h>
  #include <sys/user.h>
 @@ -36,6 +35,7 @@
  #include <err.h>
  #include <errno.h>
  #include <libprocstat.h>
 +#include <libutil.h>
  #include <limits.h>
  #include <stdio.h>
  #include <stdlib.h>
 @@ -43,36 +43,77 @@
  
  #include "procstat.h"
  
 -static struct rlimit rlimit[RLIM_NLIMITS];
 +static struct {
 +	const char *name;
 +	const char *suffix;
 +} rlimit_param[13] = {
 +	{"cputime",          "sec"},
 +	{"filesize",         "B  "},
 +	{"datasize",         "B  "},
 +	{"stacksize",        "B  "},
 +	{"coredumpsize",     "B  "},
 +	{"memoryuse",        "B  "},
 +	{"memorylocked",     "B  "},
 +	{"maxprocesses",     "   "},
 +	{"openfiles",        "   "},
 +	{"sbsize",           "B  "},
 +	{"vmemoryuse",       "B  "},
 +	{"pseudo-terminals", "   "},
 +	{"swapuse",          "B  "},
 +};
 +
 +#if RLIM_NLIMITS > 13
 +#error "Resource limits have grown. Add new entries to rlimit_param[]."
 +#endif
 +
 +static
 +const char *humanize_rlimit(int indx, rlim_t limit)
 +{
 +	static char buf[14];
 +	int scale;
 +
 +	if (limit == RLIM_INFINITY)
 +		return ("infinity     ");
 +
 +	scale = humanize_number(buf, sizeof(buf) - 1, (int64_t)limit,
 +	    rlimit_param[indx].suffix, HN_AUTOSCALE | HN_GETSCALE, HN_DECIMAL);
 +	(void)humanize_number(buf, sizeof(buf) - 1, (int64_t)limit,
 +	    rlimit_param[indx].suffix, HN_AUTOSCALE, HN_DECIMAL);
 +	/* Pad with one space if there is no suffix prefix. */
 +	if (scale == 0)
 +		sprintf(buf + strlen(buf), " ");
 +	return (buf);
 +}
  
  void
  procstat_rlimit(struct kinfo_proc *kipp)
  {
 -	int error, i, name[4];
 +	struct rlimit rlimit;
 +	int error, i, name[5];
  	size_t len;
  
 -	if (!hflag)
 -		printf("%5s %-16s %-10s %12s %12s\n", "PID", "COMM", "RLIMIT",
 -		    "CURRENT", "MAX");
 +	if (!hflag) {
 +		printf("%5s %-16s %-16s %16s %16s\n",
 +		    "PID", "COMM", "RLIMIT", "SOFT     ", "HARD     ");
 +	}
 +	len = sizeof(struct rlimit);
  	name[0] = CTL_KERN;
  	name[1] = KERN_PROC;
  	name[2] = KERN_PROC_RLIMIT;
  	name[3] = kipp->ki_pid;
 -	len = sizeof(rlimit);
 -	error = sysctl(name, 4, rlimit, &len, NULL, 0);
 -	if (error < 0 && errno != ESRCH) {
 -		warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
 -		return;
 -	}
 -	if (error < 0 || len != sizeof(rlimit))
 -		return;
 -
  	for (i = 0; i < RLIM_NLIMITS; i++) {
 -		printf("%5d %-16s %-10s %12jd %12jd\n", kipp->ki_pid,
 -		    kipp->ki_comm, rlimit_ident[i],
 -		    rlimit[i].rlim_cur == RLIM_INFINITY ?
 -		    -1 : rlimit[i].rlim_cur,
 -		    rlimit[i].rlim_max == RLIM_INFINITY ?
 -		    -1 : rlimit[i].rlim_max);
 -        }
 +		name[4] = i;
 +		error = sysctl(name, 5, &rlimit, &len, NULL, 0);
 +		if (error < 0 && errno != ESRCH) {
 +			warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
 +			return;
 +		}
 +		if (error < 0 || len != sizeof(struct rlimit))
 +			return;
 +
 +		printf("%5d %-16s %-16s ", kipp->ki_pid, kipp->ki_comm,
 +		    rlimit_param[i].name);
 +		printf("%16s ", humanize_rlimit(i, rlimit.rlim_cur));
 +		printf("%16s\n", humanize_rlimit(i, rlimit.rlim_max));
 +	}
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: antoine 
State-Changed-When: Wed May 15 16:56:33 UTC 2013 
State-Changed-Why:  
Close: as noted in the audit-trail, the feature has been implemented 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161257 
>Unformatted:
