Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log handling #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions datadisk/datadisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type datadisk struct {
}

func (d datadisk) ChangeDevice(newDevice string) (bool, *dbus.Error) {
fmt.Printf("Request to change data disk to %s.\n", newDevice)
log.Printf("Request to change data disk to %s.", newDevice)

udisks2helper := udisks2.NewUDisks2(d.conn)
dataDevice, err := udisks2helper.GetRootDeviceFromLabel("hassos-data")
Expand Down Expand Up @@ -93,7 +93,7 @@ func InitializeDBus(conn *dbus.Conn) {

err := conn.Export(d, objectPath, ifaceName)
if err != nil {
panic(err)
log.Panic(err)
}

propsSpec := map[string]map[string]*prop.Prop{
Expand All @@ -108,7 +108,7 @@ func InitializeDBus(conn *dbus.Conn) {
}
props, err := prop.Export(conn, objectPath, propsSpec)
if err != nil {
panic(err)
log.Panic(err)
}

node := &introspect.Node{}
Expand All @@ -127,8 +127,8 @@ func InitializeDBus(conn *dbus.Conn) {
err = conn.Export(dbus_xml_str, objectPath,
"org.freedesktop.DBus.Introspectable")
if err != nil {
panic(err)
log.Panic(err)
}

fmt.Printf("Exposing object %s with interface %s ...\n", objectPath, ifaceName)
log.Printf("Exposing object %s with interface %s ...", objectPath, ifaceName)
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"

"github.com/home-assistant/os-agent/datadisk"
Expand Down Expand Up @@ -36,6 +37,10 @@ func main() {
datadisk.InitializeDBus(conn)
system.InitializeDBus(conn)

daemon.SdNotify(false, daemon.SdNotifyReady)
_, err = daemon.SdNotify(false, daemon.SdNotifyReady)
if err != nil {
log.Panic(err)
}

select {}
}
15 changes: 8 additions & 7 deletions system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

Expand Down Expand Up @@ -66,7 +67,7 @@ func (d system) WipeDevice() (bool, *dbus.Error) {
if err != nil {
return false, dbus.MakeFailedError(err)
}
fmt.Printf("Successfully wiped device data.\n")
log.Printf("Successfully wiped device data.")

return true, nil
}
Expand All @@ -75,7 +76,7 @@ func (d system) ScheduleWipeDevice() (bool, *dbus.Error) {

data, err := ioutil.ReadFile(kernelCommandLine)
if err != nil {
fmt.Println(err)
log.Println(err)
return false, dbus.MakeFailedError(err)
}

Expand All @@ -84,18 +85,18 @@ func (d system) ScheduleWipeDevice() (bool, *dbus.Error) {

err = ioutil.WriteFile(tmpKernelCommandLine, []byte(datastr), 0644)
if err != nil {
fmt.Println(err)
log.Println(err)
return false, dbus.MakeFailedError(err)
}

// Boot is mounted sync on Home Assistant OS, so just rename should be fine.
err = os.Rename(tmpKernelCommandLine, kernelCommandLine)
if err != nil {
fmt.Println(err)
log.Println(err)
return false, dbus.MakeFailedError(err)
}

fmt.Printf("Device will get wiped on next reboot!\n")
log.Printf("Device will get wiped on next reboot!")
return true, nil
}

Expand Down Expand Up @@ -124,8 +125,8 @@ func InitializeDBus(conn *dbus.Conn) {
err = conn.Export(dbus_xml_str, objectPath,
"org.freedesktop.DBus.Introspectable")
if err != nil {
panic(err)
log.Panic(err)
}

fmt.Printf("Exposing object %s with interface %s ...\n", objectPath, ifaceName)
log.Printf("Exposing object %s with interface %s ...", objectPath, ifaceName)
}