rlimit-util.c revision 8b43440b7ef4b81c69c31de7ff820dc07a780254
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering This file is part of systemd.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering Copyright 2010 Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering (at your option) any later version.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering systemd is distributed in the hope that it will be useful, but
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering Lesser General Public License for more details.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringint setrlimit_closest(int resource, const struct rlimit *rlim) {
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek /* So we failed to set the desired setrlimit, then let's try
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering * to get as close as we can */
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_se(getrlimit(resource, &highest) == 0);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering fixed.rlim_cur = MIN(rlim->rlim_cur, highest.rlim_max);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering fixed.rlim_max = MIN(rlim->rlim_max, highest.rlim_max);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringstatic const char* const rlimit_table[_RLIMIT_MAX] = {
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek [RLIMIT_RTPRIO] = "LimitRTPRIO",