Skip to content

Commit

Permalink
all: mk aghnet package, rename sysutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 16, 2021
1 parent e6a8fe4 commit b033657
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 33 deletions.
3 changes: 2 additions & 1 deletion internal/sysutil/net.go → internal/aghnet/net.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package sysutil
// Package aghnet contains some utilities for networking.
package aghnet

import (
"net"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build darwin

package sysutil
package aghnet

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build linux

package sysutil
package aghnet

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build linux

package sysutil
package aghnet

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !linux,!darwin

package sysutil
package aghnet

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions internal/sysutil/os.go → internal/aghos/os.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build freebsd

package sysutil
package aghos

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build linux

package sysutil
package aghos

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion internal/sysutil/os_unix.go → internal/aghos/os_unix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build aix darwin dragonfly netbsd openbsd solaris

package sysutil
package aghos

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build windows

package sysutil
package aghos

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion internal/sysutil/syslog.go → internal/aghos/syslog.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sysutil
package aghos

// ConfigureSyslog reroutes standard logger output to syslog.
func ConfigureSyslog(serviceName string) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !windows,!plan9

package sysutil
package aghos

import (
"log/syslog"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build windows plan9

package sysutil
package aghos

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sysutil
package aghos

import (
"testing"
Expand Down
12 changes: 6 additions & 6 deletions internal/dhcpd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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; " +
Expand All @@ -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)

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions internal/home/controlinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/home/controlupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/home/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b033657

Please sign in to comment.