notify.go 1.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package restore

import (
	criu "github.com/checkpoint-restore/go-criu/v7"
	"github.com/sirupsen/logrus"
)

// RestoreNotify implements criu.Notify for restore callbacks.
// It captures the restored process PID from the PostRestore callback.
type RestoreNotify struct {
	criu.NoNotify // Embed no-op implementation for all methods

	// RestoredPID is the PID of the restored process, set by PostRestore callback
	RestoredPID int32

	// log is the logger for notification events
	log *logrus.Entry
}

// NewRestoreNotify creates a new RestoreNotify handler.
func NewRestoreNotify(log *logrus.Entry) *RestoreNotify {
	return &RestoreNotify{
		log: log,
	}
}

// PreRestore is called before CRIU starts the restore operation.
func (n *RestoreNotify) PreRestore() error {
	if n.log != nil {
		n.log.Debug("CRIU pre-restore notification")
	}
	return nil
}

// PostRestore is called after CRIU completes the restore operation.
// The pid parameter contains the PID of the restored process.
func (n *RestoreNotify) PostRestore(pid int32) error {
	n.RestoredPID = pid
	if n.log != nil {
		n.log.WithField("pid", pid).Info("CRIU post-restore notification: process restored")
	}
	return nil
}

// PostResume is called after the restored process has resumed execution.
func (n *RestoreNotify) PostResume() error {
	if n.log != nil {
		n.log.Debug("CRIU post-resume notification")
	}
	return nil
}