mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
libcontainer: prefer bytes.TrimSpace() over strings.TrimSpace()
Perform trimming before converting to a string, which should be somewhat more performant. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -105,7 +105,7 @@ func CreateCgroupPath(path string, c *configs.Cgroup) (Err error) {
|
||||
}
|
||||
cgTypeFile := filepath.Join(current, "cgroup.type")
|
||||
cgType, _ := ioutil.ReadFile(cgTypeFile)
|
||||
switch strings.TrimSpace(string(cgType)) {
|
||||
switch string(bytes.TrimSpace(cgType)) {
|
||||
// If the cgroup is in an invalid mode (usually this means there's an internal
|
||||
// process in the cgroup tree, because we created a cgroup under an
|
||||
// already-populated-by-other-processes cgroup), then we have to error out if
|
||||
@@ -128,7 +128,7 @@ func CreateCgroupPath(path string, c *configs.Cgroup) (Err error) {
|
||||
fallthrough
|
||||
case "threaded":
|
||||
if containsDomainController(c) {
|
||||
return fmt.Errorf("cannot enter cgroupv2 %q with domain controllers -- it is in %s mode", current, strings.TrimSpace(string(cgType)))
|
||||
return fmt.Errorf("cannot enter cgroupv2 %q with domain controllers -- it is in %s mode", current, string(bytes.TrimSpace(cgType)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +79,5 @@ func GetCgroupParamString(path, file string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(contents)), nil
|
||||
return strings.TrimSpace(contents), nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package libcontainer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -304,7 +305,7 @@ func setupUser(config *initConfig) error {
|
||||
// There's nothing we can do about /etc/group entries, so we silently
|
||||
// ignore setting groups here (since the user didn't explicitly ask us to
|
||||
// set the group).
|
||||
allowSupGroups := !config.RootlessEUID && strings.TrimSpace(string(setgroups)) != "deny"
|
||||
allowSupGroups := !config.RootlessEUID && string(bytes.TrimSpace(setgroups)) != "deny"
|
||||
|
||||
if allowSupGroups {
|
||||
suppGroups := append(execUser.Sgids, addGroups...)
|
||||
|
||||
@@ -1087,7 +1087,7 @@ func TestSysctl(t *testing.T) {
|
||||
// Wait for process
|
||||
waitProcess(&pconfig, t)
|
||||
|
||||
shmmniOutput := strings.TrimSpace(string(stdout.Bytes()))
|
||||
shmmniOutput := string(bytes.TrimSpace(stdout.Bytes()))
|
||||
if shmmniOutput != "8192" {
|
||||
t.Fatalf("kernel.shmmni property expected to be 8192, but is %s", shmmniOutput)
|
||||
}
|
||||
@@ -1221,7 +1221,7 @@ func TestOomScoreAdj(t *testing.T) {
|
||||
|
||||
// Wait for process
|
||||
waitProcess(&pconfig, t)
|
||||
outputOomScoreAdj := strings.TrimSpace(string(stdout.Bytes()))
|
||||
outputOomScoreAdj := string(bytes.TrimSpace(stdout.Bytes()))
|
||||
|
||||
// Check that the oom_score_adj matches the value that was set as part of config.
|
||||
if outputOomScoreAdj != strconv.Itoa(*config.OomScoreAdj) {
|
||||
@@ -1624,7 +1624,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
|
||||
|
||||
// Check if mount is visible on host or not.
|
||||
out, err := exec.Command("findmnt", "-n", "-f", "-oTARGET", dir2host).CombinedOutput()
|
||||
outtrim := strings.TrimSpace(string(out))
|
||||
outtrim := string(bytes.TrimSpace(out))
|
||||
if err != nil {
|
||||
t.Logf("findmnt error %q: %q", err, outtrim)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
package libcontainer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
"github.com/opencontainers/runc/types"
|
||||
@@ -79,7 +79,7 @@ func readSysfsNetworkStats(ethInterface, statsFile string) (uint64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
|
||||
return strconv.ParseUint(string(bytes.TrimSpace(data)), 10, 64)
|
||||
}
|
||||
|
||||
// loopback is a network strategy that provides a basic loopback device
|
||||
|
||||
Reference in New Issue
Block a user