File: prlimit.c

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (56 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* COVERAGE: prlimit64 */

// Why wasn't this testing just added to getrlimit.c? If you want to
// call prlimit(), you have to have _FILE_OFFSET_BITS defined as
// 64. But, when you do that, glibc redefines calls to
// getrlimit()/setrlimit() as prlimit64() calls. So, we'll have to
// test them separately.

#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <features.h>

int main()
{
// glibc support for prlimit() was added in glibc 2.13.
#if __GLIBC_PREREQ(2, 13)
    struct rlimit rlim;

    // Get current cpu limits.
    prlimit(0, RLIMIT_CPU, NULL, &rlim);
    //staptest// prlimit64 (0, RLIMIT_CPU, NULL, XXXX) = 0

    // Set new limits (to the same thing).
    prlimit(0, RLIMIT_CPU, &rlim, NULL);
    //staptest// prlimit64 (0, RLIMIT_CPU, \[NNNN,NNNN\], 0x0) = 0

    // Limit testing.

    prlimit(-1, RLIMIT_CPU, &rlim, NULL);
    //staptest// prlimit64 (-1, RLIMIT_CPU, \[NNNN,NNNN\], 0x0) = -NNNN

    prlimit(0, -1, &rlim, NULL);
    //staptest// prlimit64 (0, RLIM_INFINITY, \[NNNN,NNNN\], 0x0) = -NNNN

    prlimit(0, RLIMIT_CPU, (struct rlimit *)-1, NULL);
#ifdef __s390__
    //staptest// prlimit64 (0, RLIMIT_CPU, 0x[7]?[f]+, 0x0) = -NNNN
#else
    //staptest// prlimit64 (0, RLIMIT_CPU, 0x[f]+, 0x0) = -NNNN
#endif

    prlimit(0, RLIMIT_CPU, &rlim, (struct rlimit *)-1);
#ifdef __s390__
    //staptest// prlimit64 (0, RLIMIT_CPU, \[NNNN,NNNN\], 0x[7]?[f]+) = -NNNN
#else
    //staptest// prlimit64 (0, RLIMIT_CPU, \[NNNN,NNNN\], 0x[f]+) = -NNNN
#endif
#endif

    return 0;
}