show: make highlight legible
[debiancodesearch.git] / internal / addrfd / addrfd.go
blobaff9801e93ed925d29243017ddc8af763a7521eb
1 package addrfd
3 import (
4 "flag"
5 "log"
6 "os"
9 var (
10 addrfd = flag.Int("addrfd", -1, "File descriptor on which to print the picked address")
13 // MustWrite communicates listening address addr to the parent process via the
14 // file descriptor number passed to -addrfd, if any. It must be called precisely
15 // once.
16 func MustWrite(addr string) {
17 if *addrfd == -1 {
18 return
20 log.Printf("%s is listening on %s", os.Args[0], addr)
21 f := os.NewFile(uintptr(*addrfd), "")
22 if _, err := f.Write([]byte(addr)); err != nil {
23 log.Fatal(err)
25 if err := f.Close(); err != nil {
26 log.Fatal(err)