rlimit-util.c revision d0a7c5f69207b6719bab94893035fc8f5f6f87cb
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <sys/resource.h>
#include "alloc-util.h"
#include "extract-word.h"
#include "formats-util.h"
#include "macro.h"
#include "missing.h"
#include "rlimit-util.h"
#include "string-table.h"
#include "time-util.h"
return 0;
return -errno;
/* So we failed to set the desired setrlimit, then let's try
* to get as close as we can */
return -errno;
return 0;
}
uint64_t u;
int r;
*ret = RLIM_INFINITY;
return 0;
}
/* setrlimit(2) suggests rlim_t is always 64bit on Linux. */
r = safe_atou64(val, &u);
if (r < 0)
return r;
if (u >= (uint64_t) RLIM_INFINITY)
return -ERANGE;
return 0;
}
uint64_t u;
int r;
*ret = RLIM_INFINITY;
return 0;
}
if (r < 0)
return r;
if (u >= (uint64_t) RLIM_INFINITY)
return -ERANGE;
return 0;
}
uint64_t u;
usec_t t;
int r;
*ret = RLIM_INFINITY;
return 0;
}
if (r < 0)
return r;
if (t == USEC_INFINITY) {
*ret = RLIM_INFINITY;
return 0;
}
if (u >= (uint64_t) RLIM_INFINITY)
return -ERANGE;
return 0;
}
usec_t t;
int r;
*ret = RLIM_INFINITY;
return 0;
}
if (r < 0)
return r;
if (t == USEC_INFINITY) {
*ret = RLIM_INFINITY;
return 0;
}
return 0;
}
};
if (resource < 0)
return -EINVAL;
if (resource >= _RLIMIT_MAX)
return -EINVAL;
}
int r;
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
if (r < 0)
return r;
if (r < 0)
return r;
return -EINVAL;
if (r == 0)
else {
if (r < 0)
return r;
return -EILSEQ;
}
};
return 0;
}
static const char* const rlimit_table[_RLIMIT_MAX] = {
[RLIMIT_CPU] = "LimitCPU",
[RLIMIT_FSIZE] = "LimitFSIZE",
[RLIMIT_DATA] = "LimitDATA",
[RLIMIT_STACK] = "LimitSTACK",
[RLIMIT_CORE] = "LimitCORE",
[RLIMIT_RSS] = "LimitRSS",
[RLIMIT_NOFILE] = "LimitNOFILE",
[RLIMIT_AS] = "LimitAS",
[RLIMIT_NPROC] = "LimitNPROC",
[RLIMIT_MEMLOCK] = "LimitMEMLOCK",
[RLIMIT_LOCKS] = "LimitLOCKS",
[RLIMIT_SIGPENDING] = "LimitSIGPENDING",
[RLIMIT_MSGQUEUE] = "LimitMSGQUEUE",
[RLIMIT_NICE] = "LimitNICE",
[RLIMIT_RTPRIO] = "LimitRTPRIO",
[RLIMIT_RTTIME] = "LimitRTTIME"
};
DEFINE_STRING_TABLE_LOOKUP(rlimit, int);