DeviceInfo: don't kill app when deviceinfo is not found

Sometimes this is fine, e.g. when mkinitfs is run before the device
package is installed in a chroot. So it shouldn't kill the app.
This commit is contained in:
Clayton Craft
2021-08-16 22:20:14 -07:00
parent 66b86cc363
commit 217360b400

View File

@@ -3,8 +3,8 @@
package deviceinfo
import (
"errors"
"github.com/BurntSushi/toml"
"log"
"os"
)
@@ -37,16 +37,17 @@ type DeviceInfo struct {
Deviceinfo_flash_kernel_on_update string
}
func ReadDeviceinfo() DeviceInfo {
func ReadDeviceinfo() (DeviceInfo, error) {
file := "/etc/deviceinfo"
var deviceinfo DeviceInfo
_, err := os.Stat(file)
if err != nil {
log.Fatal("Unable to find deviceinfo: ", file)
return deviceinfo, errors.New("Unable to find deviceinfo: " + file)
}
var deviceinfo DeviceInfo
if _, err := toml.DecodeFile(file, &deviceinfo); err != nil {
log.Fatal(err)
return deviceinfo, err
}
return deviceinfo
return deviceinfo, nil
}