From aea123842b37b3bba0d4b130f4f8cbb6410a40b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=90=B2=93=F0=90=B3=9B=F0=90=B3=AA=F0=90=B3=82?= =?UTF-8?q?=F0=90=B3=90=20=F0=90=B2=80=F0=90=B3=A2=F0=90=B3=A6=F0=90=B3=AB?= =?UTF-8?q?=F0=90=B3=A2=20=F0=90=B2=A5=F0=90=B3=94=F0=90=B3=9B=F0=90=B3=AA?= =?UTF-8?q?=F0=90=B3=8C=F0=90=B3=91=F0=90=B3=96=F0=90=B3=87?= <26771058+KobeArthurScofield@users.noreply.github.com> Date: Mon, 8 Dec 2025 21:27:22 +0800 Subject: [PATCH] Chore: Remove ctlcmd and leftover envvar (#5392) https://github.com/v2fly/v2ray-core/issues/360 --- common/platform/ctlcmd/attr_other.go | 10 ------ common/platform/ctlcmd/attr_windows.go | 12 ------- common/platform/ctlcmd/ctlcmd.go | 50 -------------------------- common/platform/others.go | 9 ----- common/platform/platform.go | 13 ------- common/platform/windows.go | 10 ------ core/config.go | 6 ++-- infra/conf/xray.go | 4 --- main/commands/all/convert/protobuf.go | 11 +----- main/confloader/confloader.go | 12 ------- main/confloader/external/external.go | 11 ------ 11 files changed, 4 insertions(+), 144 deletions(-) delete mode 100644 common/platform/ctlcmd/attr_other.go delete mode 100644 common/platform/ctlcmd/attr_windows.go delete mode 100644 common/platform/ctlcmd/ctlcmd.go diff --git a/common/platform/ctlcmd/attr_other.go b/common/platform/ctlcmd/attr_other.go deleted file mode 100644 index 3e1bc265..00000000 --- a/common/platform/ctlcmd/attr_other.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !windows -// +build !windows - -package ctlcmd - -import "syscall" - -func getSysProcAttr() *syscall.SysProcAttr { - return nil -} diff --git a/common/platform/ctlcmd/attr_windows.go b/common/platform/ctlcmd/attr_windows.go deleted file mode 100644 index ab8ac064..00000000 --- a/common/platform/ctlcmd/attr_windows.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build windows -// +build windows - -package ctlcmd - -import "syscall" - -func getSysProcAttr() *syscall.SysProcAttr { - return &syscall.SysProcAttr{ - HideWindow: true, - } -} diff --git a/common/platform/ctlcmd/ctlcmd.go b/common/platform/ctlcmd/ctlcmd.go deleted file mode 100644 index bc28ace1..00000000 --- a/common/platform/ctlcmd/ctlcmd.go +++ /dev/null @@ -1,50 +0,0 @@ -package ctlcmd - -import ( - "context" - "io" - "os" - "os/exec" - "strings" - - "github.com/xtls/xray-core/common/buf" - "github.com/xtls/xray-core/common/errors" - "github.com/xtls/xray-core/common/platform" -) - -func Run(args []string, input io.Reader) (buf.MultiBuffer, error) { - xctl := platform.GetToolLocation("xctl") - if _, err := os.Stat(xctl); err != nil { - return nil, errors.New("xctl doesn't exist").Base(err) - } - - var errBuffer buf.MultiBufferContainer - var outBuffer buf.MultiBufferContainer - - cmd := exec.Command(xctl, args...) - cmd.Stderr = &errBuffer - cmd.Stdout = &outBuffer - cmd.SysProcAttr = getSysProcAttr() - if input != nil { - cmd.Stdin = input - } - - if err := cmd.Start(); err != nil { - return nil, errors.New("failed to start xctl").Base(err) - } - - if err := cmd.Wait(); err != nil { - msg := "failed to execute xctl" - if errBuffer.Len() > 0 { - msg += ": \n" + strings.TrimSpace(errBuffer.MultiBuffer.String()) - } - return nil, errors.New(msg).Base(err) - } - - // log stderr, info message - if !errBuffer.IsEmpty() { - errors.LogInfo(context.Background(), " \n", strings.TrimSpace(errBuffer.MultiBuffer.String())) - } - - return outBuffer.MultiBuffer, nil -} diff --git a/common/platform/others.go b/common/platform/others.go index a405ac48..be86b6fa 100644 --- a/common/platform/others.go +++ b/common/platform/others.go @@ -8,19 +8,10 @@ import ( "path/filepath" ) -func ExpandEnv(s string) string { - return os.ExpandEnv(s) -} - func LineSeparator() string { return "\n" } -func GetToolLocation(file string) string { - toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir) - return filepath.Join(toolPath, file) -} - // GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations func GetAssetLocation(file string) string { assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir) diff --git a/common/platform/platform.go b/common/platform/platform.go index b865dc0d..bc7baf65 100644 --- a/common/platform/platform.go +++ b/common/platform/platform.go @@ -8,10 +8,8 @@ import ( ) const ( - PluginLocation = "xray.location.plugin" ConfigLocation = "xray.location.config" ConfdirLocation = "xray.location.confdir" - ToolLocation = "xray.location.tool" AssetLocation = "xray.location.asset" CertLocation = "xray.location.cert" @@ -79,17 +77,6 @@ func getExecutableDir() string { return filepath.Dir(exec) } -func getExecutableSubDir(dir string) func() string { - return func() string { - return filepath.Join(getExecutableDir(), dir) - } -} - -func GetPluginDirectory() string { - pluginDir := NewEnvFlag(PluginLocation).GetValue(getExecutableSubDir("plugins")) - return pluginDir -} - func GetConfigurationPath() string { configPath := NewEnvFlag(ConfigLocation).GetValue(getExecutableDir) return filepath.Join(configPath, "config.json") diff --git a/common/platform/windows.go b/common/platform/windows.go index cb25a1ad..684ddc9c 100644 --- a/common/platform/windows.go +++ b/common/platform/windows.go @@ -5,20 +5,10 @@ package platform import "path/filepath" -func ExpandEnv(s string) string { - // TODO - return s -} - func LineSeparator() string { return "\r\n" } -func GetToolLocation(file string) string { - toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir) - return filepath.Join(toolPath, file+".exe") -} - // GetAssetLocation searches for `file` in the env dir and the executable dir func GetAssetLocation(file string) string { assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir) diff --git a/core/config.go b/core/config.go index ec9e5aa4..8f2018e6 100644 --- a/core/config.go +++ b/core/config.go @@ -64,7 +64,7 @@ func GetMergedConfig(args cmdarg.Arg) (string, error) { var files []*ConfigSource supported := []string{"json", "yaml", "toml"} for _, file := range args { - format := getFormat(file) + format := GetFormat(file) if slices.Contains(supported, format) { files = append(files, &ConfigSource{ Name: file, @@ -98,7 +98,7 @@ func getExtension(filename string) string { return filename[idx+1:] } -func getFormat(filename string) string { +func GetFormat(filename string) string { return GetFormatByExtension(getExtension(filename)) } @@ -112,7 +112,7 @@ func LoadConfig(formatName string, input interface{}) (*Config, error) { if formatName == "auto" { if file != "stdin:" { - f = getFormat(file) + f = GetFormat(file) } else { f = "json" } diff --git a/infra/conf/xray.go b/infra/conf/xray.go index e9cacc87..0dfb2a98 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -3,8 +3,6 @@ package conf import ( "context" "encoding/json" - "log" - "os" "path/filepath" "strings" @@ -47,8 +45,6 @@ var ( "dns": func() interface{} { return new(DNSOutboundConfig) }, "wireguard": func() interface{} { return &WireGuardConfig{IsClient: true} }, }, "protocol", "settings") - - ctllog = log.New(os.Stderr, "xctl> ", 0) ) type SniffingConfig struct { diff --git a/main/commands/all/convert/protobuf.go b/main/commands/all/convert/protobuf.go index 74272c57..2f4296e1 100644 --- a/main/commands/all/convert/protobuf.go +++ b/main/commands/all/convert/protobuf.go @@ -3,7 +3,6 @@ package convert import ( "fmt" "os" - "strings" "github.com/xtls/xray-core/common/cmdarg" creflect "github.com/xtls/xray-core/common/reflect" @@ -61,7 +60,7 @@ func executeConvertConfigsToProtobuf(cmd *base.Command, args []string) { } if len(optFile) > 0 { - switch core.GetFormatByExtension(getFileExtension(optFile)){ + switch core.GetFormat(optFile){ case "protobuf", "": fmt.Println("Output ProtoBuf file is ", optFile) default: @@ -106,11 +105,3 @@ func executeConvertConfigsToProtobuf(cmd *base.Command, args []string) { } } } - -func getFileExtension(filename string) string { - idx := strings.LastIndexByte(filename, '.') - if idx == -1 { - return "" - } - return filename[idx+1:] -} diff --git a/main/confloader/confloader.go b/main/confloader/confloader.go index 315c500e..b9652a67 100644 --- a/main/confloader/confloader.go +++ b/main/confloader/confloader.go @@ -10,12 +10,10 @@ import ( type ( configFileLoader func(string) (io.Reader, error) - extconfigLoader func([]string, io.Reader) (io.Reader, error) ) var ( EffectiveConfigFileLoader configFileLoader - EffectiveExtConfigLoader extconfigLoader ) // LoadConfig reads from a path/url/stdin @@ -27,13 +25,3 @@ func LoadConfig(file string) (io.Reader, error) { } return EffectiveConfigFileLoader(file) } - -// LoadExtConfig calls xctl to handle multiple config -// the actual work also in external module -func LoadExtConfig(files []string, reader io.Reader) (io.Reader, error) { - if EffectiveExtConfigLoader == nil { - return nil, errors.New("external config module not loaded").AtError() - } - - return EffectiveExtConfigLoader(files, reader) -} diff --git a/main/confloader/external/external.go b/main/confloader/external/external.go index 787de985..110b483d 100644 --- a/main/confloader/external/external.go +++ b/main/confloader/external/external.go @@ -13,7 +13,6 @@ import ( "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/errors" - "github.com/xtls/xray-core/common/platform/ctlcmd" "github.com/xtls/xray-core/main/confloader" ) @@ -129,16 +128,6 @@ func FetchUnixSocketHTTPContent(target string) ([]byte, error) { return content, nil } -func ExtConfigLoader(files []string, reader io.Reader) (io.Reader, error) { - buf, err := ctlcmd.Run(append([]string{"convert"}, files...), reader) - if err != nil { - return nil, err - } - - return strings.NewReader(buf.String()), nil -} - func init() { confloader.EffectiveConfigFileLoader = ConfigLoader - confloader.EffectiveExtConfigLoader = ExtConfigLoader }