Implement review comments

This commit is contained in:
Patrick Pacher
2020-07-17 11:07:46 +02:00
parent 7690793c66
commit 6d69039c20
6 changed files with 49 additions and 47 deletions

View File

@@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"time"
"github.com/safing/portbase/container"
@@ -113,18 +112,6 @@ func logControlError(cErr error) {
fmt.Fprintln(errorFile, cErr.Error())
}
//nolint:deadcode,unused // TODO
func logControlStack() {
fp := getPmStartLogFile(".stack.log")
if fp == nil {
return
}
defer fp.Close()
// write error and close
_ = pprof.Lookup("goroutine").WriteTo(fp, 2)
}
//nolint:deadcode,unused // false positive on linux, currently used by windows only
func runAndLogControlError(wrappedFunc func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {

View File

@@ -75,15 +75,6 @@ func main() {
// set meta info
info.Set("Portmaster Start", "0.3.5", "AGPLv3", false)
// for debugging
// log.Start()
// log.SetLogLevel(log.TraceLevel)
// go func() {
// time.Sleep(3 * time.Second)
// pprof.Lookup("goroutine").WriteTo(os.Stdout, 2)
// os.Exit(1)
// }()
// catch interrupt for clean shutdown
signalCh := make(chan os.Signal, 2)
signal.Notify(
@@ -103,13 +94,6 @@ func main() {
os.Exit(0)
}()
// for debugging windows service (no stdout/err)
// go func() {
// time.Sleep(10 * time.Second)
// // initiateShutdown(nil)
// // logControlStack()
// }()
// wait for signals
for sig := range signalCh {
if childIsRunning.IsSet() {

View File

@@ -100,7 +100,7 @@ func getExecArgs(opts *Options, cmdArgs []string) []string {
args := []string{"--data", dataDir}
if stdinSignals {
args = append(args, "-input-signals")
args = append(args, "--input-signals")
}
args = append(args, cmdArgs...)
return args
@@ -110,7 +110,7 @@ func run(opts *Options, cmdArgs []string) (err error) {
// set download option
registry.Online = opts.AllowDownload
if isShutdown() {
if isShuttingDown() {
return nil
}
@@ -328,8 +328,7 @@ func execute(opts *Options, args []string) (cont bool, err error) {
// wait until shut down
select {
case <-finished:
case <-time.After(11 * time.Second): // portmaster core prints stack if not able to shutdown in 10 seconds
// kill
case <-time.After(3 * time.Minute): // portmaster core prints stack if not able to shutdown in 3 minutes, give it one more ...
err = exc.Process.Kill()
if err != nil {
return false, fmt.Errorf("failed to kill %s: %s", opts.Identifier, err)

View File

@@ -25,7 +25,7 @@ func initiateShutdown(err error) {
}
}
func isShutdown() bool {
func isShuttingDown() bool {
select {
case <-shuttingDown:
return true

View File

@@ -40,7 +40,15 @@ func downloadUpdates() error {
}
}
// ok, now we want logging.
// add updates that we require on all platforms.
registry.MandatoryUpdates = append(
registry.MandatoryUpdates,
"all/ui/modules/base.zip",
)
// logging is configured as a presistent pre-run method inherited from
// the root command but since we don't use run.Run() we need to start
// logging ourself.
err := log.Start()
if err != nil {
fmt.Printf("failed to start logging: %s\n", err)