-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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)