optimize quit logic

This commit is contained in:
p_caiwfeng
2021-10-04 22:29:26 +08:00
parent 0a675ec17f
commit ef5541eca4

View File

@@ -7,15 +7,23 @@ import (
log "github.com/sirupsen/logrus"
"os"
"os/exec"
"os/signal"
"syscall"
)
// TODO optimize while send single CRTL+C, command will quit immediately, but output will cutoff and print util quit final
func RunWithElevated() {
cmd := exec.Command("sudo", os.Args...)
log.Info(cmd.Args)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
// while send single CRTL+C, command will quit immediately, but output will cut off and print util quit final
// so, mute single CTRL+C, let inner command handle single only
go func() {
signals := make(chan os.Signal)
signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGSTOP)
<-signals
}()
err := cmd.Run()
if err != nil {
log.Warn(err)