about summary refs log tree commit diff
path: root/Src/Builtins/rlimits.awk
blob: e9c576c666f4a7c727043adb0a3d5ba280e9d000 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# rlimits.awk: {g,n}awk script to generate rlimits.h
#
# NB: On SunOS 4.1.3 - user-functions don't work properly, also \" problems
# Without 0 + hacks some nawks compare numbers as strings
#
BEGIN {limidx = 0}

/^[\t ]*(#[\t ]*define[\t _]*RLIMIT_[A-Z_]*[\t ]*[0-9][0-9]*|RLIMIT_[A-Z_]*,[\t ]*|_*RLIMIT_[A-Z_]*[\t ]*=[\t ]*[0-9][0-9]*,[\t ]*)/ {
    limindex = index($0, "RLIMIT_")
    limtail = substr($0, limindex, 80)
    split(limtail, tmp)
    limnam = substr(tmp[1], 8, 20)
    limnum = tmp[2]
    # in this case I assume GNU libc resourcebits.h
    if (limnum == "") {
	limnum = limidx++
	limindex = index($0, ",")
	limnam = substr(limnam, 1, limindex-1)
    }
    if (limnum == "=") {
	if (tmp[3] ~ /^[0-9]/) {
	    limnum = tmp[3] + 0
	} else {
	    limnum = limidx++
	}
	limindex = index($0, ",")
	limnam = substr(limnam, 1, limindex-1)
    }
    limrev[limnam] = limnum
    if (lim[limnum] == "") {
	lim[limnum] = limnam
	if (limnum ~ /^[0-9]*$/) {
	    if (limnam == "AIO_MEM") { msg[limnum] = "Maiomemorylocked" }
	    if (limnam == "AIO_OPS") { msg[limnum] = "Naiooperations" }
	    if (limnam == "AS")      { msg[limnum] = "Maddressspace" }
	    if (limnam == "CORE")    { msg[limnum] = "Mcoredumpsize" }
	    if (limnam == "CPU")     { msg[limnum] = "Tcputime" }
	    if (limnam == "DATA")    { msg[limnum] = "Mdatasize" }
	    if (limnam == "FSIZE")   { msg[limnum] = "Mfilesize" }
	    if (limnam == "LOCKS")   { msg[limnum] = "Nmaxfilelocks" }
	    if (limnam == "MEMLOCK") { msg[limnum] = "Mmemorylocked" }
	    if (limnam == "NOFILE")  { msg[limnum] = "Ndescriptors" }
	    if (limnam == "NPROC")   { msg[limnum] = "Nmaxproc" }
	    if (limnam == "NTHR")    { msg[limnum] = "Nmaxpthreads" }
	    if (limnam == "OFILE")   { msg[limnum] = "Ndescriptors" }
	    if (limnam == "PTHREAD") { msg[limnum] = "Nmaxpthreads" }
	    if (limnam == "RSS")     { msg[limnum] = "Mresident" }
	    if (limnam == "SBSIZE")  { msg[limnum] = "Msockbufsize" }
	    if (limnam == "STACK")   { msg[limnum] = "Mstacksize" }
	    if (limnam == "TCACHE")  { msg[limnum] = "Ncachedthreads" }
	    if (limnam == "VMEM")    { msg[limnum] = "Mvmemorysize" }
	    if (limnam == "SIGPENDING") { msg[limnum] = "Nsigpending" }
	    if (limnam == "MSGQUEUE") { msg[limnum] = "Nmsgqueue" }
	    if (limnam == "NICE") { msg[limnum] = "Nnice" }
	    if (limnam == "RTPRIO") { msg[limnum] = "Nrt_priority" }
	    if (limnam == "RTTIME") { msg[limnum] = "Urt_time" }
	    if (limnam == "POSIXLOCKS") { msg[limnum] = "Nposixlocks" }
	    if (limnam == "NPTS")    { msg[limnum] = "Npseudoterminals" }
	    if (limnam == "SWAP")    { msg[limnum] = "Mswapsize" }
	    if (limnam == "KQUEUES") { msg[limnum] = "Nkqueues" }
	    if (limnam == "UMTXP")   { msg[limnum] = "Numtxp" }
        }
    }
}
/^[\t ]*#[\t ]*define[\t _]*RLIM_NLIMITS[\t ]*[0-9][0-9]*/ {
    limindex = index($0, "RLIM_")
    limtail = substr($0, limindex, 80)
    split(limtail, tmp)
    nlimits = tmp[2]
}
# in case of GNU libc
/^[\t ]*RLIM_NLIMITS[\t ]*=[\t ]*RLIMIT_NLIMITS/ {
    if(!nlimits) { nlimits = limidx }
}
/^[\t _]*RLIM(IT)?_NLIMITS[\t ]*=[\t ]*[0-9][0-9]*/ {
    limindex = index($0, "=")
    limtail = substr($0, limindex, 80)
    split(limtail, tmp)
    nlimits = tmp[2]
}

END {
    if (limrev["MEMLOCK"] != "") {
        irss = limrev["RSS"]
        msg[irss] = "Mmemoryuse"
    }
    ps = "%s"

    printf("%s\n%s\n\n", "/** rlimits.h                              **/", "/** architecture-customized limits for zsh **/")
    printf("#define ZSH_NLIMITS %d\n\nstatic char const *recs[ZSH_NLIMITS] = {\n", 0 + nlimits)

    for (i = 0; i < 0 + nlimits; i++)
	if (msg[i] == "")
            printf("\t%c%s%c,\n", 34, lim[i], 34)
	else
	    printf("\t%c%s%c,\n", 34, substr(msg[i], 2, 30), 34)
    print "};"
    print ""
    print "static int limtype[ZSH_NLIMITS] = {"
    for (i = 0; i < 0 + nlimits; i++) {
	if (msg[i] == "")
	    limtype = "UNKNOWN"
	else {
	    limtype = substr(msg[i], 1, 1)
	    if(limtype == "M") { limtype = "MEMORY" }
	    if(limtype == "N") { limtype = "NUMBER" }
	    if(limtype == "T") { limtype = "TIME" }
	    if(limtype == "U") { limtype = "MICROSECONDS" }
	}
	printf("\tZLIMTYPE_%s,\n", limtype)
    }
    print "};"

    exit(0)
}