Include the -config option in the installed service

Untested on Linux and Windows. Fear.

Fixes #304
This commit is contained in:
Frank Denis 2018-04-03 19:42:27 +02:00
parent 869d44c30e
commit c88e480a15
2 changed files with 22 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
@ -134,11 +135,22 @@ type ServerSummary struct {
Description string `json:"description,omitempty"`
}
func ConfigLoad(proxy *Proxy, svcFlag *string) error {
func FindConfigFile() (string, error) {
configFile := flag.String("config", DefaultConfigFileName, "Path to the configuration file")
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
cdLocal()
if _, err := os.Stat(*configFile); err != nil {
return "", err
}
}
pwd, err := os.Getwd()
if err != nil {
return "", err
}
return path.Join(pwd, *configFile), nil
}
func ConfigLoad(configFile *string, proxy *Proxy, svcFlag *string) error {
version := flag.Bool("version", false, "print current proxy version")
resolve := flag.String("resolve", "", "resolve a name using system libraries")
list := flag.Bool("list", false, "print the list of available resolvers for the enabled filters")

View File

@ -25,10 +25,18 @@ type App struct {
func main() {
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON")
var err error
configFile, err := FindConfigFile()
if err != nil {
dlog.Fatalf("Unable to load the configuration file: [%s] -- Maybe use the -config command-line switch?", err)
}
svcConfig := &service.Config{
Name: "dnscrypt-proxy",
DisplayName: "DNSCrypt client proxy",
Description: "Encrypted/authenticated DNS proxy",
Arguments: []string{"-config", configFile},
}
svcFlag := flag.String("service", "", fmt.Sprintf("Control the system service: %q", service.ControlAction))
app := &App{}
@ -40,7 +48,7 @@ func main() {
app.proxy = NewProxy()
app.proxy.xTransport = NewXTransport(30*time.Second, true, false)
if err := ConfigLoad(&app.proxy, svcFlag); err != nil {
if err := ConfigLoad(&configFile, &app.proxy, svcFlag); err != nil {
dlog.Fatal(err)
}
dlog.Noticef("dnscrypt-proxy %s", AppVersion)