Raise error if /etc/hostid not readable

This commit is contained in:
yo 2022-04-05 22:21:04 +02:00
parent 0f97270a6a
commit e0f371693a
2 changed files with 11 additions and 4 deletions

View File

@ -20,7 +20,11 @@ func ListJailsProps(args []string) {
var conf Jail
var result []string
// Mandatory constructor to init default values
jailconf := NewJailConfig()
jailconf, err := NewJailConfig()
if err != nil {
fmt.Printf("Error allocating JailConfig: %s\n", err.Error())
return
}
conf.Config = jailconf
@ -215,7 +219,10 @@ func getJailConfig(jailConfigPath string) (JailConfig, error) {
if err != nil { log.Fatalln(fmt.Sprintf("Unable to read %s, check path and/or rights", jailConfigPath)) }
// Mandatory constructor to init default values
jc := NewJailConfig()
jc, err := NewJailConfig()
if err != nil {
return err
}
err = json.Unmarshal([]byte(content), &jc)
if err != nil { log.Fatalln(fmt.Sprintf("Error occured during unmarshaling %s: %s", jailConfigPath, err.Error())) }

View File

@ -18,12 +18,12 @@ import (
/*****************************************************************************
* Mandatory constructor for JailConfig type. It set default values
*****************************************************************************/
func NewJailConfig() JailConfig {
func NewJailConfig() (JailConfig, error) {
var jc JailConfig
hostid, err := ioutil.ReadFile("/etc/hostid")
if err != nil {
hostid = []byte("12345678-abcd-ef98-7654-321012345678")
return err
} else {
hostid = []byte(strings.Replace(string(hostid), "\n", "", -1))
}