You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gdns/server.go

51 lines
853 B
Go

8 years ago
package main
import (
"flag"
"github.com/fangdingjun/gpp/util"
8 years ago
"github.com/miekg/dns"
"log"
"os"
"time"
8 years ago
)
func initListeners(c *cfg) {
for _, a := range c.listen {
log.Printf("Listen on %s %s...\n", a.network, a.addr)
s := &dns.Server{Addr: a.addr, Net: a.network}
go func(s *dns.Server) {
err := s.ListenAndServe()
if err != nil {
log.Println(err)
os.Exit(-1)
}
}(s)
8 years ago
}
}
func main() {
var configFile string
8 years ago
8 years ago
flag.StringVar(&configFile, "c", "", "config file")
flag.Parse()
8 years ago
8 years ago
config, err := parseCfg(configFile)
if err != nil {
log.Println(err)
os.Exit(-1)
}
initRouters(config)
initListeners(config)
8 years ago
// make a delay to make sure net bind completed before drop privilege
time.Sleep(time.Second)
err = util.DropPrivilege(config.User, config.Group)
if err != nil {
log.Println(err)
}
8 years ago
select {}
}