mirror of
https://github.com/minio/minio.git
synced 2024-12-29 00:23:21 -05:00
432275e966
- pkg/{subsystem}/{package} style - modify Makefile to reflect the new style, consolidate various entries - add a dummy ``main.go`` at top level
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// !build linux,amd64
|
|
|
|
package sysctl
|
|
|
|
import (
|
|
"bufio"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/minio-io/minio/pkg/utils"
|
|
)
|
|
|
|
type Sysctl struct {
|
|
Sysattrmap map[string][]byte
|
|
}
|
|
|
|
func (s *Sysctl) Get() error {
|
|
attrMap := make(map[string][]byte)
|
|
|
|
// Get full system level list
|
|
sysctl_cmd := exec.Command("sysctl", "-a")
|
|
// Sort the output and throw away duplicate keys
|
|
sort_cmd := exec.Command("sort", "-u")
|
|
// Ignore permission denied errors from sysctl output
|
|
grep_cmd := exec.Command("grep", "-v", "permission")
|
|
|
|
output, err := utils.ExecPipe(sysctl_cmd, sort_cmd, grep_cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
scanner := bufio.NewScanner(output)
|
|
split := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
|
advance, token, err = bufio.ScanLines(data, atEOF)
|
|
return
|
|
}
|
|
|
|
scanner.Split(split)
|
|
|
|
for scanner.Scan() {
|
|
split := strings.Split(scanner.Text(), "=")
|
|
if len(split) < 1 {
|
|
println("Invalid token skip..")
|
|
continue
|
|
}
|
|
k, v := strings.TrimSpace(split[0]), strings.TrimSpace(split[1])
|
|
attrMap[k] = []byte(v)
|
|
}
|
|
|
|
s.Sysattrmap = attrMap
|
|
return nil
|
|
}
|