From 35c7f4955bdcf90d261e7200adade5b1f4b18b5b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 25 Oct 2019 13:37:11 +0200 Subject: [PATCH] Remove dnsonly and adapt main to new convenience method --- dnsonly.go | 55 -------------------------- main.go | 114 +++++------------------------------------------------ 2 files changed, 9 insertions(+), 160 deletions(-) delete mode 100644 dnsonly.go diff --git a/dnsonly.go b/dnsonly.go deleted file mode 100644 index 556a6c79..00000000 --- a/dnsonly.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "fmt" - "os" - "os/signal" - "runtime" - "syscall" - - "github.com/safing/portbase/info" - "github.com/safing/portbase/log" - "github.com/safing/portbase/modules" - - // include packages here - _ "github.com/safing/portmaster/nameserver/only" -) - -func main() { - - runtime.GOMAXPROCS(4) - - // Set Info - info.Set("Portmaster (DNS only)", "0.2.0", "AGPLv3", false) - - // Start - err := modules.Start() - if err != nil { - if err == modules.ErrCleanExit { - os.Exit(0) - } else { - modules.Shutdown() - os.Exit(1) - } - } - - // Shutdown - // catch interrupt for clean shutdown - signalCh := make(chan os.Signal) - signal.Notify( - signalCh, - os.Interrupt, - syscall.SIGHUP, - syscall.SIGINT, - syscall.SIGTERM, - syscall.SIGQUIT, - ) - select { - case <-signalCh: - fmt.Println(" ") - log.Warning("main: program was interrupted, shutting down.") - modules.Shutdown() - case <-modules.ShuttingDown(): - } - -} diff --git a/main.go b/main.go index 8e76d615..3bb1b903 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,10 @@ package main import ( - "bufio" - "flag" - "fmt" "os" - "os/signal" - "runtime/pprof" - "syscall" - "time" "github.com/safing/portbase/info" - "github.com/safing/portbase/log" - "github.com/safing/portbase/modules" + "github.com/safing/portbase/run" // include packages here _ "github.com/safing/portmaster/core" @@ -21,102 +13,14 @@ import ( _ "github.com/safing/portmaster/ui" ) -var ( - printStackOnExit bool - enableInputSignals bool -) - -func init() { - flag.BoolVar(&printStackOnExit, "print-stack-on-exit", false, "prints the stack before of shutting down") - flag.BoolVar(&enableInputSignals, "input-signals", false, "emulate signals using stdin") -} - func main() { - // Set Info + /*go func() { + time.Sleep(10 * time.Second) + fmt.Fprintln(os.Stderr, "===== TAKING TOO LONG FOR SHUTDOWN - PRINTING STACK TRACES =====") + _ = pprof.Lookup("goroutine").WriteTo(os.Stderr, 2) + os.Exit(1) + }()*/ + info.Set("Portmaster", "0.3.9", "AGPLv3", true) - - // Start - err := modules.Start() - if err != nil { - if err == modules.ErrCleanExit { - os.Exit(0) - } else { - modules.Shutdown() - os.Exit(1) - } - } - - // Shutdown - // catch interrupt for clean shutdown - signalCh := make(chan os.Signal) - if enableInputSignals { - go inputSignals(signalCh) - } - signal.Notify( - signalCh, - os.Interrupt, - os.Kill, - syscall.SIGHUP, - syscall.SIGINT, - syscall.SIGTERM, - syscall.SIGQUIT, - ) - select { - case <-signalCh: - - fmt.Println(" ") - log.Warning("main: program was interrupted, shutting down.") - - // catch signals during shutdown - go func() { - for { - <-signalCh - fmt.Println(" again, but already shutting down") - } - }() - - if printStackOnExit { - fmt.Println("=== PRINTING TRACES ===") - fmt.Println("=== GOROUTINES ===") - pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - fmt.Println("=== BLOCKING ===") - pprof.Lookup("block").WriteTo(os.Stdout, 1) - fmt.Println("=== MUTEXES ===") - pprof.Lookup("mutex").WriteTo(os.Stdout, 1) - fmt.Println("=== END TRACES ===") - } - - go func() { - time.Sleep(10 * time.Second) - fmt.Fprintln(os.Stderr, "===== TAKING TOO LONG FOR SHUTDOWN - PRINTING STACK TRACES =====") - pprof.Lookup("goroutine").WriteTo(os.Stderr, 1) - os.Exit(1) - }() - - err := modules.Shutdown() - if err != nil { - os.Exit(1) - } else { - os.Exit(0) - } - - case <-modules.ShuttingDown(): - } - -} - -func inputSignals(signalCh chan os.Signal) { - scanner := bufio.NewScanner(os.Stdin) - for scanner.Scan() { - switch scanner.Text() { - case "SIGHUP": - signalCh <- syscall.SIGHUP - case "SIGINT": - signalCh <- syscall.SIGINT - case "SIGQUIT": - signalCh <- syscall.SIGQUIT - case "SIGTERM": - signalCh <- syscall.SIGTERM - } - } + os.Exit(run.Run()) }