build util function for write sys file

Change-Id: I8f122b4314c1d983e7ba1ce1d66ce876bef0dca9
pull/6/head
m1093782566 2016-10-20 14:17:52 +08:00
parent 6306ab00d2
commit ad89825065
1 changed files with 5 additions and 1 deletions

View File

@ -55,7 +55,7 @@ func (realConntracker) SetMax(max int) error {
}
// TODO: generify this and sysctl to a new sysfs.WriteInt()
glog.Infof("Setting conntrack hashsize to %d", max/4)
return ioutil.WriteFile("/sys/module/nf_conntrack/parameters/hashsize", []byte(strconv.Itoa(max/4)), 0640)
return writeIntStringFile("/sys/module/nf_conntrack/parameters/hashsize", max/4)
}
func (realConntracker) SetTCPEstablishedTimeout(seconds int) error {
@ -86,3 +86,7 @@ func isSysFSWritable() (bool, error) {
}
return false, nil
}
func writeIntStringFile(filename string, value int) error {
return ioutil.WriteFile(filename, []byte(strconv.Itoa(value)), 0640)
}