mirror of
https://github.com/golang/go
synced 2024-11-11 22:50:22 -07:00
log/syslog: set local to true if network is any of "unix", or "unixgram"
Fixes #41960
Change-Id: I0e0f0e11610dd2658a8f6b7e345a4aae2c19c85d
GitHub-Last-Rev: 8cac718e48
GitHub-Pull-Request: golang/go#42135
Reviewed-on: https://go-review.googlesource.com/c/go/+/264297
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
d03437a7c2
commit
7930d39f58
@ -161,7 +161,10 @@ func (w *Writer) connect() (err error) {
|
||||
var c net.Conn
|
||||
c, err = net.Dial(w.network, w.raddr)
|
||||
if err == nil {
|
||||
w.conn = &netConn{conn: c}
|
||||
w.conn = &netConn{
|
||||
conn: c,
|
||||
local: w.network == "unixgram" || w.network == "unix",
|
||||
}
|
||||
if w.hostname == "" {
|
||||
w.hostname = c.LocalAddr().String()
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func TestWithSimulated(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("log failed: %v", err)
|
||||
}
|
||||
check(t, msg, <-done)
|
||||
check(t, msg, <-done, tr)
|
||||
s.Close()
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,7 @@ func TestFlap(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("log failed: %v", err)
|
||||
}
|
||||
check(t, msg, <-done)
|
||||
check(t, msg, <-done, net)
|
||||
|
||||
// restart the server
|
||||
_, sock2, srvWG2 := startServer(net, addr, done)
|
||||
@ -193,7 +193,7 @@ func TestFlap(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("log failed: %v", err)
|
||||
}
|
||||
check(t, msg, <-done)
|
||||
check(t, msg, <-done, net)
|
||||
|
||||
s.Close()
|
||||
}
|
||||
@ -253,16 +253,31 @@ func TestDial(t *testing.T) {
|
||||
l.Close()
|
||||
}
|
||||
|
||||
func check(t *testing.T, in, out string) {
|
||||
tmpl := fmt.Sprintf("<%d>%%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
|
||||
if hostname, err := os.Hostname(); err != nil {
|
||||
func check(t *testing.T, in, out, transport string) {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
t.Error("Error retrieving hostname")
|
||||
} else {
|
||||
var parsedHostname, timestamp string
|
||||
return
|
||||
}
|
||||
|
||||
if transport == "unixgram" || transport == "unix" {
|
||||
var month, date, ts string
|
||||
var pid int
|
||||
if n, err := fmt.Sscanf(out, tmpl, ×tamp, &parsedHostname, &pid); n != 3 || err != nil || hostname != parsedHostname {
|
||||
tmpl := fmt.Sprintf("<%d>%%s %%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
|
||||
n, err := fmt.Sscanf(out, tmpl, &month, &date, &ts, &pid)
|
||||
if n != 4 || err != nil {
|
||||
t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Non-UNIX domain transports.
|
||||
var parsedHostname, timestamp string
|
||||
var pid int
|
||||
tmpl := fmt.Sprintf("<%d>%%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
|
||||
n, err := fmt.Sscanf(out, tmpl, ×tamp, &parsedHostname, &pid)
|
||||
if n != 3 || err != nil || hostname != parsedHostname {
|
||||
t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user