(linenum→info "unix/slp.c:2238")

glibc/2.7/resource/tst-getrlimit.c

    1: #include <errno.h>
    2: #include <stdbool.h>
    3: #include <stdio.h>
    4: #include <sys/resource.h>
    5: 
    6: 
    7: static struct
    8: {
    9:   const char *name;
   10:   int resource;
   11:   bool required;
   12: } tests[] =
   13:   {
   14:     /* The following 7 limits are part of POSIX and must exist.  */
   15:     { "RLIMIT_CORE", RLIMIT_CORE, true },
   16:     { "RLIMIT_CPU", RLIMIT_CPU, true },
   17:     { "RLIMIT_DATA", RLIMIT_DATA, true },
   18:     { "RLIMIT_FSIZE", RLIMIT_FSIZE, true },
   19:     { "RLIMIT_NOFILE", RLIMIT_NOFILE, true },
   20:     { "RLIMIT_STACK", RLIMIT_STACK, true },
   21:     { "RLIMIT_AS", RLIMIT_AS, true },
   22:     /* The following are traditional Unix limits which are also
   23:        expected (by us).  */
   24:     { "RLIMIT_RSS", RLIMIT_RSS, true },
   25:     { "RLIMIT_NPROC", RLIMIT_NPROC, true },
   26:     /* The following are extensions.  */
   27: #ifdef RLIMIT_MEMLOCK
   28:     { "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK, false },
   29: #endif
   30: #ifdef RLIMIT_LOCKS
   31:     { "RLIMIT_LOCKS", RLIMIT_LOCKS, false },
   32: #endif
   33: #ifdef RLIMIT_SIGPENDING
   34:     { "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING, false },
   35: #endif
   36: #ifdef RLIMIT_MSGQUEUE
   37:     { "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE, false },
   38: #endif
   39: #ifdef RLIMIT_NICE
   40:     { "RLIMIT_NICE", RLIMIT_NICE, false },
   41: #endif
   42: #ifdef RLIMIT_RTPRIO
   43:     { "RLIMIT_RTPRIO", RLIMIT_RTPRIO, false },
   44: #endif
   45:   };
   46: #define ntests (sizeof (tests) / sizeof (tests[0]))
   47: 
   48: 
   49: static int
   50: do_test (void)
   51: {
   52:   int status = 0;
   53: 
   54:   for (int i = 0; i < ntests; ++i)
   55:     {
   56:       bool this_ok = true;
   57: 
   58:       struct rlimit r;
   59:       int res = getrlimit (tests[i].resource, &r);
   60:       if (res == -1)
   61:         {
   62:           if (errno == EINVAL)
   63:             {
   64:               if (tests[i].required)
   65:                 {
   66:                   printf ("limit %s expectedly not available for getrlimit\n",
   67:                           tests[i].name);
   68:                   status = 1;
   69:                   this_ok = false;
   70:                 }
   71:             }
   72:           else
   73:             {
   74:               printf ("getrlimit for %s returned unexpected error: %m\n",
   75:                       tests[i].name);
   76:               status = 1;
   77:               this_ok = false;
   78:             }
   79:         }
   80: 
   81:       struct rlimit64 r64;
   82:       res = getrlimit64 (tests[i].resource, &r64);
   83:       if (res == -1)
   84:         {
   85:           if (errno == EINVAL)
   86:             {
   87:               if (tests[i].required)
   88:                 {
   89:                   printf ("limit %s expectedly not available for getrlimit64"
   90:                           "\n", tests[i].name);
   91:                   status = 1;
   92:                   this_ok = false;
   93:                 }
   94:             }
   95:           else
   96:             {
   97:               printf ("getrlimit64 for %s returned unexpected error: %m\n",
   98:                       tests[i].name);
   99:               status = 1;
  100:               this_ok = false;
  101:             }
  102:         }
  103: 
  104:       if (this_ok)
  105:         printf ("limit %s OK\n", tests[i].name);
  106:     }
  107: 
  108:   return status;
  109: }
  110: 
  111: #define TEST_FUNCTION do_test ()
  112: #include "../test-skeleton.c"
Syntax (Markdown)