diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-23 21:23:27 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-23 21:23:27 +0000 |
commit | 0d09a10f5f66b93bcbe3cf08da5f0a722d14066d (patch) | |
tree | 5691227e5c7cd0babfc77fc0d3a3bb1700380e07 /libgo/go | |
parent | 91bf877322132494627147ffbcc49b8ac24f184d (diff) | |
download | gcc-0d09a10f5f66b93bcbe3cf08da5f0a722d14066d.tar.gz |
log/syslog: Restore interface to make this work on Solaris again.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201188 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/log/syslog/syslog.go | 32 | ||||
-rw-r--r-- | libgo/go/log/syslog/syslog_libc.go | 8 | ||||
-rw-r--r-- | libgo/go/log/syslog/syslog_unix.go | 4 |
3 files changed, 31 insertions, 13 deletions
diff --git a/libgo/go/log/syslog/syslog.go b/libgo/go/log/syslog/syslog.go index 8bdd9825e1c..20acab8ffc0 100644 --- a/libgo/go/log/syslog/syslog.go +++ b/libgo/go/log/syslog/syslog.go @@ -88,6 +88,15 @@ type Writer struct { raddr string mu sync.Mutex // guards conn + conn serverConn +} + +type serverConn interface { + writeString(p Priority, hostname, tag, s, nl string) error + close() error +} + +type netConn struct { conn net.Conn } @@ -135,7 +144,7 @@ func Dial(network, raddr string, priority Priority, tag string) (*Writer, error) func (w *Writer) connect() (err error) { if w.conn != nil { // ignore err from close, it makes sense to continue anyway - w.conn.Close() + w.conn.close() w.conn = nil } @@ -148,7 +157,7 @@ func (w *Writer) connect() (err error) { var c net.Conn c, err = net.Dial(w.network, w.raddr) if err == nil { - w.conn = c + w.conn = netConn{c} if w.hostname == "" { w.hostname = c.LocalAddr().String() } @@ -168,7 +177,7 @@ func (w *Writer) Close() error { defer w.mu.Unlock() if w.conn != nil { - err := w.conn.Close() + err := w.conn.close() w.conn = nil return err } @@ -257,13 +266,22 @@ func (w *Writer) write(p Priority, msg string) (int, error) { nl = "\n" } - timestamp := time.Now().Format(time.RFC3339) - fmt.Fprintf(w.conn, "<%d>%s %s %s[%d]: %s%s", - p, timestamp, w.hostname, - w.tag, os.Getpid(), msg, nl) + w.conn.writeString(p, w.hostname, w.tag, msg, nl) return len(msg), nil } +func (n netConn) writeString(p Priority, hostname, tag, msg, nl string) error { + timestamp := time.Now().Format(time.RFC3339) + _, err := fmt.Fprintf(n.conn, "<%d>%s %s %s[%d]: %s%s", + p, timestamp, hostname, + tag, os.Getpid(), msg, nl) + return err +} + +func (n netConn) close() error { + return n.conn.Close() +} + // NewLogger creates a log.Logger whose output is written to // the system log service with the specified priority. The logFlag // argument is the flag set passed through to log.New to create diff --git a/libgo/go/log/syslog/syslog_libc.go b/libgo/go/log/syslog/syslog_libc.go index 2d14d5d20a8..cf370eff9d7 100644 --- a/libgo/go/log/syslog/syslog_libc.go +++ b/libgo/go/log/syslog/syslog_libc.go @@ -23,17 +23,17 @@ type libcConn int func syslog_c(int, *byte) -func (libcConn) writeString(p Priority, hostname, tag, msg string) (int, error) { +func (libcConn) writeString(p Priority, hostname, tag, msg, nl string) error { timestamp := time.Now().Format(time.RFC3339) - log := fmt.Sprintf("%s %s %s[%d]: %s", timestamp, hostname, tag, os.Getpid(), msg) + log := fmt.Sprintf("%s %s %s[%d]: %s%s", timestamp, hostname, tag, os.Getpid(), msg, nl) buf, err := syscall.BytePtrFromString(log) if err != nil { - return 0, err + return err } syscall.Entersyscall() syslog_c(int(p), buf) syscall.Exitsyscall() - return len(msg), nil + return nil } func (libcConn) close() error { diff --git a/libgo/go/log/syslog/syslog_unix.go b/libgo/go/log/syslog/syslog_unix.go index a0001ccaea9..1716d60feaa 100644 --- a/libgo/go/log/syslog/syslog_unix.go +++ b/libgo/go/log/syslog/syslog_unix.go @@ -14,7 +14,7 @@ import ( // unixSyslog opens a connection to the syslog daemon running on the // local machine using a Unix domain socket. -func unixSyslog() (conn net.Conn, err error) { +func unixSyslog() (conn serverConn, err error) { logTypes := []string{"unixgram", "unix"} logPaths := []string{"/dev/log", "/var/run/syslog"} for _, network := range logTypes { @@ -23,7 +23,7 @@ func unixSyslog() (conn net.Conn, err error) { if err != nil { continue } else { - return conn, nil + return netConn{conn}, nil } } } |