From 8052e6c08058df004229e66c9b89bbf8ea9b2905 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 22 Sep 2020 07:48:23 -0400 Subject: [PATCH] Factor out LoadConfig --- cmd/meshnamed/main.go | 16 ++++++++++++++-- src/meshname/server.go | 10 ---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/meshnamed/main.go b/cmd/meshnamed/main.go index 4fa92bc..e16c924 100644 --- a/cmd/meshnamed/main.go +++ b/cmd/meshnamed/main.go @@ -28,6 +28,14 @@ func parseNetworks(networksconf string) (map[string]*net.IPNet, error) { return networks, nil } +func loadConfig(s *meshname.MeshnameServer, confPath string) error { + zoneConf, err := meshname.ParseConfigFile(confPath) + if err == nil { + s.SetZoneConfig(zoneConf) + } + return err +} + var ( genconf, subdomain, useconffile, listenAddr, networksconf string debug bool @@ -75,7 +83,9 @@ func main() { } if useconffile != "" { - s.LoadConfig(useconffile) + if err := loadConfig(s, useconffile); err != nil { + logger.Errorln(err) + } } s.Start() @@ -91,7 +101,9 @@ func main() { return case _ = <-r: if useconffile != "" { - s.LoadConfig(useconffile) + if err := loadConfig(s, useconffile); err != nil { + logger.Errorln(err) + } } } } diff --git a/src/meshname/server.go b/src/meshname/server.go index ec95356..497bc76 100644 --- a/src/meshname/server.go +++ b/src/meshname/server.go @@ -68,16 +68,6 @@ func (s *MeshnameServer) Start() error { } } -func (s *MeshnameServer) LoadConfig(confPath string) { - if zoneConf, err := ParseConfigFile(confPath); err == nil { - s.zoneConfigLock.Lock() - s.zoneConfig = zoneConf - s.zoneConfigLock.Unlock() - } else { - s.log.Errorln("Can't parse config file:", err) - } -} - func (s *MeshnameServer) SetZoneConfig(zoneConfig map[string][]dns.RR) { s.zoneConfigLock.Lock() s.zoneConfig = zoneConfig