update signal handling

This commit is contained in:
xvzc 2022-01-04 17:38:36 +09:00
parent cf869fe9cd
commit 281a86dd32
2 changed files with 35 additions and 27 deletions

View File

@ -4,49 +4,57 @@ import (
"flag" "flag"
"log" "log"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/config"
"github.com/xvzc/SpoofDPI/proxy" "github.com/xvzc/SpoofDPI/proxy"
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
func main() { func main() {
port := flag.String("port", "8080", "port") port := flag.String("port", "8080", "port")
dns := flag.String("dns", "8.8.8.8", "DNS server") dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false") debug := flag.Bool("debug", false, "true | false")
flag.Parse() flag.Parse()
err := config.InitConfig(*port, *dns, *debug) err := config.InitConfig(*port, *dns, *debug)
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
} }
util.PrintWelcome() util.PrintWelcome()
err = config.SetOsProxy() err = config.SetOsProxy()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
os.Exit(1) os.Exit(1)
} }
go proxy.Start() go proxy.Start()
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
done := make(chan bool, 1) done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() { signal.Notify(
sigs,
syscall.SIGKILL,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGCONT,
syscall.SIGHUP)
go func() {
_ = <-sigs _ = <-sigs
done <- true done <- true
}() }()
<-done <-done
err = config.UnSetOsProxy() err = config.UnSetOsProxy()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
os.Exit(1) os.Exit(1)
} }
} }

BIN
spoof-dpi

Binary file not shown.