mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
internal/sys: simplify WriteSysctls
Apparently Write (and WriteString) must return an error (apparently io.ErrShortWrite) on short writes (see [1], [2]), so no explicit check for a short write is needed. While at it, use (*os.File).WriteString directly rather than io.WriteString. [1]: https://pkg.go.dev/os#File.Write [2]: https://pkg.go.dev/io#Writer Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package sys
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -42,10 +41,7 @@ func WriteSysctls(sysctls map[string]string) error {
|
|||||||
}
|
}
|
||||||
defer sysctlFile.Close()
|
defer sysctlFile.Close()
|
||||||
|
|
||||||
n, err := io.WriteString(sysctlFile, value)
|
_, err = sysctlFile.WriteString(value)
|
||||||
if n != len(value) && err == nil {
|
|
||||||
err = fmt.Errorf("short write to file (%d bytes != %d bytes)", n, len(value))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write sysctl %s = %q: %w", key, value, err)
|
return fmt.Errorf("failed to write sysctl %s = %q: %w", key, value, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user