mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
conf: Make rlimit [hard|soft] optional => possible to set both
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+11
-8
@@ -51,15 +51,15 @@ Syntax
|
||||
* `network <PATH>`
|
||||
Script or program to bring up networking, with optional arguments
|
||||
|
||||
* `rlimit <hard|soft> RESOURCE <LIMIT|unlimited>`
|
||||
Set the hard or soft limit for a resource. `RESOURCE` is a lower-case
|
||||
string matching the `RLIMIT_` constants from `setrlimit(2)`, without
|
||||
the prefix. E.g. to set `RLIMIT_CPU`, use `cpu`.
|
||||
* `rlimit [hard|soft] RESOURCE <LIMIT|unlimited>` Set the hard or soft
|
||||
limit for a resource, or both if that argument is omitted. `RESOURCE`
|
||||
is the lower-case `RLIMIT_` string constants from `setrlimit(2)`,
|
||||
without the prefix. E.g. to set `RLIMIT_CPU`, use `cpu`.
|
||||
|
||||
The limit is an integer that depends on the resource being modified,
|
||||
see the man page, or the kernel `/proc/PID/limits` file, for more
|
||||
information. Finit versions before v3.1 used `infinity` for
|
||||
`unlimited`, which is still a supported keyword.
|
||||
LIMIT is an integer that depends on the resource being modified, see
|
||||
the man page, or the kernel `/proc/PID/limits` file, for details.
|
||||
Finit versions before v3.1 used `infinity` for `unlimited`, which is
|
||||
still supported, albeit deprecated.
|
||||
|
||||
```shell
|
||||
# No process is allowed more than 8MB of address space
|
||||
@@ -67,6 +67,9 @@ Syntax
|
||||
|
||||
# Core dumps may be arbitrarily large
|
||||
rlimit soft core infinity
|
||||
|
||||
# CPU limit for all services, soft & hard = 10 sec
|
||||
rlimit cpu 10
|
||||
```
|
||||
|
||||
* `runlevel <N>`
|
||||
|
||||
+19
-13
@@ -221,11 +221,12 @@ char *lim2str(struct rlimit *rlim)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* First form: `rlimit <hard|soft> RESOURCE LIMIT` */
|
||||
void conf_parse_rlimit(char *line, struct rlimit arr[])
|
||||
{
|
||||
char *level, *limit, *val;
|
||||
int resource = -1;
|
||||
rlim_t cfg, *set;
|
||||
rlim_t cfg;
|
||||
|
||||
level = strtok(line, " \t");
|
||||
if (!level)
|
||||
@@ -235,21 +236,18 @@ void conf_parse_rlimit(char *line, struct rlimit arr[])
|
||||
if (!limit)
|
||||
goto error;
|
||||
|
||||
val = strtok(NULL, " \t");
|
||||
if (!val) {
|
||||
/* Second form: `rlimit RESOURCE LIMIT` */
|
||||
val = limit;
|
||||
limit = level;
|
||||
level = "both";
|
||||
}
|
||||
|
||||
resource = str2rlim(limit);
|
||||
if (resource < 0 || resource > RLIMIT_NLIMITS)
|
||||
goto error;
|
||||
|
||||
val = strtok(NULL, " \t");
|
||||
if (!val)
|
||||
goto error;
|
||||
|
||||
if (!strcmp(level, "soft"))
|
||||
set = &arr[resource].rlim_cur;
|
||||
else if (!strcmp(level, "hard"))
|
||||
set = &arr[resource].rlim_max;
|
||||
else
|
||||
goto error;
|
||||
|
||||
/* Official keyword from v3.1 is `unlimited`, from prlimit(1) */
|
||||
if (!strcmp(val, "unlimited") || !strcmp(val, "infinity")) {
|
||||
cfg = RLIM_INFINITY;
|
||||
@@ -264,7 +262,15 @@ void conf_parse_rlimit(char *line, struct rlimit arr[])
|
||||
}
|
||||
}
|
||||
|
||||
*set = cfg;
|
||||
if (!strcmp(level, "soft"))
|
||||
arr[resource].rlim_cur = cfg;
|
||||
else if (!strcmp(level, "hard"))
|
||||
arr[resource].rlim_max = cfg;
|
||||
else if (!strcmp(level, "both"))
|
||||
arr[resource].rlim_max = arr[resource].rlim_cur = cfg;
|
||||
else
|
||||
goto error;
|
||||
|
||||
return;
|
||||
error:
|
||||
logit(LOG_WARNING, "rlimit: parse error");
|
||||
|
||||
Reference in New Issue
Block a user