diff --git a/cmds/portmaster-core/main_linux.go b/cmds/portmaster-core/main_linux.go index 8c7cc369..026cd249 100644 --- a/cmds/portmaster-core/main_linux.go +++ b/cmds/portmaster-core/main_linux.go @@ -6,7 +6,6 @@ import ( "os" "os/exec" "os/signal" - "strings" "syscall" "time" @@ -113,17 +112,15 @@ func runServiceRestart() error { restartCommand, exists := os.LookupEnv("PORTMASTER_RESTART_COMMAND") // Run the service restart + var cmd *exec.Cmd if exists && restartCommand != "" { log.Debugf(`instance: running custom restart command: "%s"`, restartCommand) - commandSplit := strings.Split(restartCommand, " ") - cmd := exec.Command(commandSplit[0], commandSplit[1:]...) - _ = cmd.Run() + cmd = exec.Command("sh", "-c", restartCommand) } else { - cmd := exec.Command("systemctl", "restart", "portmaster") - if err := cmd.Start(); err != nil { - return fmt.Errorf("failed run restart command: %w", err) - } - + cmd = exec.Command("systemctl", "restart", "portmaster") + } + if err := cmd.Start(); err != nil { + return fmt.Errorf("failed run restart command: %w", err) } return nil } diff --git a/cmds/portmaster-core/main_windows.go b/cmds/portmaster-core/main_windows.go index 63cc22ff..8e0d9a6d 100644 --- a/cmds/portmaster-core/main_windows.go +++ b/cmds/portmaster-core/main_windows.go @@ -47,7 +47,7 @@ service: changes <- svc.Status{State: svc.StopPending} ws.instance.Shutdown() default: - log.Errorf("unexpected control request: #%d", c) + log.Errorf("unexpected control request: %+v", c) } } } diff --git a/desktop/tauri/src-tauri/templates/nsis_install_hooks.nsh b/desktop/tauri/src-tauri/templates/nsis_install_hooks.nsh index a162a45d..b2ddd628 100644 --- a/desktop/tauri/src-tauri/templates/nsis_install_hooks.nsh +++ b/desktop/tauri/src-tauri/templates/nsis_install_hooks.nsh @@ -25,11 +25,15 @@ !macroend !macro NSIS_HOOK_POSTINSTALL - ExecWait 'sc.exe create PortmasterCore binPath= "$INSTDIR\portmaster-core.exe" --data="$COMMONPROGRAMDATA\Portmaster\data"' + ExecWait 'sc.exe create PortmasterCore binPath= "$INSTDIR\portmaster-core.exe" --data="$COMMONPROGRAMDATA\Portmaster\data"' $0 + IntCmp $0 0 +2 + MessageBox MB_OK "Failed to create PortmasterCore service." !macroend !macro NSIS_HOOK_PREUNINSTALL - ExecWait 'sc.exe stop PortmasterCore' - ExecWait 'sc.exe delete PortmasterCore' + ExecWait 'sc.exe stop PortmasterCore' $0 + ; Ignore errors if the service is not running + ExecWait 'sc.exe delete PortmasterCore' $0 + ; Ignore errors if the service does not exist !macroend diff --git a/service/updates/bundle.go b/service/updates/bundle.go index 1ffe2abc..64ffc2a1 100644 --- a/service/updates/bundle.go +++ b/service/updates/bundle.go @@ -120,9 +120,12 @@ func checkIfFileIsValid(filename string, artifact Artifact) (bool, error) { defer func() { _ = file.Close() }() providedHash, err := hex.DecodeString(artifact.SHA256) - if err != nil || len(providedHash) != sha256.Size { + if err != nil { return false, fmt.Errorf("invalid provided hash %s: %w", artifact.SHA256, err) } + if len(providedHash) != sha256.Size { + return false, fmt.Errorf("invalid hash length for %s", artifact.SHA256) + } // Calculate hash of the file fileHash := sha256.New() diff --git a/service/updates/downloader.go b/service/updates/downloader.go index 53ad2d8d..130265be 100644 --- a/service/updates/downloader.go +++ b/service/updates/downloader.go @@ -181,7 +181,7 @@ func (d *Downloader) downloadAndVerify(ctx context.Context) error { // Make sure we have the bundle file parsed. err := d.parseBundle() if err != nil { - log.Errorf("updates: invalid update bundle file: %s", err) + return fmt.Errorf("invalid update bundle file: %w", err) } // Make sure dir exists diff --git a/spn/navigator/module_test.go b/spn/navigator/module_test.go index c0de9194..d02e1e5d 100644 --- a/spn/navigator/module_test.go +++ b/spn/navigator/module_test.go @@ -24,7 +24,7 @@ type testInstance struct { geoip *geoip.GeoIP } -func (stub *testInstance) Updates() *updates.Updates { +func (stub *testInstance) IntelUpdates() *updates.Updates { return stub.updates } @@ -78,7 +78,7 @@ func runTest(m *testing.M) error { if err != nil { return fmt.Errorf("failed to create config: %w", err) } - stub.updates, err = updates.New(stub) + stub.updates, err = updates.New(stub, "Intel Test", updates.UpdateIndex{}) if err != nil { return fmt.Errorf("failed to create updates: %w", err) }