|
Packit Service |
82fcde |
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* This is generic in the sense that it will work with the BSD, SYSV,
|
|
Packit Service |
82fcde |
or stub versions of getrlimit. Separate versions could be written
|
|
Packit Service |
82fcde |
for efficiency, but it's probably not worth it. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <sys/vlimit.h>
|
|
Packit Service |
82fcde |
#include <sys/resource.h>
|
|
Packit Service |
82fcde |
#include <errno.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set the soft limit for RESOURCE to be VALUE.
|
|
Packit Service |
82fcde |
Returns 0 for success, -1 for failure. */
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
vlimit (enum __vlimit_resource resource, int value)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (resource >= LIM_CPU && resource <= LIM_MAXRSS)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* The rlimit codes happen to each be one less
|
|
Packit Service |
82fcde |
than the corresponding vlimit codes. */
|
|
Packit Service |
82fcde |
enum __rlimit_resource rlimit_res =
|
|
Packit Service |
82fcde |
(enum __rlimit_resource) ((int) resource - 1);
|
|
Packit Service |
82fcde |
struct rlimit lims;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (__getrlimit (rlimit_res, &lims) < 0)
|
|
Packit Service |
82fcde |
return -1;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
lims.rlim_cur = value;
|
|
Packit Service |
82fcde |
return __setrlimit (rlimit_res, &lims);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
__set_errno (EINVAL);
|
|
Packit Service |
82fcde |
return -1;
|
|
Packit Service |
82fcde |
}
|