]> Cypherpunks repositories - gostls13.git/commitdiff
log/syslog: set local to true if network is any of "unix", or "unixgram"
authorimxyb <xyb4638@gmail.com>
Sun, 25 Oct 2020 03:42:20 +0000 (03:42 +0000)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Sun, 25 Oct 2020 05:19:20 +0000 (05:19 +0000)
Fixes #41960

Change-Id: I0e0f0e11610dd2658a8f6b7e345a4aae2c19c85d
GitHub-Last-Rev: 8cac718e4854773ca411116043b4b832e0468f09
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>

src/log/syslog/syslog.go
src/log/syslog/syslog_test.go

index 82dd4e7dd6d6d42a3c762126f1ba68604fea88be..97c10f31df37de41fa7da9d13f5c434165065e33 100644 (file)
@@ -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()
                        }
index 30abfae550f6e69c012d2fa4ae1e06282512e38a..8f472a56b77952fd0e2129df4bb619d364b0dbf1 100644 (file)
@@ -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, &timestamp, &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, &timestamp, &parsedHostname, &pid)
+       if n != 3 || err != nil || hostname != parsedHostname {
+               t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
        }
 }