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

Commit 1ba783f

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 4052a06 commit 1ba783f

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 {
@@ -293,8 +291,18 @@ func (middleware *Middleware) ipcNotificationLoop(reader *ipcnotification.Reader
293291
} else {
294292
log.Printf("Could not parse %s notification payload: %v\n", notification.Topic, notification.Payload)
295293
}
294+
case "systemstate-changed":
295+
if middleware.hsmFirmware == nil {
296+
log.Println("Received an IPC notification that the system state changed, but there is no HSM recognized. Not sending an extra HSM heartbeat.")
297+
break
298+
}
299+
log.Println("Received an IPC notification that the system state changed. Sending an extra HSM heartbeat.")
300+
err := middleware.hsmHeartbeat()
301+
if err != nil {
302+
log.Printf("Warning: error while sending a extra HSM heartbeat because the systemstate changed: %s\n", err)
303+
}
296304
default:
297-
log.Printf("Dropping IPC notification with unknown topic: %s\n", notification.String())
305+
log.Printf("Dropping an IPC notification with unknown topic: %s\n", notification.String())
298306
}
299307
}
300308
}

0 commit comments

Comments
 (0)