Exemple
golang.org/x/sys v0.31.0: unix.O_CLOEXEC
Échantillon vérifié pour golang golang.org/x/sys v0.31.0: unix.O_CLOEXEC. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.
sha256:29351663cb3f5cc15f11ac2e3d667c9ae3427a62a9a0ef0f277b2b61d80fde3e
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify golang.org/x/sys/unix.O_CLOEXEC in pkg:golang/golang.org/x/sys@v0.31.0
- Paquets
- Symboles
-
- golang.org/x/sys/unix.O_CLOEXEC
- Créé
- 2026-08-30T16:42:34Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Code source
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")
}
Seeder d'origine
anonyme