Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: prlimit argument error for Getrlimit and Setrlimit on linux/386 #5949

Closed
peterGo opened this issue Jul 24, 2013 · 6 comments
Closed

Comments

@peterGo
Copy link
Contributor

peterGo commented Jul 24, 2013

$ 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:

  1. rlimit.go (494 bytes)
  2. rlimit.diff (678 bytes)
@peterGo
Copy link
Contributor Author

peterGo commented Jul 24, 2013

Comment 1:

It's likely that arm has the same issue: syscall_linux_arm.go.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Looks right to me; can you send a CL?

Labels changed: added priority-soon, go1.1.2, removed priority-triage.

Status changed to Accepted.

@peterGo
Copy link
Contributor Author

peterGo commented Jul 24, 2013

Comment 3:

Will do.

@peterGo
Copy link
Contributor Author

peterGo commented Jul 25, 2013

Comment 4:

CL: https://golang.org/cl/11803043

@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 5:

This issue was closed by revision 5852760.

Status changed to Fixed.

@adg
Copy link
Contributor

adg commented Jul 29, 2013

Comment 6:

This issue was closed by revision 55ac276af5a7.

@rsc rsc added this to the Go1.1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.1.2 label Apr 14, 2015
adg added a commit that referenced this issue May 11, 2015
…and Setrlimit on Linux 32-bit

««« CL 11803043 / ba52f6399462
syscall: prlimit argument error for Getrlimit and Setrlimit on Linux 32-bit

The rlimit arguments for prlimit are reversed for linux 32-bit (386 and arm).
Getrlimit becomes Setrlimit and vice versa.
Fixes #5949.

R=iant, mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/11803043

»»»

Update #5928

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/11996043
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants