@@ -26,55 +26,55 @@ import (
26
26
// http://man7.org/linux/man-pages/man2/getrlimit.2.html.
27
27
type ProcLimits struct {
28
28
// CPU time limit in seconds.
29
- CPUTime int64
29
+ CPUTime uint64
30
30
// Maximum size of files that the process may create.
31
- FileSize int64
31
+ FileSize uint64
32
32
// Maximum size of the process's data segment (initialized data,
33
33
// uninitialized data, and heap).
34
- DataSize int64
34
+ DataSize uint64
35
35
// Maximum size of the process stack in bytes.
36
- StackSize int64
36
+ StackSize uint64
37
37
// Maximum size of a core file.
38
- CoreFileSize int64
38
+ CoreFileSize uint64
39
39
// Limit of the process's resident set in pages.
40
- ResidentSet int64
40
+ ResidentSet uint64
41
41
// Maximum number of processes that can be created for the real user ID of
42
42
// the calling process.
43
- Processes int64
43
+ Processes uint64
44
44
// Value one greater than the maximum file descriptor number that can be
45
45
// opened by this process.
46
- OpenFiles int64
46
+ OpenFiles uint64
47
47
// Maximum number of bytes of memory that may be locked into RAM.
48
- LockedMemory int64
48
+ LockedMemory uint64
49
49
// Maximum size of the process's virtual memory address space in bytes.
50
- AddressSpace int64
50
+ AddressSpace uint64
51
51
// Limit on the combined number of flock(2) locks and fcntl(2) leases that
52
52
// this process may establish.
53
- FileLocks int64
53
+ FileLocks uint64
54
54
// Limit of signals that may be queued for the real user ID of the calling
55
55
// process.
56
- PendingSignals int64
56
+ PendingSignals uint64
57
57
// Limit on the number of bytes that can be allocated for POSIX message
58
58
// queues for the real user ID of the calling process.
59
- MsqqueueSize int64
59
+ MsqqueueSize uint64
60
60
// Limit of the nice priority set using setpriority(2) or nice(2).
61
- NicePriority int64
61
+ NicePriority uint64
62
62
// Limit of the real-time priority set using sched_setscheduler(2) or
63
63
// sched_setparam(2).
64
- RealtimePriority int64
64
+ RealtimePriority uint64
65
65
// Limit (in microseconds) on the amount of CPU time that a process
66
66
// scheduled under a real-time scheduling policy may consume without making
67
67
// a blocking system call.
68
- RealtimeTimeout int64
68
+ RealtimeTimeout uint64
69
69
}
70
70
71
71
const (
72
- limitsFields = 3
72
+ limitsFields = 4
73
73
limitsUnlimited = "unlimited"
74
74
)
75
75
76
76
var (
77
- limitsDelimiter = regexp .MustCompile (" +" )
77
+ limitsMatch = regexp .MustCompile (`(Max \w+\s{0,1}?\w*\s{0,1}\w*)\s{2,}(\w+)\s+(\w+)` )
78
78
)
79
79
80
80
// NewLimits returns the current soft limits of the process.
@@ -96,46 +96,50 @@ func (p Proc) Limits() (ProcLimits, error) {
96
96
l = ProcLimits {}
97
97
s = bufio .NewScanner (f )
98
98
)
99
+
100
+ s .Scan () // Skip limits header
101
+
99
102
for s .Scan () {
100
- fields := limitsDelimiter .Split (s .Text (), limitsFields )
103
+ //fields := limitsMatch.Split(s.Text(), limitsFields)
104
+ fields := limitsMatch .FindStringSubmatch (s .Text ())
101
105
if len (fields ) != limitsFields {
102
106
return ProcLimits {}, fmt .Errorf (
103
107
"couldn't parse %s line %s" , f .Name (), s .Text ())
104
108
}
105
109
106
- switch fields [0 ] {
110
+ switch fields [1 ] {
107
111
case "Max cpu time" :
108
- l .CPUTime , err = parseInt (fields [1 ])
112
+ l .CPUTime , err = parseUint (fields [2 ])
109
113
case "Max file size" :
110
- l .FileSize , err = parseInt (fields [1 ])
114
+ l .FileSize , err = parseUint (fields [2 ])
111
115
case "Max data size" :
112
- l .DataSize , err = parseInt (fields [1 ])
116
+ l .DataSize , err = parseUint (fields [2 ])
113
117
case "Max stack size" :
114
- l .StackSize , err = parseInt (fields [1 ])
118
+ l .StackSize , err = parseUint (fields [2 ])
115
119
case "Max core file size" :
116
- l .CoreFileSize , err = parseInt (fields [1 ])
120
+ l .CoreFileSize , err = parseUint (fields [2 ])
117
121
case "Max resident set" :
118
- l .ResidentSet , err = parseInt (fields [1 ])
122
+ l .ResidentSet , err = parseUint (fields [2 ])
119
123
case "Max processes" :
120
- l .Processes , err = parseInt (fields [1 ])
124
+ l .Processes , err = parseUint (fields [2 ])
121
125
case "Max open files" :
122
- l .OpenFiles , err = parseInt (fields [1 ])
126
+ l .OpenFiles , err = parseUint (fields [2 ])
123
127
case "Max locked memory" :
124
- l .LockedMemory , err = parseInt (fields [1 ])
128
+ l .LockedMemory , err = parseUint (fields [2 ])
125
129
case "Max address space" :
126
- l .AddressSpace , err = parseInt (fields [1 ])
130
+ l .AddressSpace , err = parseUint (fields [2 ])
127
131
case "Max file locks" :
128
- l .FileLocks , err = parseInt (fields [1 ])
132
+ l .FileLocks , err = parseUint (fields [2 ])
129
133
case "Max pending signals" :
130
- l .PendingSignals , err = parseInt (fields [1 ])
134
+ l .PendingSignals , err = parseUint (fields [2 ])
131
135
case "Max msgqueue size" :
132
- l .MsqqueueSize , err = parseInt (fields [1 ])
136
+ l .MsqqueueSize , err = parseUint (fields [2 ])
133
137
case "Max nice priority" :
134
- l .NicePriority , err = parseInt (fields [1 ])
138
+ l .NicePriority , err = parseUint (fields [2 ])
135
139
case "Max realtime priority" :
136
- l .RealtimePriority , err = parseInt (fields [1 ])
140
+ l .RealtimePriority , err = parseUint (fields [2 ])
137
141
case "Max realtime timeout" :
138
- l .RealtimeTimeout , err = parseInt (fields [1 ])
142
+ l .RealtimeTimeout , err = parseUint (fields [2 ])
139
143
}
140
144
if err != nil {
141
145
return ProcLimits {}, err
@@ -145,11 +149,11 @@ func (p Proc) Limits() (ProcLimits, error) {
145
149
return l , s .Err ()
146
150
}
147
151
148
- func parseInt (s string ) (int64 , error ) {
152
+ func parseUint (s string ) (uint64 , error ) {
149
153
if s == limitsUnlimited {
150
- return - 1 , nil
154
+ return 18446744073709551615 , nil
151
155
}
152
- i , err := strconv .ParseInt (s , 10 , 64 )
156
+ i , err := strconv .ParseUint (s , 10 , 64 )
153
157
if err != nil {
154
158
return 0 , fmt .Errorf ("couldn't parse value %s: %s" , s , err )
155
159
}
0 commit comments