Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
add: send a HSM heartbeat on IPC notification
Browse files Browse the repository at this point in the history
This adds an extra HSM heartbeat that is send when a IPC notification
with the topic "systemstate-changed" arrives over the named pipe.
  • Loading branch information
0xB10C committed Dec 5, 2019
1 parent b51899e commit aafd226
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions middleware/src/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@ func (middleware *Middleware) ipcNotificationLoop(reader *ipcnotification.Reader

for {
notification := <-notifications

if notification.Version != supportedNotificationVersion {
log.Printf("Dropping IPC notification with unsupported version: %s\n", notification.String())
log.Printf("Dropping an IPC notification with unsupported version: %s\n", notification.String())
}

log.Printf("Received notification with topic '%s': %v\n", notification.Topic, notification.Payload)

log.Printf("Received an IPC notification with topic '%s': %v\n", notification.Topic, notification.Payload)
switch notification.Topic {
case "mender-update":
if success, ok := ipcnotification.ParseMenderUpdatePayload(notification.Payload); ok {
Expand All @@ -289,8 +287,18 @@ func (middleware *Middleware) ipcNotificationLoop(reader *ipcnotification.Reader
} else {
log.Printf("Could not parse %s notification payload: %v\n", notification.Topic, notification.Payload)
}
case "systemstate-changed":
if middleware.hsmFirmware == nil {
log.Println("Received an IPC notification that the system state changed, but there is no HSM recognized. Not sending an extra HSM heartbeat.")
break
}
log.Println("Received an IPC notification that the system state changed. Sending an extra HSM heartbeat.")
err := middleware.hsmHeartbeat()
if err != nil {
log.Printf("Warning: error while sending a extra HSM heartbeat because the systemstate changed: %s\n", err)
}
default:
log.Printf("Dropping IPC notification with unknown topic: %s\n", notification.String())
log.Printf("Dropping an IPC notification with unknown topic: %s\n", notification.String())
}
}
}
Expand Down

0 comments on commit aafd226

Please sign in to comment.