Commit db8da281 authored by Zoey Greer's avatar Zoey Greer Committed by Han-Wen Nienhuys

fuse: reserve fd without opening /dev/null

This enables using go-fuse in a init binary that is spawned directly from
the kernel.

See also https://github.com/hanwen/go-fuse/pull/525.

Change-Id: Ibbaa04af993677536bd4ae8a173a5a6d93118940
parent 76685c77
...@@ -18,15 +18,16 @@ func init() { ...@@ -18,15 +18,16 @@ func init() {
// completely foolproof: a preceding init routine could grab fd 3, // completely foolproof: a preceding init routine could grab fd 3,
// and then release it later.) // and then release it later.)
for { for {
f, err := os.Open(os.DevNull) r, w, err := os.Pipe()
if err != nil { if err != nil {
panic(fmt.Sprintf("open(%q): %v", os.DevNull, err)) panic(fmt.Sprintf("os.Pipe(): %v", err))
} }
if f.Fd() > 3 { w.Close()
f.Close() if r.Fd() > 3 {
r.Close()
break break
} }
reservedFDs = append(reservedFDs, f) reservedFDs = append(reservedFDs, r)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment