Skip to content

Commit

Permalink
libcontainer: set pids limit to max when set to 0
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hunt <pehunt@redhat.com>
  • Loading branch information
haircommander committed Sep 12, 2023
1 parent cb44958 commit 670474e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
16 changes: 5 additions & 11 deletions libcontainer/cgroups/fs/pids.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ func (s *PidsGroup) Apply(path string, _ *configs.Resources, pid int) error {
}

func (s *PidsGroup) Set(path string, r *configs.Resources) error {
if r.PidsLimit != 0 {
// "max" is the fallback value.
limit := "max"
// "max" is the fallback value.
limit := "max"

if r.PidsLimit > 0 {
limit = strconv.FormatInt(r.PidsLimit, 10)
}

if err := cgroups.WriteFile(path, "pids.max", limit); err != nil {
return err
}
if r.PidsLimit > 0 {
limit = strconv.FormatInt(r.PidsLimit, 10)
}

return nil
return cgroups.WriteFile(path, "pids.max", limit)
}

func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
Expand Down
3 changes: 0 additions & 3 deletions libcontainer/cgroups/fs2/pids.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func isPidsSet(r *configs.Resources) bool {
}

func setPids(dirPath string, r *configs.Resources) error {
if !isPidsSet(r) {
return nil
}
if val := numToStr(r.PidsLimit); val != "" {
if err := cgroups.WriteFile(dirPath, "pids.max", val); err != nil {
return err
Expand Down

0 comments on commit 670474e

Please sign in to comment.