Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

criu swrk: return child error to caller #175

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@
}

// Cleanup cleans up
func (c *Criu) Cleanup() {
func (c *Criu) Cleanup() error {
var errs []error
if c.swrkCmd != nil {
c.swrkSk.Close()
if err := c.swrkSk.Close(); err != nil {
errs = append(errs, err)

Check warning on line 68 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L68

Added line #L68 was not covered by tests
}
c.swrkSk = nil
_ = c.swrkCmd.Wait()
if err := c.swrkCmd.Wait(); err != nil {
errs = append(errs, fmt.Errorf("criu swrk failed: %w", err))

Check warning on line 72 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L72

Added line #L72 was not covered by tests
}
c.swrkCmd = nil
}
return errors.Join(errs...)
}

func (c *Criu) sendAndRecv(reqB []byte) ([]byte, int, error) {
Expand Down Expand Up @@ -99,9 +105,7 @@
return nil
}

func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy Notify, features *rpc.CriuFeatures) (*rpc.CriuResp, error) {
var resp *rpc.CriuResp

func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy Notify, features *rpc.CriuFeatures) (resp *rpc.CriuResp, retErr error) {
req := rpc.CriuReq{
Type: &reqType,
Opts: opts,
Expand All @@ -121,7 +125,13 @@
return nil, err
}

defer c.Cleanup()
defer func() {
// append any cleanup errors to the returned error
err := c.Cleanup()
if err != nil {
retErr = errors.Join(retErr, err)

Check warning on line 132 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L132

Added line #L132 was not covered by tests
}
}()
}

for {
Expand Down
11 changes: 9 additions & 2 deletions phaul/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package phaul

import (
"errors"
"fmt"

"github.com/checkpoint-restore/go-criu/v7"
Expand Down Expand Up @@ -55,7 +56,7 @@
}

// Migrate function
func (pc *Client) Migrate() error {
func (pc *Client) Migrate() (retErr error) {
criu := criu.MakeCriu()
psi := rpc.CriuPageServerInfo{
Fd: proto.Int32(int32(pc.cfg.Memfd)),
Expand All @@ -72,7 +73,13 @@
return err
}

defer criu.Cleanup()
defer func() {
// append any cleanup errors to the returned error
err := criu.Cleanup()
if err != nil {
retErr = errors.Join(retErr, err)

Check warning on line 80 in phaul/client.go

View check run for this annotation

Codecov / codecov/patch

phaul/client.go#L80

Added line #L80 was not covered by tests
}
}()

imgs, err := preparePhaulImages(pc.cfg.Wdir)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ func main() {
log.Fatalln("dump failed: ", err)
}

c.Cleanup()
err = c.Cleanup()
if err != nil {
log.Fatalln("cleanup failed: ", err)
}
case "restore":
log.Println("Restoring")
img, err := os.Open(os.Args[2])
Expand Down
Loading