[svn] commit: r2405 - in /branches/trac259/src/bin: auth/asio_link.cc auth/main.cc bind10/bind10.py.in bind10/tests/bind10_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jul 2 04:37:59 UTC 2010
Author: each
Date: Fri Jul 2 04:37:59 2010
New Revision: 2405
Log:
checkpoint:
- changed ProcessInfo to Process in src/bin/bind10
- added a test for dev_null_stderr initialization
- comments and other minor cleanups
Modified:
branches/trac259/src/bin/auth/asio_link.cc
branches/trac259/src/bin/auth/main.cc
branches/trac259/src/bin/bind10/bind10.py.in
branches/trac259/src/bin/bind10/tests/bind10_test.py
Modified: branches/trac259/src/bin/auth/asio_link.cc
==============================================================================
--- branches/trac259/src/bin/auth/asio_link.cc (original)
+++ branches/trac259/src/bin/auth/asio_link.cc Fri Jul 2 04:37:59 2010
@@ -55,6 +55,7 @@
return false;
}
+ // XXX: temporarily using C-style cast; it will be removed in future work
const uint16_t query_type = *(uint16_t *)(msg_data + (msg_len - 4));
if ( query_type == 0xFC00) {
return true;
@@ -82,6 +83,8 @@
XfroutClient xfr_client(path);
try {
xfr_client.connect();
+ // XXX: temporarily using C-style cast; it will be removed
+ // in future work
xfr_client.sendXfroutRequestInfo(tcp_sock, (uint8_t *)axfr_query,
query_len);
xfr_client.disconnect();
Modified: branches/trac259/src/bin/auth/main.cc
==============================================================================
--- branches/trac259/src/bin/auth/main.cc (original)
+++ branches/trac259/src/bin/auth/main.cc Fri Jul 2 04:37:59 2010
@@ -13,6 +13,8 @@
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
+
+#define AUTH_SPECFILE_SOURCE "/src/bin/auth/auth.spec"
#include "config.h"
@@ -57,18 +59,19 @@
const string PROGRAM = "Auth";
const char* DNSPORT = "5300";
-/* need global var for config/command handlers.
- * todo: turn this around, and put handlers in the authserver
- * class itself? */
+// These are defined as global variables because they are
+// used by the configuration and command handlers.
AuthSrv *auth_server;
-
asio_link::IOService* io_service;
+// Configuration handler; causes the auth server to update its
+// current settings (e.g., switching to a different data source).
ElementPtr
my_config_handler(ElementPtr new_config) {
return auth_server->updateConfig(new_config);
}
+// Command handler.
ElementPtr
my_command_handler(const string& command, const ElementPtr args) {
ElementPtr answer = createAnswer();
@@ -138,23 +141,25 @@
usage();
}
- // initialize command channel
int ret = 0;
try {
string specfile;
if (getenv("B10_FROM_BUILD")) {
specfile = string(getenv("B10_FROM_BUILD")) +
- "/src/bin/auth/auth.spec";
+ AUTH_SPECFILE_SOURCE;
} else {
specfile = string(AUTH_SPECFILE_LOCATION);
}
+ // initialize auth server
auth_server = new AuthSrv(cache);
auth_server->setVerbose(verbose_mode);
+ // set up asynchronous I/O
io_service = new asio_link::IOService(auth_server, address, port,
use_ipv4, use_ipv6);
+ // initialize command channel
ModuleCCSession cs(specfile, io_service->get_io_service(),
my_config_handler, my_command_handler);
Modified: branches/trac259/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/trac259/src/bin/bind10/bind10.py.in (original)
+++ branches/trac259/src/bin/bind10/bind10.py.in Fri Jul 2 04:37:59 2010
@@ -112,9 +112,9 @@
when = time.time()
return max(when, self.restart_time)
-class ProcessInfoError(Exception): pass
-
-class ProcessInfo:
+class ProcessError(Exception): pass
+
+class Process:
"""Information about a process"""
dev_null = open(os.devnull, "w")
@@ -140,7 +140,7 @@
except OSError as e:
if e.errno == errno.EPERM:
# if we failed to change user due to permission report that
- raise ProcessInfoError("Unable to change to user %s (uid %d)" % (self.username, self.uid))
+ raise ProcessError("Unable to change to user %s (uid %d)" % (self.username, self.uid))
else:
# otherwise simply re-raise whatever error we found
raise
@@ -278,9 +278,9 @@
if self.msgq_socket_file:
sys.stdout.write("[bind10] Starting b10-msgq\n")
try:
- c_channel = ProcessInfo("b10-msgq", ["b10-msgq"], c_channel_env,
- True, not self.verbose, uid=self.uid,
- username=self.username)
+ c_channel = Process("b10-msgq", ["b10-msgq"], c_channel_env,
+ True, not self.verbose, uid=self.uid,
+ username=self.username)
except Exception as e:
return "Unable to start b10-msgq; " + str(e)
self.processes[c_channel.pid] = c_channel
@@ -305,9 +305,9 @@
if self.verbose:
sys.stdout.write("[bind10] Starting b10-cfgmgr\n")
try:
- bind_cfgd = ProcessInfo("b10-cfgmgr", ["b10-cfgmgr"],
- c_channel_env, uid=self.uid,
- username=self.username)
+ bind_cfgd = Process("b10-cfgmgr", ["b10-cfgmgr"],
+ c_channel_env, uid=self.uid,
+ username=self.username)
except Exception as e:
c_channel.process.kill()
return "Unable to start b10-cfgmgr; " + str(e)
@@ -344,8 +344,7 @@
sys.stdout.write(" on %s" % str(self.address))
sys.stdout.write("\n")
try:
- auth = ProcessInfo("b10-auth", authargs,
- c_channel_env)
+ auth = Process("b10-auth", authargs, c_channel_env)
except Exception as e:
c_channel.process.kill()
bind_cfgd.process.kill()
@@ -366,8 +365,7 @@
sys.stdout.write("[bind10] Starting b10-xfrout\n")
xfrout_args += ['-v']
try:
- xfrout = ProcessInfo("b10-xfrout", xfrout_args,
- c_channel_env )
+ xfrout = Process("b10-xfrout", xfrout_args, c_channel_env)
except Exception as e:
c_channel.process.kill()
bind_cfgd.process.kill()
@@ -383,8 +381,7 @@
sys.stdout.write("[bind10] Starting b10-xfrin\n")
xfrin_args += ['-v']
try:
- xfrind = ProcessInfo("b10-xfrin", xfrin_args,
- c_channel_env)
+ xfrind = Process("b10-xfrin", xfrin_args, c_channel_env)
except Exception as e:
c_channel.process.kill()
bind_cfgd.process.kill()
@@ -403,8 +400,7 @@
sys.stdout.write("[bind10] Starting b10-cmdctl on port 8080\n")
cmdctl_args += ['-v']
try:
- cmd_ctrld = ProcessInfo("b10-cmdctl", cmdctl_args,
- c_channel_env)
+ cmd_ctrld = Process("b10-cmdctl", cmdctl_args, c_channel_env)
except Exception as e:
c_channel.process.kill()
bind_cfgd.process.kill()
Modified: branches/trac259/src/bin/bind10/tests/bind10_test.py
==============================================================================
--- branches/trac259/src/bin/bind10/tests/bind10_test.py (original)
+++ branches/trac259/src/bin/bind10/tests/bind10_test.py Fri Jul 2 04:37:59 2010
@@ -1,4 +1,4 @@
-from bind10 import ProcessInfo, BoB, IPAddr
+from bind10 import Process, BoB, IPAddr
# XXX: environment tests are currently disabled, due to the preprocessor
# setup that we have now complicating the environment
@@ -9,7 +9,7 @@
import signal
import socket
-class TestProcessInfo(unittest.TestCase):
+class TestProcess(unittest.TestCase):
def setUp(self):
# redirect stdout to a pipe so we can check that our
# process spawning is doing the right thing with stdout
@@ -28,33 +28,34 @@
os.close(self.pipes[0])
def test_init(self):
- pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ])
+ pi = Process('Test Process', [ '/bin/echo', 'foo' ])
os.dup2(self.old_stdout, sys.stdout.fileno())
self.assertEqual(pi.name, 'Test Process')
self.assertEqual(pi.args, [ '/bin/echo', 'foo' ])
# self.assertEqual(pi.env, { 'PATH': os.environ['PATH'],
# 'PYTHON_EXEC': os.environ['PYTHON_EXEC'] })
self.assertEqual(pi.dev_null_stdout, False)
+ self.assertEqual(pi.dev_null_stderr, False)
self.assertEqual(os.read(self.pipes[0], 100), b"foo\n")
self.assertNotEqual(pi.process, None)
self.assertTrue(type(pi.pid) is int)
# def test_setting_env(self):
-# pi = ProcessInfo('Test Process', [ '/bin/true' ], env={'FOO': 'BAR'})
+# pi = Process('Test Process', [ '/bin/true' ], env={'FOO': 'BAR'})
# os.dup2(self.old_stdout, sys.stdout.fileno())
# self.assertEqual(pi.env, { 'PATH': os.environ['PATH'],
# 'PYTHON_EXEC': os.environ['PYTHON_EXEC'],
# 'FOO': 'BAR' })
def test_setting_null_stdout(self):
- pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ],
- dev_null_stdout=True)
+ pi = Process('Test Process', [ '/bin/echo', 'foo' ],
+ dev_null_stdout=True)
os.dup2(self.old_stdout, sys.stdout.fileno())
self.assertEqual(pi.dev_null_stdout, True)
self.assertEqual(os.read(self.pipes[0], 100), b"")
def test_respawn(self):
- pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ])
+ pi = Process('Test Process', [ '/bin/echo', 'foo' ])
# wait for old process to work...
self.assertEqual(os.read(self.pipes[0], 100), b"foo\n")
# respawn it
More information about the bind10-changes
mailing list