mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
Merge pull request #2823 from eyz/sysctlCommentFixSetWarnsNoReadonly
pkg/sysctl fixes: support commented KV lines, additional seperator and comment character, no post-crit KV set skips
This commit is contained in:
commit
ff91872969
@ -13,7 +13,7 @@ onboot:
|
||||
- name: metadata
|
||||
image: linuxkit/metadata:2af15c9f4b0e73515c219b7cc14e6e65e1d4fd6d
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: sysfs
|
||||
image: linuxkit/sysfs:1284b4a7061a5cc426425f0fb00748192505a05f
|
||||
- name: binfmt
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
services:
|
||||
- name: rngd
|
||||
image: linuxkit/rngd:94e01a4b16fadb053455cdc2269c4eb0b39199cd
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: sysfs
|
||||
image: linuxkit/sysfs:1284b4a7061a5cc426425f0fb00748192505a05f
|
||||
- name: format
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -11,7 +11,7 @@ onboot:
|
||||
image: linuxkit/rngd:94e01a4b16fadb053455cdc2269c4eb0b39199cd
|
||||
command: ["/sbin/rngd", "-1"]
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: rngd1
|
||||
image: linuxkit/rngd:94e01a4b16fadb053455cdc2269c4eb0b39199cd
|
||||
command: ["/sbin/rngd", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
services:
|
||||
- name: getty
|
||||
image: linuxkit/getty:22e27189b6b354e1d5d38fc0536a5af3f2adb79f
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -22,17 +22,19 @@ func init() {
|
||||
}
|
||||
|
||||
func sysctl(line []byte) error {
|
||||
sysctlLineTrimmed := strings.TrimSpace(string(line[:]))
|
||||
// skip any commented lines
|
||||
if len(sysctlLineTrimmed) >= 1 && (sysctlLineTrimmed[:1] == "#" || sysctlLineTrimmed[:1] == ";") {
|
||||
return nil
|
||||
}
|
||||
// parse line into a string of expected form X.Y.Z=VALUE
|
||||
sysctlLineKV := strings.Split(string(line[:]), "=")
|
||||
sysctlLineKV := strings.Split(sysctlLineTrimmed, "=")
|
||||
if len(sysctlLineKV) != 2 {
|
||||
if len(sysctlLineKV) >= 1 && len(sysctlLineKV[0]) >= 1 && strings.Trim(sysctlLineKV[0], " ")[:1] == "#" {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Cannot parse %s", string(line))
|
||||
return fmt.Errorf("Cannot parse %s", sysctlLineTrimmed)
|
||||
}
|
||||
// trim any extra whitespace
|
||||
sysctlSetting, sysctlValue := strings.Trim(sysctlLineKV[0], " "), strings.Trim(sysctlLineKV[1], " ")
|
||||
sysctlFile := filepath.Join(sysctlDir, filepath.Join(strings.Split(sysctlSetting, ".")...))
|
||||
sysctlSetting, sysctlValue := strings.TrimSpace(sysctlLineKV[0]), strings.TrimSpace(sysctlLineKV[1])
|
||||
sysctlFile := filepath.Join(sysctlDir, filepath.Join(strings.FieldsFunc(sysctlSetting, splitKv)...))
|
||||
file, err := os.OpenFile(sysctlFile, os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot open %s: %s", sysctlFile, err)
|
||||
@ -45,6 +47,10 @@ func sysctl(line []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func splitKv(r rune) bool {
|
||||
return r == '.' || r == '/'
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@ -65,7 +71,7 @@ func main() {
|
||||
}
|
||||
err = sysctl(line)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(fmt.Errorf("WARN: %v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: sysfs
|
||||
image: linuxkit/sysfs:1284b4a7061a5cc426425f0fb00748192505a05f
|
||||
- name: dhcpcd
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: sysfs
|
||||
image: linuxkit/sysfs:1284b4a7061a5cc426425f0fb00748192505a05f
|
||||
- name: dhcpcd
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: format
|
||||
image: linuxkit/format:e945016ec780a788a71dcddc81497d54d3b14bc7
|
||||
- name: mount
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- mobylinux/ca-certificates:eabc5a6e59f05aa91529d80e9a595b85b046f935
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -9,7 +9,7 @@ init:
|
||||
- linuxkit/ima-utils:dfeb3896fd29308b80ff9ba7fe5b8b767e40ca29
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -9,7 +9,7 @@ init:
|
||||
- linuxkit/memlogd:9b5834189f598f43c507f6938077113906f51012
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -9,7 +9,7 @@ init:
|
||||
- samoht/fdd
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
services:
|
||||
- name: getty
|
||||
image: linuxkit/getty:22e27189b6b354e1d5d38fc0536a5af3f2adb79f
|
||||
|
@ -7,7 +7,7 @@ init:
|
||||
- linuxkit/containerd:e58a382c33bb509ba3e0e8170dfaa5a100504c5b
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcp-client
|
||||
image: miragesdk/dhcp-client:22aa9d527820534295a8cd59901c0c5197af6585
|
||||
net: host
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
services:
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: dhcpcd
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
binds:
|
||||
- /etc/sysctl.d/01-swarmd.conf:/etc/sysctl.d/01-swarmd.conf
|
||||
- name: dhcpcd
|
||||
|
@ -8,7 +8,7 @@ init:
|
||||
- linuxkit/ca-certificates:de21b84d9b055ad9dcecc57965b654a7a24ef8e0
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: sysfs
|
||||
image: linuxkit/sysfs:1284b4a7061a5cc426425f0fb00748192505a05f
|
||||
- name: format
|
||||
|
@ -11,7 +11,7 @@ onboot:
|
||||
image: linuxkit/dhcpcd:0d59a6cc03412289ef4313f2491ec666c1715cc9
|
||||
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: format
|
||||
image: linuxkit/format:e945016ec780a788a71dcddc81497d54d3b14bc7
|
||||
- name: mount
|
||||
|
@ -6,7 +6,7 @@ init:
|
||||
- linuxkit/runc:abc3f292653e64a2fd488e9675ace19a55ec7023
|
||||
onboot:
|
||||
- name: sysctl
|
||||
image: linuxkit/sysctl:db575765635dab6dd1164fce5a39782e0f646b84
|
||||
image: linuxkit/sysctl:4c1ef93bb5eb1a877318db4b2daa6768ed002e21
|
||||
- name: test
|
||||
image: alpine:3.7
|
||||
net: host
|
||||
|
Loading…
Reference in New Issue
Block a user