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

Commit aafd226

Browse files
committed
add: send a HSM heartbeat on IPC notification
This adds an extra HSM heartbeat that is send when a IPC notification with the topic "systemstate-changed" arrives over the named pipe.
1 parent b51899e commit aafd226

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

middleware/src/middleware.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,11 @@ func (middleware *Middleware) ipcNotificationLoop(reader *ipcnotification.Reader
264264

265265
for {
266266
notification := <-notifications
267-
268267
if notification.Version != supportedNotificationVersion {
269-
log.Printf("Dropping IPC notification with unsupported version: %s\n", notification.String())
268+
log.Printf("Dropping an IPC notification with unsupported version: %s\n", notification.String())
270269
}
271270

272-
log.Printf("Received notification with topic '%s': %v\n", notification.Topic, notification.Payload)
273-
271+
log.Printf("Received an IPC notification with topic '%s': %v\n", notification.Topic, notification.Payload)
274272
switch notification.Topic {
275273
case "mender-update":
276274
if success, ok := ipcnotification.ParseMenderUpdatePayload(notification.Payload); ok {
@@ -289,8 +287,18 @@ func (middleware *Middleware) ipcNotificationLoop(reader *ipcnotification.Reader
289287
} else {
290288
log.Printf("Could not parse %s notification payload: %v\n", notification.Topic, notification.Payload)
291289
}
290+
case "systemstate-changed":
291+
if middleware.hsmFirmware == nil {
292+
log.Println("Received an IPC notification that the system state changed, but there is no HSM recognized. Not sending an extra HSM heartbeat.")
293+
break
294+
}
295+
log.Println("Received an IPC notification that the system state changed. Sending an extra HSM heartbeat.")
296+
err := middleware.hsmHeartbeat()
297+
if err != nil {
298+
log.Printf("Warning: error while sending a extra HSM heartbeat because the systemstate changed: %s\n", err)
299+
}
292300
default:
293-
log.Printf("Dropping IPC notification with unknown topic: %s\n", notification.String())
301+
log.Printf("Dropping an IPC notification with unknown topic: %s\n", notification.String())
294302
}
295303
}
296304
}

0 commit comments

Comments
 (0)