Skip to content

Commit

Permalink
chore: remove redundant validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Nov 24, 2024
1 parent 6c7e692 commit eca8ae9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [x] process_capabilities_fail
- [x] process_oom_score_adj
- [x] process_rlimits
- [x] process_rlimits_fail
- [x] process_user
- [x] root_readonly_true
- [x] start
Expand All @@ -218,7 +219,6 @@ Tests are run on every build in [this Github Action](https://github.com/nixpig/b
- [ ] pidfile
- [ ] poststart_fail
- [ ] poststop_fail
- [ ] process_rlimits_fail

### Unsupported tests

Expand Down
12 changes: 10 additions & 2 deletions container/cgroups/rlimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ var Rlimits = map[string]uint{

func SetRlimits(rlimits []specs.POSIXRlimit) error {
for _, rl := range rlimits {
if err := syscall.Getrlimit(int(Rlimits[rl.Type]), &syscall.Rlimit{
rlType := int(Rlimits[rl.Type])
if err := syscall.Getrlimit(rlType, &syscall.Rlimit{
Cur: rl.Soft,
Max: rl.Hard,
}); err != nil {
return fmt.Errorf("map rlimit to kernel interface: %w", err)
}

if err := syscall.Setrlimit(int(Rlimits[rl.Type]), &syscall.Rlimit{
if err := syscall.Getrlimit(rlType, &syscall.Rlimit{
Cur: rl.Soft,
Max: rl.Hard,
}); err != nil {
return fmt.Errorf("map rlimit to kernel interface: %w", err)
}

if err := syscall.Setrlimit(rlType, &syscall.Rlimit{
Cur: rl.Soft,
Max: rl.Hard,
}); err != nil {
Expand Down
8 changes: 3 additions & 5 deletions container/container_init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package container

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -104,11 +105,8 @@ func (c *Container) Init(reexec string, arg string) error {

if c.Spec.Process != nil && c.Spec.Process.Rlimits != nil {
for _, rl := range c.Spec.Process.Rlimits {
if err := syscall.Getrlimit(int(cgroups.Rlimits[rl.Type]), &syscall.Rlimit{
Cur: rl.Soft,
Max: rl.Hard,
}); err != nil {
return fmt.Errorf("map rlimit to kernel interface: %w", err)
if _, ok := cgroups.Rlimits[rl.Type]; !ok {
return errors.New("unable to map rlimit to kernel interface")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion oci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tests=(
"process_capabilities_fail"
"process_oom_score_adj"
"process_rlimits"
# "process_rlimits_fail"
"process_rlimits_fail"
"process_user"
"root_readonly_true"
"start"
Expand Down

0 comments on commit eca8ae9

Please sign in to comment.