-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9140284
commit 0de145d
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jail | ||
|
||
import ( | ||
"bytes" | ||
"os/exec" | ||
|
||
"go.sbk.wtf/runj/runtimespec" | ||
) | ||
|
||
func Limit(id string, ociConfig *runtimespec.Spec) error { | ||
if ociConfig.FreeBSD == nil { | ||
return nil | ||
} | ||
for _, racctLimit := range ociConfig.FreeBSD.RacctLimits { | ||
rule := makeRCTLRule(id, &racctLimit) | ||
cmd := exec.Command("rctl", "-a", rule) | ||
err := cmd.Run() | ||
if (err != nil) { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func Unlimit(id string, ociConfig *runtimespec.Spec) error { | ||
if ociConfig.FreeBSD == nil { | ||
return nil | ||
} | ||
for _, racctLimit := range ociConfig.FreeBSD.RacctLimits { | ||
rule := makeRCTLRule(id, &racctLimit) | ||
cmd := exec.Command("rctl", "-r", rule) | ||
err := cmd.Run() | ||
if (err != nil) { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func makeRCTLRule(id string, racctLimit *runtimespec.RacctLimit) string { | ||
buf := bytes.Buffer{} | ||
buf.WriteString("jail:") | ||
buf.WriteString(id) | ||
buf.WriteString(":") | ||
buf.WriteString(racctLimit.Resource) | ||
buf.WriteString(":") | ||
buf.WriteString(racctLimit.Action) | ||
buf.WriteString("=") | ||
buf.WriteString(racctLimit.Amount) | ||
if racctLimit.Per != "" { | ||
buf.WriteString("/") | ||
buf.WriteString(racctLimit.Per) | ||
} | ||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters