Repository navigation
syscall: prlimit argument error for Getrlimit and Setrlimit on linux/386 #5949
Copy link
Copy link
Closed
Labels
Milestone
Description
$ go version
go version devel +5990f8211e89 Wed Jul 24 13:48:04 2013 -0400 linux/386
$ ulimit -Sn
1024
$ ulimit -Hn
4096
$ cat rlimit.go
package main
import (
"fmt"
"syscall"
)
func main() {
var rlimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
fmt.Println(rlimit, err)
return
}
fmt.Println(rlimit)
rlimit.Cur = rlimit.Max
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
fmt.Println(rlimit, err)
return
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
fmt.Println(rlimit, err)
return
}
fmt.Println(rlimit)
}
Want:
$ go run rlimit.go
{1024 4096}
{4096 4096}
Got:
$ go run rlimit.go
{0 0}
{0 0}
Fix:
diff --git a/src/pkg/syscall/syscall_linux_386.go b/src/pkg/syscall/syscall_linux_386.go
--- a/src/pkg/syscall/syscall_linux_386.go
+++ b/src/pkg/syscall/syscall_linux_386.go
@@ -78,7 +78,7 @@
const rlimInf64 = ^uint64(0)
func Getrlimit(resource int, rlim *Rlimit) (err error) {
- err = prlimit(0, resource, rlim, nil)
+ err = prlimit(0, resource, nil, rlim)
if err != ENOSYS {
return err
}
@@ -106,7 +106,7 @@
//sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT
func Setrlimit(resource int, rlim *Rlimit) (err error) {
- err = prlimit(0, resource, nil, rlim)
+ err = prlimit(0, resource, rlim, nil)
if err != ENOSYS {
return err
}
prlimit:
$ man prlimit
prlimit()
The Linux-specific prlimit() system call combines and extends the func‐
tionality of setrlimit() and getrlimit(). It can be used to both set
and get the resource limits of an arbitrary process.
The resource argument has the same meaning as for setrlimit() and getr‐
limit().
If the new_limit argument is a not NULL, then the rlimit structure to
which it points is used to set new values for the soft and hard limits
for resource. If the old_limit argument is a not NULL, then a success‐
ful call to prlimit() places the previous soft and hard limits for
resource in the rlimit structure pointed to by old_limit.
The pid argument specifies the ID of the process on which the call is
to operate. If pid is 0, then the call applies to the calling process.
To set or get the resources of a process other than itself, the caller
must have the CAP_SYS_RESOURCE capability, or the real, effective, and
saved set user IDs of the target process must match the real user ID of
the caller and the real, effective, and saved set group IDs of the tar‐
get process must match the real group ID of the caller.
Attachments:
- rlimit.go (494 bytes)
- rlimit.diff (678 bytes)
Reactions are currently unavailable
Activity
peterGo commentedon Jul 24, 2013
Comment 1:
ianlancetaylor commentedon Jul 24, 2013
Comment 2:
Labels changed: added priority-soon, go1.1.2, removed priority-triage.
Status changed to Accepted.
peterGo commentedon Jul 24, 2013
Comment 3:
peterGo commentedon Jul 25, 2013
Comment 4:
rsc commentedon Jul 25, 2013
Comment 5:
This issue was closed by revision 5852760.
Status changed to Fixed.
adg commentedon Jul 29, 2013
Comment 6:
This issue was closed by revision 55ac276af5a7.
[release-branch.go1.1] syscall: prlimit argument error for Getrlimit …