mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-11 17:04:19 +01:00
ulimit(3): simplify.
rlim_t is at least as large as long, so we don't need the extra variable to keep the intermediate step. We don't need the volatile either. The code was tested on i386 and amd64. Suggested by: bde X-MFC with: r278803
This commit is contained in:
parent
71a0c925ce
commit
d2f783303b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=278905
@ -33,7 +33,6 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <ulimit.h>
|
||||
|
||||
long
|
||||
@ -41,8 +40,7 @@ ulimit(int cmd, ...)
|
||||
{
|
||||
struct rlimit limit;
|
||||
va_list ap;
|
||||
volatile intmax_t targ;
|
||||
long arg;
|
||||
rlim_t arg;
|
||||
|
||||
if (cmd == UL_GETFSIZE) {
|
||||
if (getrlimit(RLIMIT_FSIZE, &limit) == -1)
|
||||
@ -53,18 +51,18 @@ ulimit(int cmd, ...)
|
||||
return ((long)limit.rlim_cur);
|
||||
} else if (cmd == UL_SETFSIZE) {
|
||||
va_start(ap, cmd);
|
||||
targ = arg = va_arg(ap, long);
|
||||
arg = va_arg(ap, long);
|
||||
va_end(ap);
|
||||
if (targ < 0)
|
||||
targ = LONG_MAX;
|
||||
if (targ > RLIM_INFINITY / 512)
|
||||
targ = RLIM_INFINITY / 512;
|
||||
limit.rlim_max = limit.rlim_cur = targ * 512;
|
||||
if (arg < 0)
|
||||
arg = LONG_MAX;
|
||||
if (arg > RLIM_INFINITY / 512)
|
||||
arg = RLIM_INFINITY / 512;
|
||||
limit.rlim_max = limit.rlim_cur = arg * 512;
|
||||
|
||||
/* The setrlimit() function sets errno to EPERM if needed. */
|
||||
if (setrlimit(RLIMIT_FSIZE, &limit) == -1)
|
||||
return (-1);
|
||||
return ((long)targ);
|
||||
return ((long)arg);
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
|
Loading…
Reference in New Issue
Block a user