Commit 5a860a01 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[3095] Use the traceback handler

Put the traceback handler in the top level of all the python daemons and
some utility programs. The programs that don't do logging are not
included.
parent 50072746
......@@ -78,6 +78,7 @@ from isc.log_messages.init_messages import *
import isc.bind10.component
import isc.bind10.special_component
import isc.bind10.socket_cache
import isc.util.traceback_handler
import libutil_io_python
import tempfile
......@@ -1368,4 +1369,4 @@ def main():
sys.exit(b10_init.exitcode)
if __name__ == "__main__":
main()
isc.util.traceback_handler.traceback_handler(main)
......@@ -26,6 +26,7 @@ from bindctl import command_sets
import pprint
from optparse import OptionParser, OptionValueError
import isc.util.process
import isc.util.traceback_handler
isc.util.process.rename()
......@@ -150,7 +151,7 @@ def set_bindctl_options(parser):
default=None, action='store',
help='Directory to store the password CSV file')
if __name__ == '__main__':
def main():
parser = OptionParser(version = VERSION)
set_bindctl_options(parser)
(options, args) = parser.parse_args()
......@@ -161,3 +162,6 @@ if __name__ == '__main__':
command_sets.prepare_execute_commands(tool)
result = tool.run()
sys.exit(result)
if __name__ == '__main__':
isc.util.traceback_handler.traceback_handler(main)
......@@ -30,6 +30,7 @@ import isc.log
isc.log.init("b10-cfgmgr", buffer=True)
from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError, logger
from isc.log_messages.cfgmgr_messages import *
import isc.util.traceback_handler
isc.util.process.rename()
......@@ -128,4 +129,4 @@ def main():
return 0
if __name__ == "__main__":
sys.exit(main())
sys.exit(isc.util.traceback_handler.traceback_handler(main))
......@@ -48,6 +48,7 @@ from optparse import OptionParser, OptionValueError
from hashlib import sha1
from isc.util import socketserver_mixin
from isc.log_messages.cmdctl_messages import *
import isc.util.traceback_handler
isc.log.init("b10-cmdctl", buffer=True)
logger = isc.log.Logger("cmdctl")
......@@ -675,7 +676,7 @@ def set_cmd_options(parser):
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
help="display more about what is going on")
if __name__ == '__main__':
def main():
set_signal_handler()
parser = OptionParser(version = __version__)
set_cmd_options(parser)
......@@ -701,3 +702,6 @@ if __name__ == '__main__':
logger.info(CMDCTL_EXITING)
sys.exit(result)
if __name__ == '__main__':
isc.util.traceback_handler.traceback_handler(main)
......@@ -58,6 +58,7 @@ sys.excepthook = my_except_hook
import os, sqlite3, shutil
from optparse import OptionParser
import isc.util.process
import isc.util.traceback_handler
import isc.log
from isc.log_messages.dbutil_messages import *
......@@ -566,9 +567,11 @@ def parse_command():
sys.exit(EXIT_COMMAND_ERROR)
if __name__ == "__main__":
def main():
(options, args) = parse_command()
global logger
if options.verbose:
isc.log.init("b10-dbutil", "DEBUG", 99)
logger = isc.log.Logger("dbutil")
......@@ -619,3 +622,6 @@ if __name__ == "__main__":
exit_code = EXIT_UPGRADE_ERROR
sys.exit(exit_code)
if __name__ == "__main__":
isc.util.traceback_handler.traceback_handler(main)
......@@ -28,6 +28,7 @@ from isc.config.ccsession import *
from isc.config.module_spec import ModuleSpecError
from isc.cc import SessionError, SessionTimeout, ProtocolError
import isc.util.process
import isc.util.traceback_handler
import isc.util.cio.socketsession
import isc.server_common.tsig_keyring
from isc.server_common.dns_tcp import DNSTCPContext
......@@ -738,9 +739,8 @@ def main(ddns_server=None):
logger.error(DDNS_CONFIG_ERROR, str(e))
except SessionTimeout as e:
logger.error(DDNS_CC_SESSION_TIMEOUT_ERROR)
except Exception as e:
logger.error(DDNS_UNCAUGHT_EXCEPTION, type(e).__name__, str(e))
clear_socket()
finally:
clear_socket()
if '__main__' == __name__:
main()
isc.util.traceback_handler.traceback_handler(main)
......@@ -237,11 +237,6 @@ DDNS UPDATE messages, it will return SERVFAIL. However, this does point to
an underlying problem in the messaging system, and should be inspected.
The specific error is printed in the log message.
% DDNS_UNCAUGHT_EXCEPTION uncaught exception of type %1: %2
The b10-ddns process encountered an uncaught exception and will now shut
down. This is indicative of a programming error and should not happen under
normal circumstances. The exception type and message are printed.
% DDNS_UPDATE_NOTIFY notified %1 of updates to %2
Debug message. b10-ddns has made updates to a zone based on an update
request and has successfully notified an external module of the updates.
......
......@@ -1375,7 +1375,6 @@ class TestMain(unittest.TestCase):
self.check_exception(isc.config.ModuleCCSessionError("error"))
self.check_exception(ddns.DDNSConfigError("error"))
self.check_exception(isc.cc.SessionTimeout("error"))
self.check_exception(Exception("error"))
# Add one that is not a subclass of Exception, and hence not
# caught. Misuse BaseException for that.
......
......@@ -23,6 +23,7 @@ from optparse import OptionParser
from isc.dns import *
from isc.datasrc import *
import isc.util.process
import isc.util.traceback_handler
import isc.log
from isc.log_messages.loadzone_messages import *
from datetime import timedelta
......@@ -351,11 +352,14 @@ class LoadZoneRunner:
logger.error(LOADZONE_UNEXPECTED_FAILURE, ex)
return 1
if '__main__' == __name__:
def main():
runner = LoadZoneRunner(sys.argv[1:])
ret = runner.run()
sys.exit(ret)
if '__main__' == __name__:
isc.util.traceback_handler.traceback_handler(main)
## Local Variables:
## mode: python
## End:
......@@ -32,6 +32,7 @@ from isc.server_common.datasrc_clients_mgr \
from isc.memmgr.datasrc_info import DataSrcInfo
from isc.memmgr.builder import MemorySegmentBuilder
import isc.util.process
import isc.util.traceback_handler
MODULE_NAME = 'memmgr'
......@@ -209,6 +210,9 @@ class Memmgr(BIND10Server):
except isc.server_common.datasrc_clients_mgr.ConfigError as ex:
logger.error(MEMMGR_DATASRC_CONFIG_ERROR, ex)
if '__main__' == __name__:
def main():
mgr = Memmgr()
sys.exit(mgr.run(MODULE_NAME))
if '__main__' == __name__:
isc.util.traceback_handler.traceback_handler(main)
......@@ -33,6 +33,7 @@ import threading
import isc.config.ccsession
from optparse import OptionParser, OptionValueError
import isc.util.process
import isc.util.traceback_handler
from isc.cc.proto_defs import *
import isc.log
from isc.log_messages.msgq_messages import *
......@@ -779,7 +780,7 @@ def signal_handler(msgq, signal, frame):
if msgq:
msgq.stop()
if __name__ == "__main__":
def main():
def check_port(option, opt_str, value, parser):
"""Function to insure that the port we are passed is actually
a valid port number. Used by OptionParser() on startup."""
......@@ -855,3 +856,6 @@ if __name__ == "__main__":
msgq.shutdown()
logger.info(MSGQ_EXITING)
if __name__ == "__main__":
isc.util.traceback_handler.traceback_handler(main)
......@@ -29,6 +29,7 @@ import select
import isc.cc
import isc.config
import isc.util.process
import isc.util.traceback_handler
import isc.log
from isc.log_messages.stats_messages import *
......@@ -694,7 +695,7 @@ class Stats:
1, "specified arguments are incorrect: " \
+ "owner: " + str(owner) + ", name: " + str(name))
if __name__ == "__main__":
def main():
try:
parser = OptionParser()
parser.add_option(
......@@ -718,3 +719,6 @@ if __name__ == "__main__":
logger.info(STATS_STOPPED_BY_KEYBOARD)
logger.info(STATS_EXITING)
if __name__ == "__main__":
isc.util.traceback_handler.traceback_handler(main)
......@@ -35,6 +35,7 @@ import re
import isc.cc
import isc.config
import isc.util.process
import isc.util.traceback_handler
from isc.util.address_formatter import AddressFormatter
import isc.log
......@@ -598,7 +599,7 @@ class StatsHttpd:
"%s: %s" % (err.__class__.__name__, err))
return string.Template(lines)
if __name__ == "__main__":
def main():
try:
parser = OptionParser()
parser.add_option(
......@@ -622,3 +623,6 @@ if __name__ == "__main__":
logger.info(STATSHTTPD_STOPPED_BY_KEYBOARD)
logger.info(STATSHTTPD_EXITING)
if __name__ == "__main__":
isc.util.traceback_handler.traceback_handler(main)
......@@ -31,6 +31,7 @@ from isc.config.ccsession import *
from isc.statistics.dns import Counters
from isc.notify import notify_out
import isc.util.process
import isc.util.traceback_handler
from isc.util.address_formatter import AddressFormatter
from isc.datasrc import DataSourceClient, ZoneFinder
import isc.net.parse
......@@ -1847,4 +1848,4 @@ def main(xfrin_class, use_signal=True):
logger.info(XFRIN_EXITING)
if __name__ == '__main__':
main(Xfrin)
isc.util.traceback_handler.traceback_handler(lambda: main(Xfrin))
......@@ -30,6 +30,7 @@ from isc.cc import SessionError, SessionTimeout
from isc.statistics.dns import Counters
from isc.notify import notify_out
import isc.util.process
import isc.util.traceback_handler
import fcntl
import socket
import select
......@@ -1164,7 +1165,7 @@ def set_cmd_options(parser):
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
if '__main__' == __name__:
def main():
try:
parser = OptionParser()
set_cmd_options(parser)
......@@ -1189,3 +1190,6 @@ if '__main__' == __name__:
xfrout_server.shutdown()
logger.info(XFROUT_EXITING)
if '__main__' == __name__:
isc.util.traceback_handler.traceback_handler(main)
......@@ -37,6 +37,7 @@ import errno
from optparse import OptionParser, OptionValueError
from isc.config.ccsession import *
import isc.util.process
import isc.util.traceback_handler
from isc.log_messages.zonemgr_messages import *
from isc.notify import notify_out
from isc.server_common.datasrc_clients_mgr import DataSrcClientsMgr, ConfigError
......@@ -802,7 +803,7 @@ def set_cmd_options(parser):
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
if '__main__' == __name__:
def main():
try:
logger.debug(DBG_START_SHUT, ZONEMGR_STARTING)
parser = OptionParser()
......@@ -830,3 +831,6 @@ if '__main__' == __name__:
zonemgrd.shutdown()
logger.info(ZONEMGR_SHUTDOWN)
if '__main__' == __name__:
isc.util.traceback_handler.traceback_handler(main)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment