From 217360b4005a6fc19067720dcc01b9821bcd74d1 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Mon, 16 Aug 2021 22:20:14 -0700 Subject: [PATCH] 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. --- pkgs/deviceinfo/deviceinfo.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkgs/deviceinfo/deviceinfo.go b/pkgs/deviceinfo/deviceinfo.go index 5015f91..1c9cb30 100644 --- a/pkgs/deviceinfo/deviceinfo.go +++ b/pkgs/deviceinfo/deviceinfo.go @@ -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 }