2020-02-05 22:16:58 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-08-05 22:42:39 +00:00
|
|
|
//go:build !windows
|
|
|
|
// +build !windows
|
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
|
|
|
}
|