Mainly revert 869d44c30e
Fixing #304 doesn't look trivial The service module needs to know the arguments right away. The arguments haven't been parsed yet. And if we do, we will prevent further arguments to be added to the set. Including the ones added by the service module itself. So, we have quite of a circular dependency here. If someone with some Go knowledge can fix that, that would be amazing. But it's probably never going to happen. Meanwhile, we can try to save the current directory and document that we have to be in that directory when running the install command. Which is not going to work on Windows, so this is a big fucking mess
This commit is contained in:
parent
c88e480a15
commit
a938eeff7b
|
@ -135,8 +135,7 @@ type ServerSummary struct {
|
|||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func FindConfigFile() (string, error) {
|
||||
configFile := flag.String("config", DefaultConfigFileName, "Path to the configuration file")
|
||||
func findConfigFile(configFile *string) (string, error) {
|
||||
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
|
||||
cdLocal()
|
||||
if _, err := os.Stat(*configFile); err != nil {
|
||||
|
@ -147,17 +146,23 @@ func FindConfigFile() (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if filepath.IsAbs(*configFile) {
|
||||
return *configFile, nil
|
||||
}
|
||||
return path.Join(pwd, *configFile), nil
|
||||
}
|
||||
|
||||
func ConfigLoad(configFile *string, proxy *Proxy, svcFlag *string) error {
|
||||
func ConfigLoad(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")
|
||||
listAll := flag.Bool("list-all", false, "print the complete list of available resolvers, ignoring filters")
|
||||
jsonOutput := flag.Bool("json", false, "output list as JSON")
|
||||
check := flag.Bool("check", false, "check the configuration file and exit")
|
||||
configFile := flag.String("config", DefaultConfigFileName, "Path to the configuration file")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *svcFlag == "stop" || *svcFlag == "uninstall" {
|
||||
return nil
|
||||
}
|
||||
|
@ -169,8 +174,13 @@ func ConfigLoad(configFile *string, proxy *Proxy, svcFlag *string) error {
|
|||
Resolve(*resolve)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
foundConfigFile, err := findConfigFile(configFile)
|
||||
if err != nil {
|
||||
dlog.Fatalf("Unable to load the configuration file [%s] -- Maybe use the -config command-line switch?", *configFile)
|
||||
}
|
||||
config := newConfig()
|
||||
md, err := toml.DecodeFile(*configFile, &config)
|
||||
md, err := toml.DecodeFile(foundConfigFile, &config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -178,7 +188,7 @@ func ConfigLoad(configFile *string, proxy *Proxy, svcFlag *string) error {
|
|||
if len(undecoded) > 0 {
|
||||
return fmt.Errorf("Unsupported key in configuration file: [%s]", undecoded[0])
|
||||
}
|
||||
cdFileDir(*configFile)
|
||||
cdFileDir(foundConfigFile)
|
||||
if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) {
|
||||
dlog.SetLogLevel(dlog.Severity(config.LogLevel))
|
||||
}
|
||||
|
|
|
@ -26,17 +26,15 @@ type App struct {
|
|||
func main() {
|
||||
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON")
|
||||
|
||||
var err error
|
||||
configFile, err := FindConfigFile()
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
dlog.Fatalf("Unable to load the configuration file: [%s] -- Maybe use the -config command-line switch?", err)
|
||||
dlog.Fatal("Unable to find the path to the current directory")
|
||||
}
|
||||
|
||||
svcConfig := &service.Config{
|
||||
Name: "dnscrypt-proxy",
|
||||
DisplayName: "DNSCrypt client proxy",
|
||||
Description: "Encrypted/authenticated DNS proxy",
|
||||
Arguments: []string{"-config", configFile},
|
||||
WorkingDirectory: pwd,
|
||||
}
|
||||
svcFlag := flag.String("service", "", fmt.Sprintf("Control the system service: %q", service.ControlAction))
|
||||
app := &App{}
|
||||
|
@ -48,7 +46,7 @@ func main() {
|
|||
app.proxy = NewProxy()
|
||||
app.proxy.xTransport = NewXTransport(30*time.Second, true, false)
|
||||
|
||||
if err := ConfigLoad(&configFile, &app.proxy, svcFlag); err != nil {
|
||||
if err := ConfigLoad(&app.proxy, svcFlag); err != nil {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
dlog.Noticef("dnscrypt-proxy %s", AppVersion)
|
||||
|
|
Loading…
Reference in New Issue