跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

osutil_unix.go

49 行 · 1.1 KB历史下载
1//go:build !windows
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package osutil
7
8import (
9 "bytes"
10 "context"
11 "errors"
12 "fmt"
13 "os"
14 "os/exec"
15 "strings"
16 "syscall"
17
18 "golang.org/x/sys/unix"
19)
20
21func Dup2(oldfd, newfd int) (err error) {
22 return unix.Dup2(oldfd, newfd)
23}
24
25func SignalName(sig os.Signal) string {
26 return unix.SignalName(sig.(syscall.Signal))
27}
28
29func Sysctl(ctx context.Context, name string) (string, error) {
30 var stderrBuf bytes.Buffer
31 cmd := exec.CommandContext(ctx, "sysctl", "-n", name)
32 cmd.Stderr = &stderrBuf
33 stdout, err := cmd.Output()
34 if err != nil {
35 return "", fmt.Errorf("failed to run %v: %w (stdout=%#q, stderr=%#q)", cmd.Args, err,
36 string(stdout), stderrBuf.String())
37 }
38 return strings.TrimSuffix(string(stdout), "\n"), nil
39}
40
41func IsEACCES(err error) bool {
42 return errors.Is(err, unix.EACCES)
43}
44
45// ProcessAlive reports whether the process with the given PID is still running.
46func ProcessAlive(pid int) bool {
47 err := syscall.Kill(pid, 0)
48 return err == nil || errors.Is(err, syscall.EPERM)
49}