Skip to content

Commit

Permalink
Merge pull request #9912 from mvo5/snap-run-gdbserver-early-error
Browse files Browse the repository at this point in the history
snap: provide a useful error message if gdbserver is not installed
  • Loading branch information
mvo5 authored Feb 16, 2021
2 parents 9c4eac8 + 06b2607 commit 75b3d4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/snap/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,16 @@ func (x *cmdRun) runSnapConfine(info *snap.Info, securityTag, snapApp, hook stri
} else if x.Gdb {
return x.runCmdUnderGdb(cmd, envForExec)
} else if x.useGdbserver() {
if _, err := exec.LookPath("gdbserver"); err != nil {
// TODO: use xerrors.Is(err, exec.ErrNotFound) once
// we moved off from go-1.9
if execErr, ok := err.(*exec.Error); ok {
if execErr.Err == exec.ErrNotFound {
return fmt.Errorf("please install gdbserver on your system")
}
}
return err
}
return x.runCmdUnderGdbserver(cmd, envForExec)
} else if x.useStrace() {
return x.runCmdUnderStrace(cmd, envForExec)
Expand Down
14 changes: 14 additions & 0 deletions cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,3 +1569,17 @@ func (s *RunSuite) TestSnapRunHookKernelImplicitBase(c *check.C) {
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42")
c.Check(nModel, check.Equals, 1)
}

func (s *RunSuite) TestRunGdbserverNoGdbserver(c *check.C) {
oldPath := os.Getenv("PATH")
os.Setenv("PATH", "/no-path:/really-not")
defer os.Setenv("PATH", oldPath)

defer mockSnapConfine(dirs.DistroLibExecDir)()
snaptest.MockSnapCurrent(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R("x2"),
})

_, err := snaprun.Parser(snaprun.Client()).ParseArgs([]string{"run", "--gdbserver", "snapname.app"})
c.Assert(err, check.ErrorMatches, "please install gdbserver on your system")
}

0 comments on commit 75b3d4d

Please sign in to comment.