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.
|
|
|
|
|
2022-08-03 23:15:21 +00:00
|
|
|
//go:build !windows && !js
|
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
|
|
|
}
|