diff --git a/backup.go b/backup.go index fb117c8..4eee154 100644 --- a/backup.go +++ b/backup.go @@ -93,6 +93,7 @@ func (b *Backup) PrepareRun() error { // Run runs the backup script with appropriate rights. func (b *Backup) Run() error { log.Printf("Running backup '%s'.", b.Name) + UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Running backup '%s'...", b.Name), MsgLevels.Info) dev, ok := config.Devices[b.TargetDevice] if ok { log.Printf("Device found: %s (%s).", dev.Name, dev.UUID) @@ -157,6 +158,7 @@ func (b *Backup) Run() error { return err } runs.RegisterRun(b) + UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Finished backup '%s'", b.Name), MsgLevels.Info) return nil } // quit with error that the device is not available. diff --git a/cmd/backive/main.go b/cmd/backive/main.go index 41ac64f..0f89352 100644 --- a/cmd/backive/main.go +++ b/cmd/backive/main.go @@ -74,11 +74,15 @@ func defaultCallback(envMap map[string]string) { if rerr != nil { log.Printf("Error running the backup routine: %v", err) } - dev.Unmount() } else { - log.Printf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err) + msg := fmt.Sprintf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err) + log.Printf(msg) + backive.UiHdl.DisplayMessage("Backive backup", msg, backive.MsgLevels.Info) } } + if dev.IsMounted() { + dev.Unmount() + } } else { log.Println("No backup found.") } diff --git a/events.go b/events.go index 2cd7641..e15eafa 100644 --- a/events.go +++ b/events.go @@ -53,7 +53,6 @@ func (eh *EventHandler) RegisterCallback(cb func(map[string]string)) { func (eh *EventHandler) process() { client, err := mockAccept(eh) log.Println("Accepted client") - UiHdl.DisplayMessage("Event debugging", "Catched event...", MsgLevels.Debug) if err != nil { log.Println(err) return @@ -87,7 +86,6 @@ func (eh *EventHandler) process() { for k, v := range message["data"].(map[string]interface{}) { env[k] = v.(string) } - UiHdl.DisplayMessage("Event debugging", "Got udev event msg.", MsgLevels.Debug) } for _, v := range eh.callbacks { if v != nil { diff --git a/ui/ui_main.go b/ui/ui_main.go index 302505f..e7eae5f 100644 --- a/ui/ui_main.go +++ b/ui/ui_main.go @@ -3,8 +3,6 @@ package ui import ( "bytes" "encoding/json" - "fmt" - "io" "log" "net" "os" @@ -59,10 +57,7 @@ func PollConnection() { if c == nil { log.Println("Creating connection") c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation) - } else { - err = fmt.Errorf("Connection already established") - log.Println(err) - } + } // else already connected // handle error on connection if err != nil { log.Println(err) @@ -75,23 +70,11 @@ func PollConnection() { // receive msgs if c != nil { data := make([]byte, 2048) - for { - buf := make([]byte, 512) - nr, err := c.Read(buf) - log.Printf("Read %d bytes...", nr) - if err == io.ErrClosedPipe { - c = nil - err = nil - break - } - if err != nil && err != io.EOF { - log.Println(err) - break - } - data = append(data, buf[0:nr]...) - if err == io.EOF { - break - } + nr, err := c.Read(data) + log.Printf("Read %d bytes...", nr) + if err != nil { + log.Println(err) + break } sdata := string(bytes.Trim(data, "\x00")) var message map[string]string @@ -124,7 +107,7 @@ func ShallShow(data map[string]string) bool { if err != nil { return false } - if level <= 10 { + if level <= 30 { return true } if int(level) <= uisettings.globalLevel && messageLevel > 0 { diff --git a/ui_handler.go b/ui_handler.go index 74bbaf7..72d7be2 100644 --- a/ui_handler.go +++ b/ui_handler.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net" + "os" "path" ) @@ -49,6 +50,7 @@ func (uh *UIHandler) Init(socketPath string) error { dir, _ := path.Split(socketPath) CreateDirectoryIfNotExists(dir) uh.ls, err = net.Listen("unix", socketPath) + os.Chmod(socketPath, 0777) if err != nil { log.Printf("Error: %s", err) return err @@ -79,8 +81,8 @@ func (uh *UIHandler) Listen() { // DisplayMessage is the method to use inside the service to display messages, with intended level func (uh *UIHandler) DisplayMessage(header string, message string, level MsgLevel) error { if uh.client != nil { - var data map[string]interface{} - data["level"] = int(level) + var data = make(map[string]string) + data["level"] = fmt.Sprint(level) data["header"] = header data["message"] = message b, err := json.Marshal(data)