Skip to content

Commit

Permalink
aghos: imp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 18, 2021
1 parent 220d37e commit e3d6fbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ and this project adheres to

### Fixed

- Sending `reload` signal to AdGuard Home on macOS ([#3457]).
- `reload` service action on macOS and FreeBSD ([#3457]).
- Inaccurate using of service actions in the installation script ([#3450]).
- Client ID checking ([#3437]).
- Discovering other DHCP servers on `darwin` and `freebsd` ([#3417]).
Expand Down
17 changes: 4 additions & 13 deletions internal/aghos/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"syscall"

"github.com/AdguardTeam/golibs/log"
)
Expand Down Expand Up @@ -51,17 +49,6 @@ func HaveAdminRights() (bool, error) {
return haveAdminRights()
}

// SendProcessSignal sends sig to a process defined by pid.
func SendProcessSignal(pid int, sig syscall.Signal) (err error) {
var proc *os.Process
proc, err = os.FindProcess(pid)
if err != nil {
return err
}

return proc.Signal(sig)
}

// MaxCmdOutputSize is the maximum length of performed shell command output.
const MaxCmdOutputSize = 2 * 1024

Expand All @@ -82,6 +69,10 @@ func RunCommand(command string, arguments ...string) (int, string, error) {
// PIDByCommand searches for process named command and returns its PID ignoring
// the PIDs from except. If no processes found, the error returned.
func PIDByCommand(command string, except ...int) (pid int, err error) {
// Don't use -C flag here since it's a feature of linux's ps
// implementation. Use POSIX-compatible flags instead.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/3457.
cmd := exec.Command("ps", "-A", "-o", "pid=", "-o", "comm=")

var stdout io.ReadCloser
Expand Down
10 changes: 8 additions & 2 deletions internal/home/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ func sendSigReload() {
}
}

err = aghos.SendProcessSignal(pid, syscall.SIGHUP)
if err != nil {
var proc *os.Process
if proc, err = os.FindProcess(pid); err != nil {
log.Error("can't send signal to pid %d: %s", pid, err)

return
}

if err = proc.Signal(syscall.SIGHUP); err != nil {
log.Error("Can't send signal to pid %d: %s", pid, err)

return
Expand Down

0 comments on commit e3d6fbc

Please sign in to comment.