From b033657f5c5ee91f869c36508a5eb15976a174a0 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Tue, 16 Mar 2021 17:24:07 +0300 Subject: [PATCH] all: mk aghnet package, rename sysutil package --- internal/{sysutil => aghnet}/net.go | 3 ++- internal/{sysutil => aghnet}/net_darwin.go | 2 +- internal/{sysutil => aghnet}/net_linux.go | 2 +- internal/{sysutil => aghnet}/net_linux_test.go | 2 +- internal/{sysutil => aghnet}/net_others.go | 2 +- internal/{sysutil => aghos}/os.go | 4 ++-- internal/{sysutil => aghos}/os_freebsd.go | 2 +- internal/{sysutil => aghos}/os_linux.go | 2 +- internal/{sysutil => aghos}/os_unix.go | 2 +- internal/{sysutil => aghos}/os_windows.go | 2 +- internal/{sysutil => aghos}/syslog.go | 2 +- internal/{sysutil => aghos}/syslog_others.go | 2 +- internal/{sysutil => aghos}/syslog_windows.go | 2 +- internal/{sysutil => aghos}/sysutil_test.go | 2 +- internal/dhcpd/http.go | 12 ++++++------ internal/home/controlinstall.go | 7 +++---- internal/home/controlupdate.go | 4 ++-- internal/home/home.go | 8 ++++---- internal/home/service.go | 4 ++-- 19 files changed, 33 insertions(+), 33 deletions(-) rename internal/{sysutil => aghnet}/net.go (94%) rename internal/{sysutil => aghnet}/net_darwin.go (99%) rename internal/{sysutil => aghnet}/net_linux.go (99%) rename internal/{sysutil => aghnet}/net_linux_test.go (99%) rename internal/{sysutil => aghnet}/net_others.go (94%) rename internal/{sysutil => aghos}/os.go (87%) rename internal/{sysutil => aghos}/os_freebsd.go (97%) rename internal/{sysutil => aghos}/os_linux.go (98%) rename internal/{sysutil => aghos}/os_unix.go (97%) rename internal/{sysutil => aghos}/os_windows.go (97%) rename internal/{sysutil => aghos}/syslog.go (90%) rename internal/{sysutil => aghos}/syslog_others.go (94%) rename internal/{sysutil => aghos}/syslog_windows.go (98%) rename internal/{sysutil => aghos}/sysutil_test.go (89%) diff --git a/internal/sysutil/net.go b/internal/aghnet/net.go similarity index 94% rename from internal/sysutil/net.go rename to internal/aghnet/net.go index 9ba41704c1f..1f0ccf998f5 100644 --- a/internal/sysutil/net.go +++ b/internal/aghnet/net.go @@ -1,4 +1,5 @@ -package sysutil +// Package aghnet contains some utilities for networking. +package aghnet import ( "net" diff --git a/internal/sysutil/net_darwin.go b/internal/aghnet/net_darwin.go similarity index 99% rename from internal/sysutil/net_darwin.go rename to internal/aghnet/net_darwin.go index 1bc1ac61196..56fa51e1bfa 100644 --- a/internal/sysutil/net_darwin.go +++ b/internal/aghnet/net_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package sysutil +package aghnet import ( "errors" diff --git a/internal/sysutil/net_linux.go b/internal/aghnet/net_linux.go similarity index 99% rename from internal/sysutil/net_linux.go rename to internal/aghnet/net_linux.go index 1964f9dda96..e8273971ce3 100644 --- a/internal/sysutil/net_linux.go +++ b/internal/aghnet/net_linux.go @@ -1,6 +1,6 @@ // +build linux -package sysutil +package aghnet import ( "bufio" diff --git a/internal/sysutil/net_linux_test.go b/internal/aghnet/net_linux_test.go similarity index 99% rename from internal/sysutil/net_linux_test.go rename to internal/aghnet/net_linux_test.go index 3fbfc547fe6..81ebb8b03a9 100644 --- a/internal/sysutil/net_linux_test.go +++ b/internal/aghnet/net_linux_test.go @@ -1,6 +1,6 @@ // +build linux -package sysutil +package aghnet import ( "bytes" diff --git a/internal/sysutil/net_others.go b/internal/aghnet/net_others.go similarity index 94% rename from internal/sysutil/net_others.go rename to internal/aghnet/net_others.go index fd28c1a1500..3b8e9da8c69 100644 --- a/internal/sysutil/net_others.go +++ b/internal/aghnet/net_others.go @@ -1,6 +1,6 @@ // +build !linux,!darwin -package sysutil +package aghnet import ( "fmt" diff --git a/internal/sysutil/os.go b/internal/aghos/os.go similarity index 87% rename from internal/sysutil/os.go rename to internal/aghos/os.go index 63d2bf7eb46..f573d7a705b 100644 --- a/internal/sysutil/os.go +++ b/internal/aghos/os.go @@ -1,5 +1,5 @@ -// Package sysutil contains utilities for functions requiring system calls. -package sysutil +// Package aghos contains utilities for functions requiring system calls. +package aghos import "syscall" diff --git a/internal/sysutil/os_freebsd.go b/internal/aghos/os_freebsd.go similarity index 97% rename from internal/sysutil/os_freebsd.go rename to internal/aghos/os_freebsd.go index 12321aa79af..40965e3a5cb 100644 --- a/internal/sysutil/os_freebsd.go +++ b/internal/aghos/os_freebsd.go @@ -1,6 +1,6 @@ // +build freebsd -package sysutil +package aghos import ( "os" diff --git a/internal/sysutil/os_linux.go b/internal/aghos/os_linux.go similarity index 98% rename from internal/sysutil/os_linux.go rename to internal/aghos/os_linux.go index 2bab01d4c6d..7c74bbd0d21 100644 --- a/internal/sysutil/os_linux.go +++ b/internal/aghos/os_linux.go @@ -1,6 +1,6 @@ // +build linux -package sysutil +package aghos import ( "os" diff --git a/internal/sysutil/os_unix.go b/internal/aghos/os_unix.go similarity index 97% rename from internal/sysutil/os_unix.go rename to internal/aghos/os_unix.go index a77e9da12ec..5e0ffef6ec2 100644 --- a/internal/sysutil/os_unix.go +++ b/internal/aghos/os_unix.go @@ -1,6 +1,6 @@ // +build aix darwin dragonfly netbsd openbsd solaris -package sysutil +package aghos import ( "os" diff --git a/internal/sysutil/os_windows.go b/internal/aghos/os_windows.go similarity index 97% rename from internal/sysutil/os_windows.go rename to internal/aghos/os_windows.go index 3d6745c7126..738889b4ecb 100644 --- a/internal/sysutil/os_windows.go +++ b/internal/aghos/os_windows.go @@ -1,6 +1,6 @@ // +build windows -package sysutil +package aghos import ( "fmt" diff --git a/internal/sysutil/syslog.go b/internal/aghos/syslog.go similarity index 90% rename from internal/sysutil/syslog.go rename to internal/aghos/syslog.go index 7bd505fc4ed..a67a56354f3 100644 --- a/internal/sysutil/syslog.go +++ b/internal/aghos/syslog.go @@ -1,4 +1,4 @@ -package sysutil +package aghos // ConfigureSyslog reroutes standard logger output to syslog. func ConfigureSyslog(serviceName string) error { diff --git a/internal/sysutil/syslog_others.go b/internal/aghos/syslog_others.go similarity index 94% rename from internal/sysutil/syslog_others.go rename to internal/aghos/syslog_others.go index 91fe27cf569..e202b573c37 100644 --- a/internal/sysutil/syslog_others.go +++ b/internal/aghos/syslog_others.go @@ -1,6 +1,6 @@ // +build !windows,!plan9 -package sysutil +package aghos import ( "log/syslog" diff --git a/internal/sysutil/syslog_windows.go b/internal/aghos/syslog_windows.go similarity index 98% rename from internal/sysutil/syslog_windows.go rename to internal/aghos/syslog_windows.go index 1d5cd03f73c..c1ec03232ce 100644 --- a/internal/sysutil/syslog_windows.go +++ b/internal/aghos/syslog_windows.go @@ -1,6 +1,6 @@ // +build windows plan9 -package sysutil +package aghos import ( "strings" diff --git a/internal/sysutil/sysutil_test.go b/internal/aghos/sysutil_test.go similarity index 89% rename from internal/sysutil/sysutil_test.go rename to internal/aghos/sysutil_test.go index 8ca0ff668b3..e68c26b7a3e 100644 --- a/internal/sysutil/sysutil_test.go +++ b/internal/aghos/sysutil_test.go @@ -1,4 +1,4 @@ -package sysutil +package aghos import ( "testing" diff --git a/internal/dhcpd/http.go b/internal/dhcpd/http.go index 9fea7bf6311..7de43228ef4 100644 --- a/internal/dhcpd/http.go +++ b/internal/dhcpd/http.go @@ -10,7 +10,7 @@ import ( "os" "strings" - "github.com/AdguardTeam/AdGuardHome/internal/sysutil" + "github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/golibs/log" ) @@ -93,7 +93,7 @@ func (s *Server) handleDHCPStatus(w http.ResponseWriter, r *http.Request) { func (s *Server) enableDHCP(ifaceName string) (code int, err error) { var hasStaticIP bool - hasStaticIP, err = sysutil.IfaceHasStaticIP(ifaceName) + hasStaticIP, err = aghnet.IfaceHasStaticIP(ifaceName) if err != nil { if errors.Is(err, os.ErrPermission) { // ErrPermission may happen here on Linux systems where @@ -110,7 +110,7 @@ func (s *Server) enableDHCP(ifaceName string) (code int, err error) { log.Info("error while checking static ip: %s; "+ "assuming machine has static ip and going on", err) hasStaticIP = true - } else if errors.Is(err, sysutil.ErrNoStaticIPInfo) { + } else if errors.Is(err, aghnet.ErrNoStaticIPInfo) { // Couldn't obtain a definitive answer. Assume static // IP an go on. log.Info("can't check for static ip; " + @@ -124,7 +124,7 @@ func (s *Server) enableDHCP(ifaceName string) (code int, err error) { } if !hasStaticIP { - err = sysutil.IfaceSetStaticIP(ifaceName) + err = aghnet.IfaceSetStaticIP(ifaceName) if err != nil { err = fmt.Errorf("setting static ip: %w", err) @@ -317,7 +317,7 @@ func (s *Server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { } } if len(jsonIface.Addrs4)+len(jsonIface.Addrs6) != 0 { - jsonIface.GatewayIP = sysutil.GatewayIP(iface.Name) + jsonIface.GatewayIP = aghnet.GatewayIP(iface.Name) response[iface.Name] = jsonIface } } @@ -397,7 +397,7 @@ func (s *Server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Reque found4, err4 := CheckIfOtherDHCPServersPresentV4(interfaceName) - isStaticIP, err := sysutil.IfaceHasStaticIP(interfaceName) + isStaticIP, err := aghnet.IfaceHasStaticIP(interfaceName) if err != nil { result.V4.StaticIP.Static = "error" result.V4.StaticIP.Error = err.Error() diff --git a/internal/home/controlinstall.go b/internal/home/controlinstall.go index 3577a000f44..7443248651b 100644 --- a/internal/home/controlinstall.go +++ b/internal/home/controlinstall.go @@ -15,10 +15,9 @@ import ( "strings" "time" + "github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/AdGuardHome/internal/util" - "github.com/AdguardTeam/AdGuardHome/internal/sysutil" - "github.com/AdguardTeam/golibs/log" ) @@ -155,7 +154,7 @@ func handleStaticIP(ip net.IP, set bool) staticIPJSON { if set { // Try to set static IP for the specified interface - err := sysutil.IfaceSetStaticIP(interfaceName) + err := aghnet.IfaceSetStaticIP(interfaceName) if err != nil { resp.Static = "error" resp.Error = err.Error() @@ -165,7 +164,7 @@ func handleStaticIP(ip net.IP, set bool) staticIPJSON { // Fallthrough here even if we set static IP // Check if we have a static IP and return the details - isStaticIP, err := sysutil.IfaceHasStaticIP(interfaceName) + isStaticIP, err := aghnet.IfaceHasStaticIP(interfaceName) if err != nil { resp.Static = "error" resp.Error = err.Error() diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index 8b3f1bf519f..1aafa2f76ab 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -12,7 +12,7 @@ import ( "syscall" "time" - "github.com/AdguardTeam/AdGuardHome/internal/sysutil" + "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/updater" "github.com/AdguardTeam/golibs/log" ) @@ -141,7 +141,7 @@ func (vr *versionResponse) confirmAutoUpdate() { tlsConf.PortDNSOverQUIC < 1024)) || config.BindPort < 1024 || config.DNS.Port < 1024) { - canUpdate, _ = sysutil.CanBindPrivilegedPorts() + canUpdate, _ = aghos.CanBindPrivilegedPorts() } vr.CanAutoUpdate = &canUpdate } diff --git a/internal/home/home.go b/internal/home/home.go index 21307c05df9..ed0fbca67a5 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -22,12 +22,12 @@ import ( "time" "github.com/AdguardTeam/AdGuardHome/internal/agherr" + "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" "github.com/AdguardTeam/AdGuardHome/internal/querylog" "github.com/AdguardTeam/AdGuardHome/internal/stats" - "github.com/AdguardTeam/AdGuardHome/internal/sysutil" "github.com/AdguardTeam/AdGuardHome/internal/updater" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/AdGuardHome/internal/version" @@ -204,7 +204,7 @@ func setupConfig(args options) { if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && config.RlimitNoFile != 0 { - sysutil.SetRlimit(config.RlimitNoFile) + aghos.SetRlimit(config.RlimitNoFile) } // override bind host/port from the console @@ -361,7 +361,7 @@ func checkPermissions() { if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly - admin, _ := sysutil.HaveAdminRights() + admin, _ := aghos.HaveAdminRights() if admin { return } @@ -481,7 +481,7 @@ func configureLogger(args options) { if ls.LogFile == configSyslog { // Use syslog where it is possible and eventlog on Windows - err := sysutil.ConfigureSyslog(serviceName) + err := aghos.ConfigureSyslog(serviceName) if err != nil { log.Fatalf("cannot initialize syslog: %s", err) } diff --git a/internal/home/service.go b/internal/home/service.go index caebb582b57..2ebd4f2f217 100644 --- a/internal/home/service.go +++ b/internal/home/service.go @@ -9,7 +9,7 @@ import ( "strings" "syscall" - "github.com/AdguardTeam/AdGuardHome/internal/sysutil" + "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/golibs/log" "github.com/kardianos/service" @@ -121,7 +121,7 @@ func sendSigReload() { log.Error("Can't read PID file %s: %s", pidfile, err) return } - err = sysutil.SendProcessSignal(pid, syscall.SIGHUP) + err = aghos.SendProcessSignal(pid, syscall.SIGHUP) if err != nil { log.Error("Can't send signal to PID %d: %s", pid, err) return