Blame hurd/hurdrlimit.c

Packit 6c4009
/* Resource limits.
Packit 6c4009
   Copyright (C) 1994-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <hurd.h>
Packit 6c4009
#include <cthreads.h>
Packit 6c4009
#include <hurd/resource.h>
Packit 6c4009
Packit 6c4009
/* This must be given an initializer, or the a.out linking rules will
Packit 6c4009
   not include the entire file when this symbol is referenced. */
Packit 6c4009
struct rlimit _hurd_rlimits[RLIM_NLIMITS] = { { 0, }, };
Packit 6c4009
Packit 6c4009
/* This must be initialized data for the same reason as above, but this is
Packit 6c4009
   intentionally initialized to a bogus value to emphasize the point that
Packit 6c4009
   mutex_init is still required below just in case of unexec.  */
Packit 6c4009
struct mutex _hurd_rlimit_lock = { SPIN_LOCK_INITIALIZER, };
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
init_rlimit (void)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
Packit 6c4009
  __mutex_init (&_hurd_rlimit_lock);
Packit 6c4009
Packit 6c4009
  for (i = 0; i < RLIM_NLIMITS; ++i)
Packit 6c4009
    {
Packit 6c4009
      if (_hurd_rlimits[i].rlim_max == 0)
Packit 6c4009
	_hurd_rlimits[i].rlim_max = RLIM_INFINITY;
Packit 6c4009
      if (_hurd_rlimits[i].rlim_cur == 0)
Packit 6c4009
#define I(lim, val) case RLIMIT_##lim: _hurd_rlimits[i].rlim_cur = (val); break
Packit 6c4009
	switch (i)
Packit 6c4009
	  {
Packit 6c4009
	    I (NOFILE, 1024);	/* Linux 2.2.12 uses this initial value.  */
Packit 6c4009
Packit 6c4009
	  default:
Packit 6c4009
	    _hurd_rlimits[i].rlim_cur = _hurd_rlimits[i].rlim_max;
Packit 6c4009
	    break;
Packit 6c4009
	  }
Packit 6c4009
#undef	I
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  (void) &init_rlimit;
Packit 6c4009
}
Packit 6c4009
text_set_element (_hurd_preinit_hook, init_rlimit);