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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #include <sys/types.h>
31 #include <sys/resource.h>
46 #define ERR_SET_ULIMIT "unable to set ulimit to <%ld> blocks"
47 #define ERR_DO_ULIMIT "An attempt was made to create a file larger than " \
48 "ULIMIT. Source of fault is unknown."
49 #define ERR_SCRULIMIT "Script <%s> attempted to create a file exceeding " \
52 static char *script_name
= NULL
, *scr_error
= NULL
;
53 static struct rlimit ulimit
= {RLIM_INFINITY
, RLIM_INFINITY
};
54 static struct rlimit dblimit
= {RLIM_INFINITY
, RLIM_INFINITY
};
55 static int limit_is_set
= 0, fail_return
= 0;
57 void ulimit_quit(); /* XFSZ controlled signal handler. */
58 int clr_ulimit(); /* Clear the user supplied file size limit. */
59 void set_limit(); /* Called from installf to undo ulimit */
60 int set_ulimit(char *script
, char *err_msg
);
61 int assign_ulimit(char *fslimit
);
83 /* Clear out the limit to infinity. */
84 return (setrlimit(RLIMIT_FSIZE
, &dblimit
));
90 * This sets up the ULIMIT facility for the signal retrieval. This sets up
91 * the static pointers to the message constants for indicating where the
95 set_ulimit(char *script
, char *err_msg
)
100 (void) signal(SIGXFSZ
, ulimit_quit
);
103 script_name
= strdup(script
);
106 scr_error
= strdup(err_msg
);
109 n
= setrlimit(RLIMIT_FSIZE
, &ulimit
);
117 /* Validate ULIMIT and set accordingly. */
119 assign_ulimit(char *fslimit
)
124 if (fslimit
&& *fslimit
) {
125 /* fslimit must be a simple unsigned integer. */
127 if (!isdigit(fslimit
[cnt
]))
129 } while (fslimit
[++cnt
]);
131 limit
= atol(fslimit
);
133 ulimit
.rlim_cur
= (limit
* 512); /* fslimit is in blocks */
143 * This is the signal handler for ULIMIT.
153 setrlimit(RLIMIT_FSIZE
, &dblimit
);
154 signal(SIGXFSZ
, SIG_IGN
);
157 progerr(gettext(ERR_SCRULIMIT
), script_name
);
159 progerr("%s", scr_error
);
161 progerr(gettext(ERR_DO_ULIMIT
));