From 004dd211e7fdd3f8e642886f40eee35415859021 Mon Sep 17 00:00:00 2001 From: Denis Vaumoron Date: Fri, 25 Oct 2024 17:54:02 +0200 Subject: [PATCH] specialize to avoid missing pgid error on windows (#272) Signed-off-by: Denis Vaumoron --- versionmanager/proxy/detached_others.go | 45 ++++++++++++++++++++++++ versionmanager/proxy/detached_windows.go | 35 ++++++++++++++++++ versionmanager/proxy/proxy.go | 18 ---------- 3 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 versionmanager/proxy/detached_others.go create mode 100644 versionmanager/proxy/detached_windows.go diff --git a/versionmanager/proxy/detached_others.go b/versionmanager/proxy/detached_others.go new file mode 100644 index 0000000..48bd060 --- /dev/null +++ b/versionmanager/proxy/detached_others.go @@ -0,0 +1,45 @@ +//go:build !windows + +/* + * + * Copyright 2024 tofuutils authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package proxy + +import ( + "fmt" + "os/exec" + "syscall" + + configutils "github.com/tofuutils/tenv/v3/config/utils" +) + +func initDetachedBehaviorFromEnv(cmd *exec.Cmd) { + detached, err := configutils.GetenvBool(false, "TENV_DETACHED_PROXY") + if err != nil { + fmt.Println("Failed to read TENV_DETACHED_PROXY environment variable, disable behavior :", err) //nolint + } + if !detached { + return + } + + if cmd.SysProcAttr == nil { + cmd.SysProcAttr = &syscall.SysProcAttr{} + } + + cmd.SysProcAttr.Setpgid = true +} diff --git a/versionmanager/proxy/detached_windows.go b/versionmanager/proxy/detached_windows.go new file mode 100644 index 0000000..13c623a --- /dev/null +++ b/versionmanager/proxy/detached_windows.go @@ -0,0 +1,35 @@ +/* + * + * Copyright 2024 tofuutils authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package proxy + +import ( + "fmt" + "os/exec" + + configutils "github.com/tofuutils/tenv/v3/config/utils" +) + +func initDetachedBehaviorFromEnv(_ *exec.Cmd) { + switch detached, err := configutils.GetenvBool(false, "TENV_DETACHED_PROXY"); { + case err != nil: + fmt.Println("TENV_DETACHED_PROXY behavior is always disabled on Windows OS, failed to read environment variable :", err) //nolint + case detached: + fmt.Println("TENV_DETACHED_PROXY behavior is always disabled on Windows OS, can not apply environment variable") //nolint + } +} diff --git a/versionmanager/proxy/proxy.go b/versionmanager/proxy/proxy.go index 1ee5512..c0bb8ce 100644 --- a/versionmanager/proxy/proxy.go +++ b/versionmanager/proxy/proxy.go @@ -26,12 +26,10 @@ import ( "os/exec" "path/filepath" "strings" - "syscall" "github.com/hashicorp/hcl/v2/hclparse" "github.com/tofuutils/tenv/v3/config" - configutils "github.com/tofuutils/tenv/v3/config/utils" cmdproxy "github.com/tofuutils/tenv/v3/pkg/cmdproxy" "github.com/tofuutils/tenv/v3/pkg/loghelper" "github.com/tofuutils/tenv/v3/versionmanager/builder" @@ -86,19 +84,3 @@ func updateWorkPath(conf *config.Config, cmdArgs []string) { } } } - -func initDetachedBehaviorFromEnv(cmd *exec.Cmd) { - detached, err := configutils.GetenvBool(false, "TENV_DETACHED_PROXY") - if err != nil { - fmt.Println("Failed to read TENV_DETACHED_PROXY environment variable, disable behavior :", err) //nolint - } - if !detached { - return - } - - if cmd.SysProcAttr == nil { - cmd.SysProcAttr = &syscall.SysProcAttr{} - } - - cmd.SysProcAttr.Setpgid = true -}