xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | /* Resource limits. |
| 2 | Copyright (C) 1994-2016 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <hurd.h> |
| 20 | #include <cthreads.h> |
| 21 | #include <hurd/resource.h> |
| 22 | |
| 23 | /* This must be given an initializer, or the a.out linking rules will |
| 24 | not include the entire file when this symbol is referenced. */ |
| 25 | struct rlimit _hurd_rlimits[RLIM_NLIMITS] = { { 0, }, }; |
| 26 | |
| 27 | /* This must be initialized data for the same reason as above, but this is |
| 28 | intentionally initialized to a bogus value to emphasize the point that |
| 29 | mutex_init is still required below just in case of unexec. */ |
| 30 | struct mutex _hurd_rlimit_lock = { SPIN_LOCK_INITIALIZER, }; |
| 31 | |
| 32 | static void |
| 33 | init_rlimit (void) |
| 34 | { |
| 35 | int i; |
| 36 | |
| 37 | __mutex_init (&_hurd_rlimit_lock); |
| 38 | |
| 39 | for (i = 0; i < RLIM_NLIMITS; ++i) |
| 40 | { |
| 41 | if (_hurd_rlimits[i].rlim_max == 0) |
| 42 | _hurd_rlimits[i].rlim_max = RLIM_INFINITY; |
| 43 | if (_hurd_rlimits[i].rlim_cur == 0) |
| 44 | #define I(lim, val) case RLIMIT_##lim: _hurd_rlimits[i].rlim_cur = (val); break |
| 45 | switch (i) |
| 46 | { |
| 47 | I (NOFILE, 1024); /* Linux 2.2.12 uses this initial value. */ |
| 48 | |
| 49 | default: |
| 50 | _hurd_rlimits[i].rlim_cur = _hurd_rlimits[i].rlim_max; |
| 51 | break; |
| 52 | } |
| 53 | #undef I |
| 54 | } |
| 55 | |
| 56 | (void) &init_rlimit; |
| 57 | } |
| 58 | text_set_element (_hurd_preinit_hook, init_rlimit); |