Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
df51b141
Commit
df51b141
authored
May 11, 2000
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collector #888: newer syslogd won't accept SOCK_STREAM connections; add unit test
parent
0054243b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
6 deletions
+156
-6
ZServer/medusa/m_syslog.py
ZServer/medusa/m_syslog.py
+64
-3
ZServer/medusa/test_logger.py
ZServer/medusa/test_logger.py
+14
-0
lib/python/ZServer/medusa/m_syslog.py
lib/python/ZServer/medusa/m_syslog.py
+64
-3
lib/python/ZServer/medusa/test_logger.py
lib/python/ZServer/medusa/test_logger.py
+14
-0
No files found.
ZServer/medusa/m_syslog.py
View file @
df51b141
# -*- Mode: Python; tab-width: 4 -*-
# From: "Samual M. Rushing" <rushing@nightmare.com>
# Date: Mon, 21 Apr 1997 16:10:42 -0500
# ======================================================================
# Copyright 1997 by Sam Rushing
#
...
...
@@ -140,11 +143,18 @@ class syslog_client:
def
__init__
(
self
,
address
=
'/dev/log'
):
self
.
address
=
address
if
type
(
address
)
==
type
(
''
):
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
address
)
try
:
# APUE 13.4.2 specifes /dev/log as datagram socket
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
self
.
socket
.
connect
(
address
)
except
:
# older linux may create as stream socket
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
address
)
self
.
unix
=
1
else
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
unix
=
0
# curious: when talking to the unix-domain '/dev/log' socket, a
...
...
@@ -175,3 +185,54 @@ class syslog_client:
if
self
.
unix
:
self
.
socket
.
close
()
if
__name__
==
'__main__'
:
"""
Unit test for syslog_client. Set up for the test by:
* tail -f /var/log/allstuf (to see the "normal" log messages).
* Running the test_logger.py script with a junk file name (which
will be opened as a Unix-domain socket). "Custom" log messages
will go here.
* Run this script, passing the same junk file name.
* Check that the "bogus" test throws, and that none of the rest do.
* Check that the 'default' and 'UDP' messages show up in the tail.
* Check that the 'non-std' message shows up in the test_logger
console.
* Finally, kill off the tail and test_logger, and clean up the
socket file.
"""
import
sys
,
traceback
if
len
(
sys
.
argv
)
!=
2
:
print
"Usage: syslog.py localSocketFilename"
sys
.
exit
()
def
test_client
(
desc
,
address
=
None
):
try
:
if
address
:
client
=
syslog_client
(
address
)
else
:
client
=
syslog_client
()
except
:
print
'syslog_client() [%s] ctor threw'
%
desc
traceback
.
print_exc
()
return
try
:
client
.
log
(
'testing syslog_client() [%s]'
%
desc
,
facility
=
'local0'
,
priority
=
'debug'
)
print
'syslog_client.log() [%s] did not throw'
%
desc
except
:
print
'syslog_client.log() [%s] threw'
%
desc
traceback
.
print_exc
()
test_client
(
'default'
)
test_client
(
'bogus file'
,
'/some/bogus/logsocket'
)
test_client
(
'nonstd file'
,
sys
.
argv
[
1
]
)
test_client
(
'UDP'
,
(
'localhost'
,
514
)
)
ZServer/medusa/test_logger.py
0 → 100644
View file @
df51b141
import
sys
import
socket
import
select
print
"Simulating Unix-domain logging using file: %s"
%
sys
.
argv
[
1
]
log_socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
log_socket
.
bind
(
sys
.
argv
[
1
]
)
while
1
:
n
=
select
.
select
(
[
log_socket
],
[],
[]
)
print
"."
,
if
n
>
0
:
print
log_socket
.
recv
(
1024
)
lib/python/ZServer/medusa/m_syslog.py
View file @
df51b141
# -*- Mode: Python; tab-width: 4 -*-
# From: "Samual M. Rushing" <rushing@nightmare.com>
# Date: Mon, 21 Apr 1997 16:10:42 -0500
# ======================================================================
# Copyright 1997 by Sam Rushing
#
...
...
@@ -140,11 +143,18 @@ class syslog_client:
def
__init__
(
self
,
address
=
'/dev/log'
):
self
.
address
=
address
if
type
(
address
)
==
type
(
''
):
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
address
)
try
:
# APUE 13.4.2 specifes /dev/log as datagram socket
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
self
.
socket
.
connect
(
address
)
except
:
# older linux may create as stream socket
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
address
)
self
.
unix
=
1
else
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
unix
=
0
# curious: when talking to the unix-domain '/dev/log' socket, a
...
...
@@ -175,3 +185,54 @@ class syslog_client:
if
self
.
unix
:
self
.
socket
.
close
()
if
__name__
==
'__main__'
:
"""
Unit test for syslog_client. Set up for the test by:
* tail -f /var/log/allstuf (to see the "normal" log messages).
* Running the test_logger.py script with a junk file name (which
will be opened as a Unix-domain socket). "Custom" log messages
will go here.
* Run this script, passing the same junk file name.
* Check that the "bogus" test throws, and that none of the rest do.
* Check that the 'default' and 'UDP' messages show up in the tail.
* Check that the 'non-std' message shows up in the test_logger
console.
* Finally, kill off the tail and test_logger, and clean up the
socket file.
"""
import
sys
,
traceback
if
len
(
sys
.
argv
)
!=
2
:
print
"Usage: syslog.py localSocketFilename"
sys
.
exit
()
def
test_client
(
desc
,
address
=
None
):
try
:
if
address
:
client
=
syslog_client
(
address
)
else
:
client
=
syslog_client
()
except
:
print
'syslog_client() [%s] ctor threw'
%
desc
traceback
.
print_exc
()
return
try
:
client
.
log
(
'testing syslog_client() [%s]'
%
desc
,
facility
=
'local0'
,
priority
=
'debug'
)
print
'syslog_client.log() [%s] did not throw'
%
desc
except
:
print
'syslog_client.log() [%s] threw'
%
desc
traceback
.
print_exc
()
test_client
(
'default'
)
test_client
(
'bogus file'
,
'/some/bogus/logsocket'
)
test_client
(
'nonstd file'
,
sys
.
argv
[
1
]
)
test_client
(
'UDP'
,
(
'localhost'
,
514
)
)
lib/python/ZServer/medusa/test_logger.py
0 → 100644
View file @
df51b141
import
sys
import
socket
import
select
print
"Simulating Unix-domain logging using file: %s"
%
sys
.
argv
[
1
]
log_socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
log_socket
.
bind
(
sys
.
argv
[
1
]
)
while
1
:
n
=
select
.
select
(
[
log_socket
],
[],
[]
)
print
"."
,
if
n
>
0
:
print
log_socket
.
recv
(
1024
)
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