Skip to content

Commit

Permalink
Merge branch 'master' into minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
janeczku committed Oct 2, 2016
2 parents 4682888 + 4ec175c commit b43be71
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.2
FROM alpine:3.4
MAINTAINER Jan Broer <[email protected]>

ADD https://github.com/janeczku/go-dnsmasq/releases/download/1.0.0/go-dnsmasq_linux-amd64 /go-dnsmasq
ADD https://github.com/janeczku/go-dnsmasq/releases/download/1.0.7/go-dnsmasq-min_linux-amd64 /go-dnsmasq
RUN chmod +x /go-dnsmasq

ENV DNSMASQ_LISTEN=0.0.0.0
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ COPY scripts/upx /usr/local/bin/
RUN chmod +x /usr/local/bin/upx

WORKDIR /go/src/github.com/janeczku/go-dnsmasq

#RUN go get -d ./...
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.7
7 changes: 4 additions & 3 deletions hostsfile/hostsfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func NewHostsfile(path string, config *Config) (*Hostsfile, error) {

log.Debugf("Found host:ip pairs in %s:", h.file.path)
for _, hostname := range *h.hosts {
log.Debugf("%s : %s",
log.Debugf("%s -> %s *=%t",
hostname.domain,
hostname.ip.String())
hostname.ip.String(),
hostname.wildcard)
}

return &h, nil
Expand All @@ -67,7 +68,7 @@ func (h *Hostsfile) FindHosts(name string) (addrs []net.IP, err error) {
name = strings.TrimSuffix(name, ".")
h.hostMutex.RLock()
defer h.hostMutex.RUnlock()
addrs = h.hosts.FindHosts(name);
addrs = h.hosts.FindHosts(name)
return
}

Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func main() {
Verbose: c.Bool("verbose"),
}

resolvconf.Clean()
if err := server.ResolvConf(config, c); err != nil {
if !os.IsNotExist(err) {
log.Warnf("Error parsing resolv.conf: %s", err.Error())
Expand Down Expand Up @@ -298,7 +299,11 @@ func main() {
if err != nil {
log.Warnf("Failed to register as default nameserver: %s", err)
}
defer resolvconf.Clean()

defer func() {
log.Info("Restoring /etc/resolv.conf")
resolvconf.Clean()
}()
}

go func() {
Expand Down
9 changes: 4 additions & 5 deletions resolvconf/resolvconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ const RESOLVCONF_PATH = "/etc/resolv.conf"
var resolvConfPattern = regexp.MustCompile("(?m:^.*" + regexp.QuoteMeta(RESOLVCONF_COMMENT_ADD) + ")(?:$|\n)")

func StoreAddress(address string) error {
log.Info("Setting host nameserver to %s", address)
log.Infof("Setting host nameserver to %s", address)
resolveConfEntry := fmt.Sprintf("nameserver %s %s\n", address, RESOLVCONF_COMMENT_ADD)
return updateResolvConf(resolveConfEntry, RESOLVCONF_PATH)
}

func Clean() {
log.Info("Restoring /etc/resolv.conf")
updateResolvConf("", RESOLVCONF_PATH)
}

Expand Down Expand Up @@ -60,17 +59,17 @@ func updateResolvConf(insert, path string) error {
for _, line := range lines {
switch insert {
case "":
// Uncomment lines we commented
// uncomment lines we commented
if strings.Contains(line, RESOLVCONF_COMMENT_OUT) {
line = strings.Replace(line, RESOLVCONF_COMMENT_OUT, "", -1)
line = strings.TrimLeft(line, " ")
}
default:
// Comment out active nameservers only
// comment out active nameservers only
if strings.HasPrefix(strings.ToLower(strings.TrimSpace(line)), "nameserver") {
line = fmt.Sprintf("%s %s", RESOLVCONF_COMMENT_OUT, line)
}
}
}

if _, err = f.WriteString(line); err != nil {
return err
Expand Down

0 comments on commit b43be71

Please sign in to comment.