Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
9d824f6c
Commit
9d824f6c
authored
Jul 23, 2013
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log/syslog: Restore interface to make this work on Solaris again.
From-SVN: r201188
parent
dd7a40e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
libgo/go/log/syslog/syslog.go
+25
-7
libgo/go/log/syslog/syslog_libc.go
+4
-4
libgo/go/log/syslog/syslog_unix.go
+2
-2
No files found.
libgo/go/log/syslog/syslog.go
View file @
9d824f6c
...
@@ -88,6 +88,15 @@ type Writer struct {
...
@@ -88,6 +88,15 @@ type Writer struct {
raddr
string
raddr
string
mu
sync
.
Mutex
// guards conn
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
conn
net
.
Conn
}
}
...
@@ -135,7 +144,7 @@ func Dial(network, raddr string, priority Priority, tag string) (*Writer, error)
...
@@ -135,7 +144,7 @@ func Dial(network, raddr string, priority Priority, tag string) (*Writer, error)
func
(
w
*
Writer
)
connect
()
(
err
error
)
{
func
(
w
*
Writer
)
connect
()
(
err
error
)
{
if
w
.
conn
!=
nil
{
if
w
.
conn
!=
nil
{
// ignore err from close, it makes sense to continue anyway
// ignore err from close, it makes sense to continue anyway
w
.
conn
.
C
lose
()
w
.
conn
.
c
lose
()
w
.
conn
=
nil
w
.
conn
=
nil
}
}
...
@@ -148,7 +157,7 @@ func (w *Writer) connect() (err error) {
...
@@ -148,7 +157,7 @@ func (w *Writer) connect() (err error) {
var
c
net
.
Conn
var
c
net
.
Conn
c
,
err
=
net
.
Dial
(
w
.
network
,
w
.
raddr
)
c
,
err
=
net
.
Dial
(
w
.
network
,
w
.
raddr
)
if
err
==
nil
{
if
err
==
nil
{
w
.
conn
=
c
w
.
conn
=
netConn
{
c
}
if
w
.
hostname
==
""
{
if
w
.
hostname
==
""
{
w
.
hostname
=
c
.
LocalAddr
()
.
String
()
w
.
hostname
=
c
.
LocalAddr
()
.
String
()
}
}
...
@@ -168,7 +177,7 @@ func (w *Writer) Close() error {
...
@@ -168,7 +177,7 @@ func (w *Writer) Close() error {
defer
w
.
mu
.
Unlock
()
defer
w
.
mu
.
Unlock
()
if
w
.
conn
!=
nil
{
if
w
.
conn
!=
nil
{
err
:=
w
.
conn
.
C
lose
()
err
:=
w
.
conn
.
c
lose
()
w
.
conn
=
nil
w
.
conn
=
nil
return
err
return
err
}
}
...
@@ -257,13 +266,22 @@ func (w *Writer) write(p Priority, msg string) (int, error) {
...
@@ -257,13 +266,22 @@ func (w *Writer) write(p Priority, msg string) (int, error) {
nl
=
"
\n
"
nl
=
"
\n
"
}
}
timestamp
:=
time
.
Now
()
.
Format
(
time
.
RFC3339
)
w
.
conn
.
writeString
(
p
,
w
.
hostname
,
w
.
tag
,
msg
,
nl
)
fmt
.
Fprintf
(
w
.
conn
,
"<%d>%s %s %s[%d]: %s%s"
,
p
,
timestamp
,
w
.
hostname
,
w
.
tag
,
os
.
Getpid
(),
msg
,
nl
)
return
len
(
msg
),
nil
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
// NewLogger creates a log.Logger whose output is written to
// the system log service with the specified priority. The logFlag
// the system log service with the specified priority. The logFlag
// argument is the flag set passed through to log.New to create
// argument is the flag set passed through to log.New to create
...
...
libgo/go/log/syslog/syslog_libc.go
View file @
9d824f6c
...
@@ -23,17 +23,17 @@ type libcConn int
...
@@ -23,17 +23,17 @@ type libcConn int
func
syslog_c
(
int
,
*
byte
)
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
)
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
)
buf
,
err
:=
syscall
.
BytePtrFromString
(
log
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
err
}
}
syscall
.
Entersyscall
()
syscall
.
Entersyscall
()
syslog_c
(
int
(
p
),
buf
)
syslog_c
(
int
(
p
),
buf
)
syscall
.
Exitsyscall
()
syscall
.
Exitsyscall
()
return
len
(
msg
),
nil
return
nil
}
}
func
(
libcConn
)
close
()
error
{
func
(
libcConn
)
close
()
error
{
...
...
libgo/go/log/syslog/syslog_unix.go
View file @
9d824f6c
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
// unixSyslog opens a connection to the syslog daemon running on the
// unixSyslog opens a connection to the syslog daemon running on the
// local machine using a Unix domain socket.
// local machine using a Unix domain socket.
func
unixSyslog
()
(
conn
net
.
Conn
,
err
error
)
{
func
unixSyslog
()
(
conn
server
Conn
,
err
error
)
{
logTypes
:=
[]
string
{
"unixgram"
,
"unix"
}
logTypes
:=
[]
string
{
"unixgram"
,
"unix"
}
logPaths
:=
[]
string
{
"/dev/log"
,
"/var/run/syslog"
}
logPaths
:=
[]
string
{
"/dev/log"
,
"/var/run/syslog"
}
for
_
,
network
:=
range
logTypes
{
for
_
,
network
:=
range
logTypes
{
...
@@ -23,7 +23,7 @@ func unixSyslog() (conn net.Conn, err error) {
...
@@ -23,7 +23,7 @@ func unixSyslog() (conn net.Conn, err error) {
if
err
!=
nil
{
if
err
!=
nil
{
continue
continue
}
else
{
}
else
{
return
conn
,
nil
return
netConn
{
conn
}
,
nil
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment