UPDATE: Enhance macOS support with new build steps, add admin relaunch functionality, and improve proxy management
Build and Release / release (push) Failing after 41s
Build and Release / release (push) Failing after 41s
This commit is contained in:
@@ -7,7 +7,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func relaunchWithAdminIfNeeded() (bool, error) {
|
||||
@@ -25,11 +28,17 @@ func relaunchWithAdminIfNeeded() (bool, error) {
|
||||
return false, fmt.Errorf("get working directory: %w", err)
|
||||
}
|
||||
|
||||
wrapperPID := os.Getpid()
|
||||
launcherPID := os.Getppid()
|
||||
|
||||
args := make([]string, 0, len(os.Args))
|
||||
args = append(args, shellQuote(exePath))
|
||||
for _, arg := range os.Args[1:] {
|
||||
args = append(args, shellQuote(arg))
|
||||
}
|
||||
if !hasFlagArg("parent-pid") {
|
||||
args = append(args, shellQuote("-parent-pid"), shellQuote(strconv.Itoa(wrapperPID)))
|
||||
}
|
||||
|
||||
command := fmt.Sprintf(
|
||||
"cd %s && %s > /dev/null 2>&1 &",
|
||||
@@ -42,5 +51,27 @@ func relaunchWithAdminIfNeeded() (bool, error) {
|
||||
return false, formatCommandError("relaunch proxy as admin", err, out)
|
||||
}
|
||||
|
||||
waitForRelaunchedProxyShutdown(launcherPID)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func waitForRelaunchedProxyShutdown(launcherPID int) {
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
||||
defer signal.Stop(stop)
|
||||
|
||||
select {
|
||||
case <-stop:
|
||||
case <-parentProcessDone(launcherPID):
|
||||
}
|
||||
}
|
||||
|
||||
func hasFlagArg(name string) bool {
|
||||
for _, arg := range os.Args[1:] {
|
||||
trimmed := strings.TrimLeft(arg, "-")
|
||||
if trimmed == name || strings.HasPrefix(trimmed, name+"=") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user