aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-23 12:41:58 +0000
committerRon Yorston <rmy@pobox.com>2012-03-23 12:41:58 +0000
commit802674045737c916203521043905526b5c851c92 (patch)
tree7057aa4b055bb0acb1f9cb81cd1aaf96d65afc1b
parentb0f54743e36af163ae2530c381c485bb29df13dc (diff)
downloadbusybox-w32-802674045737c916203521043905526b5c851c92.tar.gz
busybox-w32-802674045737c916203521043905526b5c851c92.tar.bz2
busybox-w32-802674045737c916203521043905526b5c851c92.zip
Remove unused file builtin_ulimit.c
-rw-r--r--shell/builtin_ulimit.c237
1 files changed, 0 insertions, 237 deletions
diff --git a/shell/builtin_ulimit.c b/shell/builtin_ulimit.c
deleted file mode 100644
index 7ef17b1b0..000000000
--- a/shell/builtin_ulimit.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * ulimit builtin
4 *
5 * Adapted from ash applet code
6 *
7 * This code, originally by Doug Gwyn, Doug Kingston, Eric Gisin, and
8 * Michael Rendell was ripped from pdksh 5.0.8 and hacked for use with
9 * ash by J.T. Conklin.
10 *
11 * Public domain.
12 *
13 * Copyright (c) 2010 Tobias Klauser
14 * Split from ash.c and slightly adapted.
15 *
16 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
17 */
18#include "libbb.h"
19
20#if ENABLE_PLATFORM_MINGW32
21int FAST_FUNC shell_builtin_ulimit(char **argv)
22{
23 return 1;
24}
25#else
26
27#include "builtin_ulimit.h"
28
29
30struct limits {
31 uint8_t cmd; /* RLIMIT_xxx fit into it */
32 uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */
33 char option;
34 const char *name;
35};
36
37static const struct limits limits_tbl[] = {
38#ifdef RLIMIT_FSIZE
39 { RLIMIT_FSIZE, 9, 'f', "file size (blocks)" },
40#endif
41#ifdef RLIMIT_CPU
42 { RLIMIT_CPU, 0, 't', "cpu time (seconds)" },
43#endif
44#ifdef RLIMIT_DATA
45 { RLIMIT_DATA, 10, 'd', "data seg size (kb)" },
46#endif
47#ifdef RLIMIT_STACK
48 { RLIMIT_STACK, 10, 's', "stack size (kb)" },
49#endif
50#ifdef RLIMIT_CORE
51 { RLIMIT_CORE, 9, 'c', "core file size (blocks)" },
52#endif
53#ifdef RLIMIT_RSS
54 { RLIMIT_RSS, 10, 'm', "resident set size (kb)" },
55#endif
56#ifdef RLIMIT_MEMLOCK
57 { RLIMIT_MEMLOCK, 10, 'l', "locked memory (kb)" },
58#endif
59#ifdef RLIMIT_NPROC
60 { RLIMIT_NPROC, 0, 'p', "processes" },
61#endif
62#ifdef RLIMIT_NOFILE
63 { RLIMIT_NOFILE, 0, 'n', "file descriptors" },
64#endif
65#ifdef RLIMIT_AS
66 { RLIMIT_AS, 10, 'v', "address space (kb)" },
67#endif
68#ifdef RLIMIT_LOCKS
69 { RLIMIT_LOCKS, 0, 'w', "locks" },
70#endif
71};
72
73enum {
74 OPT_hard = (1 << 0),
75 OPT_soft = (1 << 1),
76};
77
78/* "-": treat args as parameters of option with ASCII code 1 */
79static const char ulimit_opt_string[] = "-HSa"
80#ifdef RLIMIT_FSIZE
81 "f::"
82#endif
83#ifdef RLIMIT_CPU
84 "t::"
85#endif
86#ifdef RLIMIT_DATA
87 "d::"
88#endif
89#ifdef RLIMIT_STACK
90 "s::"
91#endif
92#ifdef RLIMIT_CORE
93 "c::"
94#endif
95#ifdef RLIMIT_RSS
96 "m::"
97#endif
98#ifdef RLIMIT_MEMLOCK
99 "l::"
100#endif
101#ifdef RLIMIT_NPROC
102 "p::"
103#endif
104#ifdef RLIMIT_NOFILE
105 "n::"
106#endif
107#ifdef RLIMIT_AS
108 "v::"
109#endif
110#ifdef RLIMIT_LOCKS
111 "w::"
112#endif
113 ;
114
115static void printlim(unsigned opts, const struct rlimit *limit,
116 const struct limits *l)
117{
118 rlim_t val;
119
120 val = limit->rlim_max;
121 if (!(opts & OPT_hard))
122 val = limit->rlim_cur;
123
124 if (val == RLIM_INFINITY)
125 printf("unlimited\n");
126 else {
127 val >>= l->factor_shift;
128 printf("%llu\n", (long long) val);
129 }
130}
131
132int FAST_FUNC shell_builtin_ulimit(char **argv)
133{
134 unsigned opts;
135 unsigned argc;
136
137 /* We can't use getopt32: need to handle commands like
138 * ulimit 123 -c2 -l 456
139 */
140
141 /* In case getopt was already called:
142 * reset the libc getopt() function, which keeps internal state.
143 */
144#ifdef __GLIBC__
145 optind = 0;
146#else /* BSD style */
147 optind = 1;
148 /* optreset = 1; */
149#endif
150 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
151
152 argc = 1;
153 while (argv[argc])
154 argc++;
155
156 opts = 0;
157 while (1) {
158 struct rlimit limit;
159 const struct limits *l;
160 int opt_char = getopt(argc, argv, ulimit_opt_string);
161
162 if (opt_char == -1)
163 break;
164 if (opt_char == 'H') {
165 opts |= OPT_hard;
166 continue;
167 }
168 if (opt_char == 'S') {
169 opts |= OPT_soft;
170 continue;
171 }
172
173 if (opt_char == 'a') {
174 for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE(limits_tbl)]; l++) {
175 getrlimit(l->cmd, &limit);
176 printf("-%c: %-30s ", l->option, l->name);
177 printlim(opts, &limit, l);
178 }
179 continue;
180 }
181
182 if (opt_char == 1)
183 opt_char = 'f';
184 for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE(limits_tbl)]; l++) {
185 if (opt_char == l->option) {
186 char *val_str;
187
188 getrlimit(l->cmd, &limit);
189
190 val_str = optarg;
191 if (!val_str && argv[optind] && argv[optind][0] != '-')
192 val_str = argv[optind++]; /* ++ skips NN in "-c NN" case */
193 if (val_str) {
194 rlim_t val;
195
196 if (strcmp(val_str, "unlimited") == 0)
197 val = RLIM_INFINITY;
198 else {
199 if (sizeof(val) == sizeof(int))
200 val = bb_strtou(val_str, NULL, 10);
201 else if (sizeof(val) == sizeof(long))
202 val = bb_strtoul(val_str, NULL, 10);
203 else
204 val = bb_strtoull(val_str, NULL, 10);
205 if (errno) {
206 bb_error_msg("bad number");
207 return EXIT_FAILURE;
208 }
209 val <<= l->factor_shift;
210 }
211//bb_error_msg("opt %c val_str:'%s' val:%lld", opt_char, val_str, (long long)val);
212 if (opts & OPT_hard)
213 limit.rlim_max = val;
214 if ((opts & OPT_soft) || opts == 0)
215 limit.rlim_cur = val;
216//bb_error_msg("setrlimit(%d, %lld, %lld)", l->cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max);
217 if (setrlimit(l->cmd, &limit) < 0) {
218 bb_perror_msg("error setting limit");
219 return EXIT_FAILURE;
220 }
221 } else {
222 printlim(opts, &limit, l);
223 }
224 break;
225 }
226 } /* for (every possible opt) */
227
228 if (l == &limits_tbl[ARRAY_SIZE(limits_tbl)]) {
229 /* bad option. getopt already complained. */
230 break;
231 }
232
233 } /* while (there are options) */
234
235 return 0;
236}
237#endif