OSDN Git Service

log/syslog: Solaris portability patches.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Dec 2012 21:07:27 +0000 (21:07 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Dec 2012 21:07:27 +0000 (21:07 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194566 138bc75d-0d04-0410-961f-82ee72b054a4

libgo/go/log/syslog/syslog_libc.go

index fb98ad7..2d14d5d 100644 (file)
@@ -10,7 +10,9 @@ package syslog
 
 import (
        "fmt"
+       "os"
        "syscall"
+       "time"
 )
 
 func unixSyslog() (conn serverConn, err error) {
@@ -21,14 +23,17 @@ type libcConn int
 
 func syslog_c(int, *byte)
 
-func (libcConn) writeBytes(p Priority, prefix string, b []byte) (int, error) {
-       syslog_c(int(p), syscall.StringBytePtr(fmt.Sprintf("%s: %s", prefix, b)))
-       return len(b), nil
-}
-
-func (libcConn) writeString(p Priority, prefix string, s string) (int, error) {
-       syslog_c(int(p), syscall.StringBytePtr(fmt.Sprintf("%s: %s", prefix, s)))
-       return len(s), nil
+func (libcConn) writeString(p Priority, hostname, tag, msg string) (int, error) {
+       timestamp := time.Now().Format(time.RFC3339)
+       log := fmt.Sprintf("%s %s %s[%d]: %s", timestamp, hostname, tag, os.Getpid(), msg)
+       buf, err := syscall.BytePtrFromString(log)
+       if err != nil {
+               return 0, err
+       }
+       syscall.Entersyscall()
+       syslog_c(int(p), buf)
+       syscall.Exitsyscall()
+       return len(msg), nil
 }
 
 func (libcConn) close() error {