two/internal/sysctl/sysctl.go
GnomeZworc 94c2f82867
f-41: frr, sysctl, netif: primitives du L3VNI #41
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-10-06 14:13:08 +02:00

23 lines
457 B
Go

package sysctl
import (
"fmt"
"os"
"path/filepath"
"strings"
)
var root = "/proc/sys"
func Set(key, value string) error {
path := filepath.Join(root, strings.ReplaceAll(key, ".", "/"))
f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)
if err != nil {
return fmt.Errorf("sysctl %s: %w", key, err)
}
if _, err := f.WriteString(value); err != nil {
f.Close()
return fmt.Errorf("sysctl %s=%s: %w", key, value, err)
}
return f.Close()
}