mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-28 04:46:42 -04:00
Add MacOS support
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
//go:build darwin
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// pidToPath returns the path of the executable that has the given PID.
|
||||
func pidToPath(pid int) string {
|
||||
pidString := strconv.Itoa(pid)
|
||||
cmd := exec.Command("lsof", "-a", "-dtxt", "-p"+pidString)
|
||||
output, _ := cmd.Output()
|
||||
line := strings.Split(string(output), "\n")[1]
|
||||
return line[strings.Index(line, "/"):]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//go:build linux || freebsd
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// pidToPath returns the path of the executable that has the given PID.
|
||||
func pidToPath(pid int) string {
|
||||
path, _ := os.Readlink(fmt.Sprintf("/proc/%d/"+pidPathFile, pid))
|
||||
return path
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@@ -97,12 +96,6 @@ func handleConn(conn net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
// pidToPath returns the path of the executable that has the given PID.
|
||||
func pidToPath(pid int) string {
|
||||
path, _ := os.Readlink(fmt.Sprintf("/proc/%d/"+pidPathFile, pid))
|
||||
return path
|
||||
}
|
||||
|
||||
// getFileHash returns the SHA256 hash of the file at the given path.
|
||||
func getFileHash(path string) []byte {
|
||||
file, _ := os.Open(path)
|
||||
|
||||
Reference in New Issue
Block a user