mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
A new VM can get network policy: --network-policy, else a question in a terminal (no by default), else off. devvm makes its CA, writes the VM's secret bindings, starts the VM's proxy (devvm _proxy, its password in a file) and starts the VM confined to it, then runs the self-check before the setup and the shell: a VM that isn't held to its proxy is stopped. Tokens stay on the host; the hidden devvm secret get reads them for the proxy, from the Keychain or a file. e2e gets a network section. Co-Authored-By: Claude Opus 5.5 <[email protected]>
41 lines
948 B
Go
41 lines
948 B
Go
package platform
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"errors"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// ProcessArgs returns a running process's arguments, its program's name
|
|
// first, from the kernel (kern.procargs2).
|
|
func ProcessArgs(pid int) ([]string, error) {
|
|
b, err := unix.SysctlRaw("kern.procargs2", pid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// argc, the executable's path, NUL padding, then argc NUL-ended
|
|
// arguments (the environment follows).
|
|
if len(b) < 4 {
|
|
return nil, errors.New("short kern.procargs2")
|
|
}
|
|
argc := int(binary.LittleEndian.Uint32(b[:4]))
|
|
rest := b[4:]
|
|
i := bytes.IndexByte(rest, 0)
|
|
if i < 0 {
|
|
return nil, errors.New("bad kern.procargs2")
|
|
}
|
|
rest = bytes.TrimLeft(rest[i:], "\x00")
|
|
args := make([]string, 0, argc)
|
|
for range argc {
|
|
j := bytes.IndexByte(rest, 0)
|
|
if j < 0 {
|
|
return nil, errors.New("bad kern.procargs2")
|
|
}
|
|
args = append(args, string(rest[:j]))
|
|
rest = rest[j+1:]
|
|
}
|
|
return args, nil
|
|
}
|