Merge pull request #522 from alouche/minor_cleanup

Minor cleanup
This commit is contained in:
Armon Dadgar 2014-12-07 17:02:32 -08:00
commit e5ea4ad54a
4 changed files with 28 additions and 26 deletions

View File

@ -274,7 +274,7 @@ func (d *DNSServer) handleTest(resp dns.ResponseWriter, req *dns.Msg) {
m.Authoritative = true
m.RecursionAvailable = true
header := dns.RR_Header{Name: q.Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
txt := &dns.TXT{header, []string{"ok"}}
txt := &dns.TXT{Hdr: header, Txt: []string{"ok"}}
m.Answer = append(m.Answer, txt)
d.addSOA(consulDomain, m)
if err := resp.WriteMsg(m); err != nil {

View File

@ -144,14 +144,18 @@ func (c *WatchCommand) Run(args []string) int {
}
// Setup handler
errExit := false
// errExit:
// 0: false
// 1: true
errExit := 0
if script == "" {
wp.Handler = func(idx uint64, data interface{}) {
defer wp.Stop()
buf, err := json.MarshalIndent(data, "", " ")
if err != nil {
c.Ui.Error(fmt.Sprintf("Error encoding output: %s", err))
errExit = true
errExit = 1
}
c.Ui.Output(string(buf))
}
@ -186,7 +190,7 @@ func (c *WatchCommand) Run(args []string) int {
return
ERR:
wp.Stop()
errExit = true
errExit = 1
}
}
@ -203,12 +207,7 @@ func (c *WatchCommand) Run(args []string) int {
return 1
}
// Handle an error exit
if errExit {
return 1
} else {
return 0
}
return errExit
}
func (c *WatchCommand) Synopsis() string {

View File

@ -1,6 +1,7 @@
package consul
import (
"errors"
"fmt"
"io"
"io/ioutil"
@ -164,8 +165,9 @@ func (c *consulFSM) applyKVSOperation(buf []byte, index uint64) interface{} {
return act
}
default:
c.logger.Printf("[WARN] consul.fsm: Invalid KVS operation '%s'", req.Op)
return fmt.Errorf("Invalid KVS operation '%s'", req.Op)
err := errors.New(fmt.Sprintf("Invalid KVS operation '%s'", req.Op))
c.logger.Printf("[WARN] consul.fsm: %v", err)
return err
}
}

View File

@ -259,7 +259,16 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
}
// Wrap the connection
c := &Conn{
var c *Conn
// Track this connection, handle potential race condition
p.Lock()
defer p.Unlock()
if existing := p.pool[addr.String()]; existing != nil {
c = existing
} else {
c = &Conn{
refCount: 1,
addr: addr,
session: session,
@ -268,18 +277,10 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
version: version,
pool: p,
}
// Track this connection, handle potential race condition
p.Lock()
if existing := p.pool[addr.String()]; existing != nil {
c.Close()
p.Unlock()
return existing, nil
} else {
p.pool[addr.String()] = c
p.Unlock()
return c, nil
}
return c, nil
}
// clearConn is used to clear any cached connection, potentially in response to an erro