Source file src/syscall/syscall_ptrace_test.go

     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  
     5  //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
     6  
     7  package syscall_test
     8  
     9  import (
    10  	"internal/testenv"
    11  	"os"
    12  	"os/exec"
    13  	"syscall"
    14  	"testing"
    15  )
    16  
    17  func TestExecPtrace(t *testing.T) {
    18  	testenv.MustHaveExec(t)
    19  
    20  	bin, err := exec.LookPath("sh")
    21  	if err != nil {
    22  		t.Skipf("skipped because sh is not available")
    23  	}
    24  
    25  	attr := &os.ProcAttr{
    26  		Sys: &syscall.SysProcAttr{
    27  			Ptrace: true,
    28  		},
    29  	}
    30  	proc, err := os.StartProcess(bin, []string{bin}, attr)
    31  	if err == nil {
    32  		proc.Kill()
    33  	}
    34  	if err != nil && !os.IsPermission(err) {
    35  		t.Fatalf("StartProcess with ptrace enabled failed: %v", err)
    36  	}
    37  }
    38  

View as plain text