syscall_ptrace_test.go 768 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
  5. package syscall_test
  6. import (
  7. "internal/testenv"
  8. "os"
  9. "os/exec"
  10. "syscall"
  11. "testing"
  12. )
  13. func TestExecPtrace(t *testing.T) {
  14. testenv.MustHaveExec(t)
  15. bin, err := exec.LookPath("sh")
  16. if err != nil {
  17. t.Skipf("skipped because sh is not available")
  18. }
  19. attr := &os.ProcAttr{
  20. Sys: &syscall.SysProcAttr{
  21. Ptrace: true,
  22. },
  23. }
  24. proc, err := os.StartProcess(bin, []string{bin}, attr)
  25. if err == nil {
  26. proc.Kill()
  27. }
  28. if err != nil && !os.IsPermission(err) {
  29. t.Fatalf("StartProcess with ptrace enabled failed: %v", err)
  30. }
  31. }