diff --git a/cmd/sing-box/cmd_tools_synctime.go b/cmd/sing-box/cmd_tools_synctime.go index 38510eb8..09d487ef 100644 --- a/cmd/sing-box/cmd_tools_synctime.go +++ b/cmd/sing-box/cmd_tools_synctime.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/sagernet/sing-box/common/settings" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" E "github.com/sagernet/sing/common/exceptions" @@ -58,7 +57,7 @@ func syncTime() error { return err } if commandSyncTimeWrite { - err = settings.SetSystemTime(response.Time) + err = ntp.SetSystemTime(response.Time) if err != nil { return E.Cause(err, "write time to system") } diff --git a/common/settings/time_stub.go b/common/settings/time_stub.go deleted file mode 100644 index 06204913..00000000 --- a/common/settings/time_stub.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build !(windows || linux || darwin) - -package settings - -import ( - "os" - "time" -) - -func SetSystemTime(nowTime time.Time) error { - return os.ErrInvalid -} diff --git a/common/settings/time_unix.go b/common/settings/time_unix.go deleted file mode 100644 index 9eff244d..00000000 --- a/common/settings/time_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build linux || darwin - -package settings - -import ( - "time" - - "golang.org/x/sys/unix" -) - -func SetSystemTime(nowTime time.Time) error { - timeVal := unix.NsecToTimeval(nowTime.UnixNano()) - return unix.Settimeofday(&timeVal) -} diff --git a/common/settings/time_windows.go b/common/settings/time_windows.go deleted file mode 100644 index 5d95e3ba..00000000 --- a/common/settings/time_windows.go +++ /dev/null @@ -1,32 +0,0 @@ -package settings - -import ( - "time" - "unsafe" - - "golang.org/x/sys/windows" -) - -func SetSystemTime(nowTime time.Time) error { - var systemTime windows.Systemtime - systemTime.Year = uint16(nowTime.Year()) - systemTime.Month = uint16(nowTime.Month()) - systemTime.Day = uint16(nowTime.Day()) - systemTime.Hour = uint16(nowTime.Hour()) - systemTime.Minute = uint16(nowTime.Minute()) - systemTime.Second = uint16(nowTime.Second()) - systemTime.Milliseconds = uint16(nowTime.UnixMilli() - nowTime.Unix()*1000) - - dllKernel32 := windows.NewLazySystemDLL("kernel32.dll") - proc := dllKernel32.NewProc("SetSystemTime") - - _, _, err := proc.Call( - uintptr(unsafe.Pointer(&systemTime)), - ) - - if err != nil && err.Error() != "The operation completed successfully." { - return err - } - - return nil -}