샘플
golang.org/x/sys v0.31.0: unix.O_CLOEXEC
검증된 샘플 — golang golang.org/x/sys v0.31.0: unix.O_CLOEXEC. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: unix.O_CLOEXEC is non-zero and opening…
sha256:29351663cb3f5cc15f11ac2e3d667c9ae3427a62a9a0ef0f277b2b61d80fde3e
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-30 |
케이스
HOW- 목표
- verify golang.org/x/sys/unix.O_CLOEXEC in pkg:golang/golang.org/x/sys@v0.31.0
- 심벌
-
- golang.org/x/sys/unix.O_CLOEXEC
- 생성일
- 2026-08-30T16:42:34Z
컨트랙트
- unix.O_CLOEXEC is non-zero and opening a file with unix.O_CLOEXEC sets the FD_CLOEXEC flag
- Opening a file without unix.O_CLOEXEC does not set the FD_CLOEXEC flag initially
- unix.Pipe2 with unix.O_CLOEXEC creates read and write file descriptors with FD_CLOEXEC set
- unix.Openat with unix.O_CLOEXEC opens relative file descriptors with FD_CLOEXEC set
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify golang.org/x/sys/unix.O_CLOEXEC in pkg:golang/golang.org/x/sys@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sys@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/sys/unix.O_CLOEXEC
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:21d52d174c3a939035944830a2cfaf7828a05d40d7382da9d810ebd7055f129f","contract":["unix.O_CLOEXEC is non-zero and opening a file with unix.O_CLOEXEC sets the FD_CLOEXEC flag","Opening a file without unix.O_CLOEXEC does not set the FD_CLOEXEC flag initially","unix.Pipe2 with unix.O_CLOEXEC creates read and write file descriptors with FD_CLOEXEC set","unix.Openat with unix.O_CLOEXEC opens relative file descriptors with FD_CLOEXEC set"],"goal":"verify golang.org/x/sys/unix.O_CLOEXEC in pkg:golang/golang.org/x/sys@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/sys/unix.O_CLOEXEC"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.31.0","symbols":["golang.org/x/sys/unix.O_CLOEXEC"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.23.0
require golang.org/x/sys v0.31.0
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
package main
import (
"fmt"
"os"
"path/filepath"
"golang.org/x/sys/unix"
)
// OpenWithCLOEXEC opens or creates a file with O_CLOEXEC flag set.
func OpenWithCLOEXEC(path string, flags int, mode uint32) (int, error) {
fd, err := unix.Open(path, flags|unix.O_CLOEXEC, mode)
if err != nil {
return -1, fmt.Errorf("unix.Open failed: %w", err)
}
return fd, nil
}
// IsCloseOnExec checks whether the FD_CLOEXEC flag is set on the given file descriptor.
func IsCloseOnExec(fd int) (bool, error) {
flags, err := unix.FcntlInt(uintptr(fd), unix.F_GETFD, 0)
if err != nil {
return false, fmt.Errorf("unix.FcntlInt F_GETFD failed: %w", err)
}
return (flags & unix.FD_CLOEXEC) != 0, nil
}
// CreatePipeWithCLOEXEC creates a pipe with both ends having O_CLOEXEC set.
func CreatePipeWithCLOEXEC() ([2]int, error) {
var p [2]int
if err := unix.Pipe2(p[:], unix.O_CLOEXEC); err != nil {
return p, fmt.Errorf("unix.Pipe2 failed: %w", err)
}
return p, nil
}
func main() {
tmpDir, err := os.MkdirTemp("", "csx-cloexec-*")
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
filePath := filepath.Join(tmpDir, "example.txt")
// Open file with O_CLOEXEC
fd, err := OpenWithCLOEXEC(filePath, unix.O_RDWR|unix.O_CREAT|unix.O_TRUNC, 0600)
if err != nil {
fmt.Fprintf(os.Stderr, "Error opening file: %v\n", err)
os.Exit(1)
}
defer unix.Close(fd)
cloexec, err := IsCloseOnExec(fd)
if err != nil {
fmt.Fprintf(os.Stderr, "Error checking close-on-exec: %v\n", err)
os.Exit(1)
}
fmt.Printf("File opened with O_CLOEXEC (fd: %d, FD_CLOEXEC: %v)\n", fd, cloexec)
// Create pipe with O_CLOEXEC
pipeFds, err := CreatePipeWithCLOEXEC()
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating pipe: %v\n", err)
os.Exit(1)
}
defer unix.Close(pipeFds[0])
defer unix.Close(pipeFds[1])
rCLOEXEC, _ := IsCloseOnExec(pipeFds[0])
wCLOEXEC, _ := IsCloseOnExec(pipeFds[1])
fmt.Printf("Pipe created with O_CLOEXEC (read fd: %d, cloexec: %v; write fd: %d, cloexec: %v)\n",
pipeFds[0], rCLOEXEC, pipeFds[1], wCLOEXEC)
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sys/unix.O_CLOEXEC in pkg:golang/golang.org/x/sys@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sys@v0.31.0"
],
"symbols": [
"golang.org/x/sys/unix.O_CLOEXEC"
]
}
package main
import (
"fmt"
"os"
"path/filepath"
"golang.org/x/sys/unix"
)
func main() {
tmpDir, err := os.MkdirTemp("", "cloexec-contract-*")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
// Assertion 1: unix.O_CLOEXEC is non-zero and opening a file with unix.O_CLOEXEC sets the FD_CLOEXEC flag
if unix.O_CLOEXEC == 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected unix.O_CLOEXEC to be non-zero\n")
os.Exit(1)
}
testFile := filepath.Join(tmpDir, "cloexec.txt")
fdWithCloexec, err := unix.Open(testFile, unix.O_RDWR|unix.O_CREAT|unix.O_TRUNC|unix.O_CLOEXEC, 0600)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Open with unix.O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(fdWithCloexec)
flags1, err := unix.FcntlInt(uintptr(fdWithCloexec), unix.F_GETFD, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.FcntlInt F_GETFD failed: %v\n", err)
os.Exit(1)
}
if flags1&unix.FD_CLOEXEC == 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected FD_CLOEXEC flag to be set when opened with unix.O_CLOEXEC\n")
os.Exit(1)
}
// Assertion 2: Opening a file without unix.O_CLOEXEC does not set the FD_CLOEXEC flag initially
noCloexecFile := filepath.Join(tmpDir, "nocloexec.txt")
fdWithoutCloexec, err := unix.Open(noCloexecFile, unix.O_RDWR|unix.O_CREAT|unix.O_TRUNC, 0600)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Open without unix.O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(fdWithoutCloexec)
flags2, err := unix.FcntlInt(uintptr(fdWithoutCloexec), unix.F_GETFD, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.FcntlInt F_GETFD failed: %v\n", err)
os.Exit(1)
}
if flags2&unix.FD_CLOEXEC != 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected FD_CLOEXEC flag NOT to be set when opened without unix.O_CLOEXEC\n")
os.Exit(1)
}
// Assertion 3: unix.Pipe2 with unix.O_CLOEXEC creates read and write file descriptors with FD_CLOEXEC set
var pipeFds [2]int
if err := unix.Pipe2(pipeFds[:], unix.O_CLOEXEC); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 with unix.O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(pipeFds[0])
defer unix.Close(pipeFds[1])
readFlags, err := unix.FcntlInt(uintptr(pipeFds[0]), unix.F_GETFD, 0)
if err != nil || readFlags&unix.FD_CLOEXEC == 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected FD_CLOEXEC on pipe read fd: flags=%d, err=%v\n", readFlags, err)
os.Exit(1)
}
writeFlags, err := unix.FcntlInt(uintptr(pipeFds[1]), unix.F_GETFD, 0)
if err != nil || writeFlags&unix.FD_CLOEXEC == 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected FD_CLOEXEC on pipe write fd: flags=%d, err=%v\n", writeFlags, err)
os.Exit(1)
}
// Assertion 4: unix.Openat with unix.O_CLOEXEC opens relative file descriptors with FD_CLOEXEC set
dirFd, err := unix.Open(tmpDir, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Open directory with unix.O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(dirFd)
atFd, err := unix.Openat(dirFd, "cloexec_at.txt", unix.O_RDWR|unix.O_CREAT|unix.O_TRUNC|unix.O_CLOEXEC, 0600)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Openat with unix.O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(atFd)
atFlags, err := unix.FcntlInt(uintptr(atFd), unix.F_GETFD, 0)
if err != nil || atFlags&unix.FD_CLOEXEC == 0 {
fmt.Fprintf(os.Stderr, "FAIL: expected FD_CLOEXEC on openat fd: flags=%d, err=%v\n", atFlags, err)
os.Exit(1)
}
fmt.Println("PASS: golang.org/x/sys unix.O_CLOEXEC contract passed")
}
오리진 시더
익명