Beispiel
golang.org/x/sys v0.31.0: unix.Pipe2
Verifiziertes Beispiel für golang golang.org/x/sys v0.31.0: unix.Pipe2. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und bestand.
sha256:7f37935fc7bb95e07127d0bd4901045c3f11c2e6ffff01109b63a65c9e72efd4
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 go
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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 |
Fall
HOW- Ziel
- verify golang.org/x/sys/unix.Pipe2 in pkg:golang/golang.org/x/sys@v0.31.0
- Pakete
- Symbole
-
- golang.org/x/sys/unix.Pipe2
- Erstellt
- 2026-08-30T17:06:20Z
Contract
- unix.Pipe2 creates connected read and write file descriptors with default flags (0)
- unix.Pipe2 with unix.O_CLOEXEC sets the FD_CLOEXEC flag on both descriptors
- unix.Pipe2 with unix.O_NONBLOCK creates descriptors returning EAGAIN or EWOULDBLOCK on empty read
- unix.Pipe2 transfers data from write descriptor to read descriptor preserving byte integrity
- unix.Pipe2 returns EINVAL when provided a descriptor slice with length less than 2
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Quelltext
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.Pipe2 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.Pipe2
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:3135de5d2d5e829ba466ddec64658d6c29d5722a3b3d25c4e44164a42a9fb10f","contract":["unix.Pipe2 creates connected read and write file descriptors with default flags (0)","unix.Pipe2 with unix.O_CLOEXEC sets the FD_CLOEXEC flag on both descriptors","unix.Pipe2 with unix.O_NONBLOCK creates descriptors returning EAGAIN or EWOULDBLOCK on empty read","unix.Pipe2 transfers data from write descriptor to read descriptor preserving byte integrity","unix.Pipe2 returns EINVAL when provided a descriptor slice with length less than 2"],"goal":"verify golang.org/x/sys/unix.Pipe2 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.Pipe2"]},"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.Pipe2"],"verifierAdapter":"golang@1"}
module sample
go 1.25.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 (
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
// OpenPipe creates a pipe with the given flags using unix.Pipe2.
func OpenPipe(flags int) ([2]int, error) {
var fds [2]int
if err := unix.Pipe2(fds[:], flags); err != nil {
return fds, fmt.Errorf("pipe2 failed: %w", err)
}
return fds, nil
}
func main() {
// Create a non-blocking, close-on-exec pipe using unix.Pipe2
fds, err := OpenPipe(unix.O_CLOEXEC | unix.O_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating pipe: %v\n", err)
os.Exit(1)
}
defer unix.Close(fds[0])
defer unix.Close(fds[1])
// Attempt reading from empty non-blocking pipe
buf := make([]byte, 128)
n, err := unix.Read(fds[0], buf)
if err != nil && (errors.Is(err, unix.EAGAIN) || errors.Is(err, unix.EWOULDBLOCK)) {
fmt.Println("Confirmed non-blocking behavior: read returned EAGAIN/EWOULDBLOCK on empty pipe")
} else if err != nil {
fmt.Fprintf(os.Stderr, "Unexpected read error: %v\n", err)
os.Exit(1)
} else {
fmt.Fprintf(os.Stderr, "Unexpected read result: %d bytes\n", n)
os.Exit(1)
}
// Write data through the write end
message := []byte("hello from unix.Pipe2")
wn, err := unix.Write(fds[1], message)
if err != nil || wn != len(message) {
fmt.Fprintf(os.Stderr, "Write failed: %v\n", err)
os.Exit(1)
}
// Read data from the read end
rn, err := unix.Read(fds[0], buf)
if err != nil || rn != len(message) {
fmt.Fprintf(os.Stderr, "Read failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Successfully transferred %d bytes: %s\n", rn, string(buf[:rn]))
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sys/unix.Pipe2 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.Pipe2"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
func main() {
// Assertion 1: unix.Pipe2 creates connected read and write file descriptors with default flags (0)
var defaultFds [2]int
if err := unix.Pipe2(defaultFds[:], 0); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 with flag 0 failed: %v\n", err)
os.Exit(1)
}
if defaultFds[0] < 0 || defaultFds[1] < 0 {
fmt.Fprintf(os.Stderr, "FAIL: invalid descriptors returned: %v\n", defaultFds)
os.Exit(1)
}
_ = unix.Close(defaultFds[0])
_ = unix.Close(defaultFds[1])
// Assertion 2: unix.Pipe2 with unix.O_CLOEXEC sets the FD_CLOEXEC flag on both descriptors
var cloexecFds [2]int
if err := unix.Pipe2(cloexecFds[:], unix.O_CLOEXEC); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 with O_CLOEXEC failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(cloexecFds[0])
defer unix.Close(cloexecFds[1])
for i, fd := range cloexecFds {
flags, err := unix.FcntlInt(uintptr(fd), unix.F_GETFD, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: fcntl F_GETFD on fd %d failed: %v\n", fd, err)
os.Exit(1)
}
if (flags & unix.FD_CLOEXEC) == 0 {
fmt.Fprintf(os.Stderr, "FAIL: FD_CLOEXEC not set on fd index %d (%d)\n", i, fd)
os.Exit(1)
}
}
// Assertion 3: unix.Pipe2 with unix.O_NONBLOCK creates descriptors returning EAGAIN or EWOULDBLOCK on empty read
var nbFds [2]int
if err := unix.Pipe2(nbFds[:], unix.O_NONBLOCK); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: unix.Pipe2 with O_NONBLOCK failed: %v\n", err)
os.Exit(1)
}
defer unix.Close(nbFds[0])
defer unix.Close(nbFds[1])
fl, err := unix.FcntlInt(uintptr(nbFds[0]), unix.F_GETFL, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: fcntl F_GETFL failed: %v\n", err)
os.Exit(1)
}
if (fl & unix.O_NONBLOCK) == 0 {
fmt.Fprintf(os.Stderr, "FAIL: O_NONBLOCK flag not set on read fd\n")
os.Exit(1)
}
buf := make([]byte, 64)
n, err := unix.Read(nbFds[0], buf)
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL: expected EAGAIN/EWOULDBLOCK on empty read, got %d bytes\n", n)
os.Exit(1)
}
if !errors.Is(err, unix.EAGAIN) && !errors.Is(err, unix.EWOULDBLOCK) {
fmt.Fprintf(os.Stderr, "FAIL: expected EAGAIN or EWOULDBLOCK, got %v\n", err)
os.Exit(1)
}
// Assertion 4: unix.Pipe2 transfers data from write descriptor to read descriptor preserving byte integrity
payload := []byte("pipe2-contract-test-data-12345")
wn, err := unix.Write(nbFds[1], payload)
if err != nil || wn != len(payload) {
fmt.Fprintf(os.Stderr, "FAIL: write to pipe failed: wn=%d, err=%v\n", wn, err)
os.Exit(1)
}
readBuf := make([]byte, 64)
rn, err := unix.Read(nbFds[0], readBuf)
if err != nil || rn != len(payload) || !bytes.Equal(readBuf[:rn], payload) {
fmt.Fprintf(os.Stderr, "FAIL: read verification failed: rn=%d, err=%v, data=%q\n", rn, err, string(readBuf[:rn]))
os.Exit(1)
}
// Assertion 5: unix.Pipe2 returns EINVAL when provided a descriptor slice with length less than 2
shortSlice := make([]int, 1)
if err := unix.Pipe2(shortSlice, 0); !errors.Is(err, unix.EINVAL) {
fmt.Fprintf(os.Stderr, "FAIL: expected EINVAL for slice length < 2, got: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: all contract assertions passed")
}
Ursprungs-Seeder
anonym