跳到主要内容

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

浏览文件

process_linux.go

43 行 · 919 B历史下载
1//go:build linux
2
3package containerenv
4
5import (
6 "context"
7 "errors"
8 "os"
9 "os/exec"
10 "syscall"
11 "time"
12
13 "golang.org/x/sys/unix"
14)
15
16func detachWorker(command *exec.Cmd) { command.SysProcAttr = &syscall.SysProcAttr{Setsid: true} }
17func tryLockRuntime(path string) (func(), error) {
18 file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0600)
19 if err != nil {
20 return nil, err
21 }
22 if err = unix.Flock(int(file.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil {
23 file.Close()
24 return nil, err
25 }
26 return func() { _ = unix.Flock(int(file.Fd()), unix.LOCK_UN); _ = file.Close() }, nil
27}
28func lockRuntime(ctx context.Context, path string) (func(), error) {
29 for {
30 unlock, err := tryLockRuntime(path)
31 if err == nil {
32 return unlock, nil
33 }
34 if !errors.Is(err, unix.EWOULDBLOCK) {
35 return nil, err
36 }
37 select {
38 case <-ctx.Done():
39 return nil, ctx.Err()
40 case <-time.After(100 * time.Millisecond):
41 }
42 }
43}