github.com/divyam234/rclone@v1.64.1/fs/log/redirect_stderr_unix.go (about)

     1  // Log the panic under unix to the log file
     2  
     3  //go:build !windows && !solaris && !plan9 && !js
     4  // +build !windows,!solaris,!plan9,!js
     5  
     6  package log
     7  
     8  import (
     9  	"log"
    10  	"os"
    11  
    12  	"github.com/divyam234/rclone/fs/config"
    13  	"golang.org/x/sys/unix"
    14  )
    15  
    16  // redirectStderr to the file passed in
    17  func redirectStderr(f *os.File) {
    18  	passPromptFd, err := unix.Dup(int(os.Stderr.Fd()))
    19  	if err != nil {
    20  		log.Fatalf("Failed to duplicate stderr: %v", err)
    21  	}
    22  	config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt")
    23  	err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
    24  	if err != nil {
    25  		log.Fatalf("Failed to redirect stderr to file: %v", err)
    26  	}
    27  }