使用自定义 executils.LookPath() 代替 exec.LookPath() 避免因$PATH环境变量被破坏而无法工作

This commit is contained in:
刘祥超
2023-07-03 10:37:36 +08:00
parent d0bd7bb88d
commit 2c59ae4a5b
14 changed files with 95 additions and 33 deletions

View File

@@ -13,7 +13,6 @@ import (
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
timeutil "github.com/iwind/TeaGo/utils/time"
"net"
"os/exec"
"runtime"
"time"
)
@@ -86,7 +85,7 @@ func (this *ClockManager) Sync() error {
// check chrony
if config.CheckChrony {
chronycExe, err := exec.LookPath("chronyc")
chronycExe, err := executils.LookPath("chronyc")
if err == nil && len(chronycExe) > 0 {
var chronyCmd = executils.NewTimeoutCmd(3*time.Second, chronycExe, "tracking")
err = chronyCmd.Run()
@@ -101,11 +100,11 @@ func (this *ClockManager) Sync() error {
server = "pool.ntp.org"
}
ntpdate, err := exec.LookPath("ntpdate")
ntpdate, err := executils.LookPath("ntpdate")
if err != nil {
// 使用 date 命令设置
// date --set TIME
dateExe, err := exec.LookPath("date")
dateExe, err := executils.LookPath("date")
if err == nil {
currentTime, err := this.ReadServer(server)
if err != nil {