Skip to content

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

Closed

Description

@peterGo
$ 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)

Activity

  1. peterGo commented on Jul 24, 2013

    @peterGo
    ContributorAuthor

    Comment 1:

    It's likely that arm has the same issue: syscall_linux_arm.go.
  2. ianlancetaylor commented on Jul 24, 2013

    @ianlancetaylor
    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.

  3. peterGo commented on Jul 24, 2013

    @peterGo
    ContributorAuthor

    Comment 3:

    Will do.
  4. peterGo commented on Jul 25, 2013

    @peterGo
    ContributorAuthor
  5. rsc commented on Jul 25, 2013

    @rsc
    Contributor

    Comment 5:

    This issue was closed by revision 5852760.

    Status changed to Fixed.

  6. adg commented on Jul 29, 2013

    @adg
    Contributor

    Comment 6:

    This issue was closed by revision 55ac276af5a7.

  7. added this to the Go1.1.2 milestone on Apr 14, 2015
  8. added a commit that references this issue on May 11, 2015
    2041d55
  9. locked and limited conversation to collaborators on Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions