procfs_rlimit.c revision 139776
1139776Simp/*- 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 139776 2005-01-06 18:10:42Z imp $ 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> 49125454Sjhb#include <sys/lock.h> 50125454Sjhb#include <sys/mutex.h> 5146201Sphk#include <sys/systm.h> 5246201Sphk#include <sys/proc.h> 5346201Sphk#include <sys/resourcevar.h> 5446201Sphk#include <sys/resource.h> 5587321Sdes#include <sys/sbuf.h> 56125454Sjhb#include <sys/types.h> 57125454Sjhb#include <sys/malloc.h> 5887321Sdes 5987321Sdes#include <fs/pseudofs/pseudofs.h> 6077031Sru#include <fs/procfs/procfs.h> 6146201Sphk 6246201Sphk 6346201Sphkint 6487321Sdesprocfs_doprocrlimit(PFS_FILL_ARGS) 6546201Sphk{ 66125454Sjhb struct plimit *limp; 6746201Sphk int i; 6846201Sphk 69125454Sjhb /* 70125454Sjhb * Obtain a private reference to resource limits 71125454Sjhb */ 72125454Sjhb 73125454Sjhb PROC_LOCK(p); 74125454Sjhb limp = lim_hold(p->p_limit); 75125454Sjhb PROC_UNLOCK(p); 76125454Sjhb 7746201Sphk for (i = 0; i < RLIM_NLIMITS; i++) { 7846201Sphk 7946201Sphk /* 8046201Sphk * Add the rlimit ident 8146201Sphk */ 8246201Sphk 8387321Sdes sbuf_printf(sb, "%s ", rlimit_ident[i]); 8446201Sphk 85123247Sdes /* 8646201Sphk * Replace RLIM_INFINITY with -1 in the string 8746201Sphk */ 8846201Sphk 8946201Sphk /* 9046201Sphk * current limit 9146201Sphk */ 9246201Sphk 93125454Sjhb if (limp->pl_rlimit[i].rlim_cur == RLIM_INFINITY) { 9487321Sdes sbuf_printf(sb, "-1 "); 9546201Sphk } else { 9687321Sdes sbuf_printf(sb, "%llu ", 97125454Sjhb (unsigned long long)limp->pl_rlimit[i].rlim_cur); 9846201Sphk } 9946201Sphk 10046201Sphk /* 10146201Sphk * maximum limit 10246201Sphk */ 10346201Sphk 104125454Sjhb if (limp->pl_rlimit[i].rlim_max == RLIM_INFINITY) { 10587321Sdes sbuf_printf(sb, "-1\n"); 10646201Sphk } else { 10787321Sdes sbuf_printf(sb, "%llu\n", 108125454Sjhb (unsigned long long)limp->pl_rlimit[i].rlim_max); 10946201Sphk } 11046201Sphk } 11146201Sphk 112125454Sjhb lim_free(limp); 11387321Sdes return (0); 11446201Sphk} 115