mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-28 18:08:51 +03:00
0182b9ec18
Updates #6158.
Squashed commit of the following:
commit d474a7cb2cdf0a28cf2df320f9095a739241dcc3
Merge: 9c371bde4 53625d891
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Aug 31 17:33:14 2023 +0300
Merge branch 'master' into 6158-fix-service-restart
commit 9c371bde4b32eee7b5b36766095af3d579e14f2c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Aug 31 16:53:11 2023 +0300
aghos: imp code
commit 2722d38ad51ea6b42caf81bbfc41206c95dac358
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Aug 31 16:29:22 2023 +0300
home: imp code more
commit 50de4c3379cf6e46e5a7cf287381d2b2c3b97127
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Aug 31 16:20:18 2023 +0300
home: imp code
commit dcba579fbe5cb82bea391bd08caee9df82c2618b
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Aug 31 14:57:24 2023 +0300
home: fix service restart for windows
83 lines
1.6 KiB
Go
83 lines
1.6 KiB
Go
//go:build windows
|
|
|
|
package aghos
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"syscall"
|
|
|
|
"github.com/AdguardTeam/golibs/log"
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func rootDirFS() (fsys fs.FS) {
|
|
// TODO(a.garipov): Use a better way if golang/go#44279 is ever resolved.
|
|
sysDir, err := windows.GetSystemDirectory()
|
|
if err != nil {
|
|
log.Error("aghos: getting root filesystem: %s; using C:", err)
|
|
|
|
// Assume that C: is the safe default.
|
|
return os.DirFS("C:")
|
|
}
|
|
|
|
return os.DirFS(filepath.VolumeName(sysDir))
|
|
}
|
|
|
|
func setRlimit(val uint64) (err error) {
|
|
return Unsupported("setrlimit")
|
|
}
|
|
|
|
func haveAdminRights() (bool, error) {
|
|
var token windows.Token
|
|
h := windows.CurrentProcess()
|
|
err := windows.OpenProcessToken(h, windows.TOKEN_QUERY, &token)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
info := make([]byte, 4)
|
|
var returnedLen uint32
|
|
err = windows.GetTokenInformation(token, windows.TokenElevation, &info[0], uint32(len(info)), &returnedLen)
|
|
token.Close()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if info[0] == 0 {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
func isOpenWrt() (ok bool) {
|
|
return false
|
|
}
|
|
|
|
func notifyReconfigureSignal(c chan<- os.Signal) {
|
|
signal.Notify(c, windows.SIGHUP)
|
|
}
|
|
|
|
func notifyShutdownSignal(c chan<- os.Signal) {
|
|
// syscall.SIGTERM is processed automatically. See go doc os/signal,
|
|
// section Windows.
|
|
signal.Notify(c, os.Interrupt)
|
|
}
|
|
|
|
func isReconfigureSignal(sig os.Signal) (ok bool) {
|
|
return sig == windows.SIGHUP
|
|
}
|
|
|
|
func isShutdownSignal(sig os.Signal) (ok bool) {
|
|
switch sig {
|
|
case os.Interrupt, syscall.SIGTERM:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func sendShutdownSignal(c chan<- os.Signal) {
|
|
c <- os.Interrupt
|
|
}
|