2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2023-08-30 12:23:38 +00:00
|
|
|
//go:build !windows && !wasm && !plan9 && !tamago
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
package filch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-02-14 07:56:39 +00:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func saveStderr() (*os.File, error) {
|
2020-02-14 07:56:39 +00:00
|
|
|
fd, err := unix.Dup(stderrFD)
|
2020-02-05 22:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return os.NewFile(uintptr(fd), "stderr"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unsaveStderr(f *os.File) error {
|
|
|
|
err := dup2Stderr(f)
|
|
|
|
f.Close()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func dup2Stderr(f *os.File) error {
|
2020-02-14 07:56:39 +00:00
|
|
|
return unix.Dup2(int(f.Fd()), stderrFD)
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|