Skip to content

Commit 7de2ac5

Browse files
author
Ma Shimiao
committed
optimize matched action remove
Signed-off-by: Ma Shimiao <[email protected]>
1 parent d964565 commit 7de2ac5

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

generate/seccomp/parse_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func ParseDefaultAction(action string, config *rspec.LinuxSeccomp) error {
9797
return err
9898
}
9999
config.DefaultAction = defaultAction
100-
err = RemoveAllMatchingRules(config, action)
100+
err = RemoveAllMatchingRules(config, defaultAction)
101101
if err != nil {
102102
return err
103103
}

generate/seccomp/parse_remove.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ func RemoveAction(arguments string, config *rspec.LinuxSeccomp) error {
1515
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
1616
}
1717

18-
var syscallsToRemove []string
19-
if strings.Contains(arguments, ",") {
20-
syscallsToRemove = strings.Split(arguments, ",")
21-
} else {
22-
syscallsToRemove = append(syscallsToRemove, arguments)
23-
}
18+
syscallsToRemove := strings.Split(arguments, ",")
2419

2520
for counter, syscallStruct := range config.Syscalls {
2621
if reflect.DeepEqual(syscallsToRemove, syscallStruct.Names) {
@@ -42,16 +37,11 @@ func RemoveAllSeccompRules(config *rspec.LinuxSeccomp) error {
4237
}
4338

4439
// RemoveAllMatchingRules will remove any syscall rules that match the specified action
45-
func RemoveAllMatchingRules(config *rspec.LinuxSeccomp, action string) error {
40+
func RemoveAllMatchingRules(config *rspec.LinuxSeccomp, seccompAction rspec.LinuxSeccompAction) error {
4641
if config == nil {
4742
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
4843
}
4944

50-
seccompAction, err := parseAction(action)
51-
if err != nil {
52-
return err
53-
}
54-
5545
for _, syscall := range config.Syscalls {
5646
if reflect.DeepEqual(syscall.Action, seccompAction) {
5747
RemoveAction(strings.Join(syscall.Names, ","), config)

0 commit comments

Comments
 (0)