procfs_rlimit.c revision 87321
146201Sphk/* 246201Sphk * Copyright (c) 1999 Adrian Chadd 346201Sphk * Copyright (c) 1993 446201Sphk * The Regents of the University of California. All rights reserved. 546201Sphk * 646201Sphk * This code is derived from software contributed to Berkeley by 746201Sphk * Jan-Simon Pendry. 846201Sphk * 946201Sphk * Redistribution and use in source and binary forms, with or without 1046201Sphk * modification, are permitted provided that the following conditions 1146201Sphk * are met: 1246201Sphk * 1. Redistributions of source code must retain the above copyright 1346201Sphk * notice, this list of conditions and the following disclaimer. 1446201Sphk * 2. Redistributions in binary form must reproduce the above copyright 1546201Sphk * notice, this list of conditions and the following disclaimer in the 1646201Sphk * documentation and/or other materials provided with the distribution. 1746201Sphk * 3. All advertising materials mentioning features or use of this software 1846201Sphk * must display the following acknowledgement: 1946201Sphk * This product includes software developed by the University of 2046201Sphk * California, Berkeley and its contributors. 2146201Sphk * 4. Neither the name of the University nor the names of its contributors 2246201Sphk * may be used to endorse or promote products derived from this software 2346201Sphk * without specific prior written permission. 2446201Sphk * 2546201Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2646201Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2746201Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2846201Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2946201Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3046201Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3146201Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3246201Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3346201Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3446201Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3546201Sphk * SUCH DAMAGE. 3646201Sphk * 3746201Sphk * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 3846201Sphk * 3950477Speter * $FreeBSD: head/sys/fs/procfs/procfs_rlimit.c 87321 2001-12-04 01:35:06Z des $ 4046201Sphk */ 4146201Sphk 4246201Sphk/* 4346201Sphk * To get resource.h to include our rlimit_ident[] array of rlimit identifiers 4446201Sphk */ 4546201Sphk 4646201Sphk#define _RLIMIT_IDENT 4746201Sphk 4846201Sphk#include <sys/param.h> 4946201Sphk#include <sys/systm.h> 5046201Sphk#include <sys/proc.h> 5146201Sphk#include <sys/resourcevar.h> 5246201Sphk#include <sys/resource.h> 5387321Sdes#include <sys/sbuf.h> 5487321Sdes 5587321Sdes#include <fs/pseudofs/pseudofs.h> 5677031Sru#include <fs/procfs/procfs.h> 5746201Sphk 5846201Sphk 5946201Sphkint 6087321Sdesprocfs_doprocrlimit(PFS_FILL_ARGS) 6146201Sphk{ 6246201Sphk int i; 6346201Sphk 6446201Sphk for (i = 0; i < RLIM_NLIMITS; i++) { 6546201Sphk 6646201Sphk /* 6746201Sphk * Add the rlimit ident 6846201Sphk */ 6946201Sphk 7087321Sdes sbuf_printf(sb, "%s ", rlimit_ident[i]); 7146201Sphk 7246201Sphk /* 7346201Sphk * Replace RLIM_INFINITY with -1 in the string 7446201Sphk */ 7546201Sphk 7646201Sphk /* 7746201Sphk * current limit 7846201Sphk */ 7946201Sphk 8046201Sphk if (p->p_rlimit[i].rlim_cur == RLIM_INFINITY) { 8187321Sdes sbuf_printf(sb, "-1 "); 8246201Sphk } else { 8387321Sdes sbuf_printf(sb, "%llu ", 8448715Speter (unsigned long long)p->p_rlimit[i].rlim_cur); 8546201Sphk } 8646201Sphk 8746201Sphk /* 8846201Sphk * maximum limit 8946201Sphk */ 9046201Sphk 9146201Sphk if (p->p_rlimit[i].rlim_max == RLIM_INFINITY) { 9287321Sdes sbuf_printf(sb, "-1\n"); 9346201Sphk } else { 9487321Sdes sbuf_printf(sb, "%llu\n", 9548715Speter (unsigned long long)p->p_rlimit[i].rlim_max); 9646201Sphk } 9746201Sphk } 9846201Sphk 9987321Sdes return (0); 10046201Sphk} 10146201Sphk 102