Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 1 | diff -r -u go/src/log/syslog/syslog.go /home/achang/GOCOPY/go/src/log/syslog/syslog.go |
| 2 | --- go/src/log/syslog/syslog.go 2013-11-28 13:38:28.000000000 -0800 |
| 3 | +++ /home/achang/GOCOPY/go/src/log/syslog/syslog.go 2014-10-03 11:44:37.710403200 -0700 |
| 4 | @@ -33,6 +33,9 @@ |
| 5 | const severityMask = 0x07 |
| 6 | const facilityMask = 0xf8 |
| 7 | |
| 8 | +var writeTimeout = 1 * time.Second |
| 9 | +var connectTimeout = 1 * time.Second |
| 10 | + |
| 11 | const ( |
| 12 | // Severity. |
| 13 | |
| 14 | @@ -100,6 +103,7 @@ |
| 15 | type serverConn interface { |
| 16 | writeString(p Priority, hostname, tag, s, nl string) error |
| 17 | close() error |
| 18 | + setWriteDeadline(t time.Time) error |
| 19 | } |
| 20 | |
| 21 | type netConn struct { |
| 22 | @@ -273,7 +277,11 @@ |
| 23 | nl = "\n" |
| 24 | } |
| 25 | |
| 26 | - err := w.conn.writeString(p, w.hostname, w.tag, msg, nl) |
| 27 | + err := w.conn.setWriteDeadline(time.Now().Add(writeTimeout)) |
| 28 | + if err != nil { |
| 29 | + return 0, err |
| 30 | + } |
| 31 | + err = w.conn.writeString(p, w.hostname, w.tag, msg, nl) |
| 32 | if err != nil { |
| 33 | return 0, err |
| 34 | } |
| 35 | @@ -305,6 +313,10 @@ |
| 36 | return n.conn.Close() |
| 37 | } |
| 38 | |
| 39 | +func (n *netConn) setWriteDeadline(t time.Time) error { |
| 40 | + return n.conn.SetWriteDeadline(t) |
| 41 | +} |
| 42 | + |
| 43 | // NewLogger creates a log.Logger whose output is written to |
| 44 | // the system log service with the specified priority. The logFlag |
| 45 | // argument is the flag set passed through to log.New to create |
| 46 | diff -r -u go/src/log/syslog/syslog_unix.go /home/achang/GOCOPY/go/src/log/syslog/syslog_unix.go |
| 47 | --- go/src/log/syslog/syslog_unix.go 2013-11-28 13:38:28.000000000 -0800 |
| 48 | +++ /home/achang/GOCOPY/go/src/log/syslog/syslog_unix.go 2014-10-03 11:44:39.010403175 -0700 |
| 49 | @@ -19,7 +19,7 @@ |
| 50 | logPaths := []string{"/dev/log", "/var/run/syslog"} |
| 51 | for _, network := range logTypes { |
| 52 | for _, path := range logPaths { |
| 53 | - conn, err := net.Dial(network, path) |
| 54 | + conn, err := net.DialTimeout(network, path, connectTimeout) |
| 55 | if err != nil { |
| 56 | continue |
| 57 | } else { |