Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. #include <errno.h>
  3. #include <stddef.h>
  4. #include <unistd.h>
  5. #include <sys/resource.h>
  6. #include <libc/bss.h>
  7.  
  8. extern unsigned int _stklen;
  9. extern struct rlimit __libc_limits[];
  10.  
  11. static int rlimit_count = -1;
  12. struct rlimit __libc_limits[RLIM_NLIMITS];
  13.  
  14. static void
  15. __limits_initialize (void)
  16. {
  17.   int i;
  18.  
  19.   /* set hard limit */
  20.   __libc_limits[RLIMIT_CPU].rlim_max = RLIM_INFINITY;
  21.   __libc_limits[RLIMIT_FSIZE].rlim_max = RLIM_INFINITY;
  22.   __libc_limits[RLIMIT_DATA].rlim_max = RLIM_INFINITY;
  23.   __libc_limits[RLIMIT_STACK].rlim_max = (long) _stklen;
  24.   __libc_limits[RLIMIT_CORE].rlim_max = RLIM_INFINITY;
  25.   __libc_limits[RLIMIT_RSS].rlim_max = RLIM_INFINITY;
  26.   __libc_limits[RLIMIT_MEMLOCK].rlim_max = RLIM_INFINITY;
  27.   __libc_limits[RLIMIT_NPROC].rlim_max = RLIM_INFINITY;
  28.   __libc_limits[RLIMIT_NOFILE].rlim_max = sysconf (_SC_OPEN_MAX);
  29.  
  30.   /* copy all hard limit to soft limit */
  31.   for (i = 0; i < RLIM_NLIMITS; i++)
  32.     __libc_limits[i].rlim_cur = __libc_limits[i].rlim_max;
  33. }
  34.  
  35. int
  36. getrlimit (int rltype, struct rlimit *rlimitp)
  37. {
  38.   /* check argument range */
  39.   if (rltype < 0 || rltype >= RLIM_NLIMITS || rlimitp == NULL)
  40.     {
  41.       errno = EINVAL;
  42.       return -1;
  43.     }
  44.  
  45.   /* initialize */
  46.   if (rlimit_count != __bss_count)
  47.     {
  48.       rlimit_count = __bss_count;
  49.       __limits_initialize ();
  50.     }
  51.  
  52.   /* copy limit value */
  53.   *rlimitp = __libc_limits[rltype];
  54.  
  55.   return 0;
  56. }
  57.