mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-06-29 21:00:57 +08:00
Some checks failed
Build docker image / build-image (push) Has been cancelled
Build and Release / prepare (push) Has been cancelled
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
Build and Release / build (386, freebsd, , ) (push) Has been cancelled
Build and Release / build (386, linux, , ) (push) Has been cancelled
Build and Release / build (386, openbsd, , ) (push) Has been cancelled
Build and Release / build (386, windows, , ) (push) Has been cancelled
Build and Release / build (386, windows, 1.21.4, win7-32) (push) Has been cancelled
Build and Release / build (amd64, darwin, , ) (push) Has been cancelled
Build and Release / build (amd64, freebsd, , ) (push) Has been cancelled
Build and Release / build (amd64, linux, , ) (push) Has been cancelled
Build and Release / build (amd64, openbsd, , ) (push) Has been cancelled
Build and Release / build (amd64, windows, , ) (push) Has been cancelled
Build and Release / build (amd64, windows, 1.21.4, win7-64) (push) Has been cancelled
Build and Release / build (arm, 5, linux) (push) Has been cancelled
Build and Release / build (arm, 6, linux) (push) Has been cancelled
Build and Release / build (arm, 7, freebsd) (push) Has been cancelled
Build and Release / build (arm, 7, linux) (push) Has been cancelled
Build and Release / build (arm, 7, openbsd) (push) Has been cancelled
Build and Release / build (arm, 7, windows) (push) Has been cancelled
Build and Release / build (arm64, android) (push) Has been cancelled
Build and Release / build (arm64, darwin) (push) Has been cancelled
Build and Release / build (arm64, freebsd) (push) Has been cancelled
Build and Release / build (arm64, linux) (push) Has been cancelled
Build and Release / build (arm64, openbsd) (push) Has been cancelled
Build and Release / build (arm64, windows) (push) Has been cancelled
Build and Release / build (loong64, linux) (push) Has been cancelled
Build and Release / build (mips, linux) (push) Has been cancelled
Build and Release / build (mips64, linux) (push) Has been cancelled
Build and Release / build (mips64le, linux) (push) Has been cancelled
Build and Release / build (mipsle, linux) (push) Has been cancelled
Build and Release / build (ppc64, linux) (push) Has been cancelled
Build and Release / build (ppc64le, linux) (push) Has been cancelled
Build and Release / build (riscv64, linux) (push) Has been cancelled
Build and Release / build (s390x, linux) (push) Has been cancelled
* Add feature migration notice * Remove legacy code of transport processing * Clear legacy proto field * Fix missing * Unify protocolname * Test remove * Supressor * Weird code * Remove errorgen related comments
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
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(), "<xctl message> \n", strings.TrimSpace(errBuffer.MultiBuffer.String()))
|
|
}
|
|
|
|
return outBuffer.MultiBuffer, nil
|
|
}
|