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 package deviceinfo
import ( import (
"errors"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"log"
"os" "os"
) )
@@ -37,16 +37,17 @@ type DeviceInfo struct {
Deviceinfo_flash_kernel_on_update string Deviceinfo_flash_kernel_on_update string
} }
func ReadDeviceinfo() DeviceInfo { func ReadDeviceinfo() (DeviceInfo, error) {
file := "/etc/deviceinfo" file := "/etc/deviceinfo"
var deviceinfo DeviceInfo
_, err := os.Stat(file) _, err := os.Stat(file)
if err != nil { 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 { if _, err := toml.DecodeFile(file, &deviceinfo); err != nil {
log.Fatal(err) return deviceinfo, err
} }
return deviceinfo return deviceinfo, nil
} }