Home | History | Annotate | Download | only in diskomizer
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"@(#)limit.c	1.7	09/05/26 SMI"
     28 
     29 #include <sys/resource.h>
     30 #include "limit.h"
     31 #include "args.h"
     32 #include <diskomizer/log.h>
     33 
     34 void
     35 set_limits(void)
     36 {
     37 	struct rlimit rl;
     38 
     39 	if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
     40 		pperror("getrlimit(RLIMIT_NOFILE, &rl)");
     41 		return;
     42 	}
     43 	rl.rlim_cur = rl.rlim_max;
     44 	if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
     45 		pperror("setrlimit(RLIMIT_NOFILE, max = %ld, cur %ld)",
     46 		    rl.rlim_max, rl.rlim_cur);
     47 	}
     48 	if (!opts.debug_allow_coredump) {
     49 		if (getrlimit(RLIMIT_CORE, &rl) == -1) {
     50 			pperror("getrlimit(RLIMIT_CORE, &rl)");
     51 			return;
     52 		}
     53 		rl.rlim_cur = 0;
     54 		if (setrlimit(RLIMIT_CORE, &rl) == -1) {
     55 			pperror("setrlimit(RLIMIT_CORE, max = %ld, cur %ld)",
     56 			    rl.rlim_max, rl.rlim_cur);
     57 		}
     58 	}
     59 }
     60