mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-27 20:36:30 -04:00
Move daemon code to dedicated package
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -19,8 +19,8 @@ var daemonHash []byte
|
|||||||
// RCWService provides an RPC method.
|
// RCWService provides an RPC method.
|
||||||
type RCWService struct{}
|
type RCWService struct{}
|
||||||
|
|
||||||
// StartDaemon should be called to start an RPC server.
|
// Run should be called to start an RPC server.
|
||||||
func StartDaemon() {
|
func Run() {
|
||||||
// store the hash of the daemon binary
|
// store the hash of the daemon binary
|
||||||
daemonHash = getFileHash(binPath)
|
daemonHash = getFileHash(binPath)
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@@ -6,7 +6,8 @@ import (
|
|||||||
"net/rpc"
|
"net/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CallDaemon() string {
|
// Call connects to the RPC server and requests the passphrase.
|
||||||
|
func Call() string {
|
||||||
// connect to the UNIX domain socket
|
// connect to the UNIX domain socket
|
||||||
conn, err := net.Dial("unix", socketPath)
|
conn, err := net.Dial("unix", socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -3,17 +3,18 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"rcw/daemon"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "client":
|
case "client":
|
||||||
fmt.Println("RPC Reply: " + CallDaemon())
|
fmt.Println("RPC Reply: " + daemon.Call())
|
||||||
default:
|
default:
|
||||||
StartDaemon()
|
daemon.Run()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StartDaemon()
|
daemon.Run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user