mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
optimize quit logic
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user