Requested-by: P R Dinesh Requested-at: https://github.com/openvswitch/ovs/pull/94 Signed-off-by: Ben Pfaff <b...@ovn.org> --- lib/vlog.c | 24 ++++++++++++++++++ python/ovs/vlog.py | 11 +++++++- tests/vlog.at | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/lib/vlog.c b/lib/vlog.c index 28cea5d..2b8ba2b 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -677,6 +677,28 @@ vlog_unixctl_reopen(struct unixctl_conn *conn, int argc OVS_UNUSED, } static void +vlog_unixctl_close(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) +{ + ovs_mutex_lock(&log_file_mutex); + if (log_fd >= 0) { + close(log_fd); + log_fd = -1; + + async_append_destroy(log_writer); + log_writer = NULL; + + struct vlog_module *mp; + LIST_FOR_EACH (mp, list, &vlog_modules) { + update_min_level(mp); + } + } + ovs_mutex_unlock(&log_file_mutex); + + unixctl_command_reply(conn, NULL); +} + +static void set_all_rate_limits(bool enable) { struct vlog_module *mp; @@ -770,6 +792,8 @@ vlog_init(void) 0, INT_MAX, vlog_disable_rate_limit, NULL); unixctl_command_register("vlog/reopen", "", 0, 0, vlog_unixctl_reopen, NULL); + unixctl_command_register("vlog/close", "", 0, 0, + vlog_unixctl_close, NULL); ovs_rwlock_rdlock(&pattern_rwlock); print_syslog_target_deprecation = syslog_fd >= 0; diff --git a/python/ovs/vlog.py b/python/ovs/vlog.py index d5741a6..7102503 100644 --- a/python/ovs/vlog.py +++ b/python/ovs/vlog.py @@ -1,5 +1,5 @@ -# Copyright (c) 2011, 2012, 2013 Nicira, Inc. +# Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -238,6 +238,8 @@ class Vlog: ovs.unixctl.command_register("vlog/reopen", "", 0, 0, Vlog._unixctl_vlog_reopen, None) + ovs.unixctl.command_register("vlog/close", "", 0, 0, + Vlog._unixctl_vlog_close, None) ovs.unixctl.command_register("vlog/set", "spec", 1, sys.maxint, Vlog._unixctl_vlog_set, None) ovs.unixctl.command_register("vlog/list", "", 0, 0, @@ -387,6 +389,13 @@ class Vlog: conn.reply("Logging to file not configured") @staticmethod + def _unixctl_vlog_close(conn, unused_argv, unused_aux): + if Vlog.__log_file: + logger = logging.getLogger("file") + logger.removeHandler(Vlog.__file_handler) + conn.reply(None) + + @staticmethod def _unixctl_vlog_set(conn, argv, unused_aux): for arg in argv: msg = Vlog.set_levels_from_string(arg) diff --git a/tests/vlog.at b/tests/vlog.at index a614647..269bfc5 100644 --- a/tests/vlog.at +++ b/tests/vlog.at @@ -255,6 +255,80 @@ AT_CHECK([sed 's/.*|//' log], [0], [dnl ]) AT_CLEANUP +AT_SETUP([vlog - vlog/close - C]) +on_exit 'kill `cat test-unixctl.pid`' + +AT_CAPTURE_FILE([log]) +AT_CAPTURE_FILE([log.old]) +AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach], + [0], [], [stderr]) +AT_CHECK([vlog_filt stderr], [0], [opened log file +]) + +AT_CHECK([APPCTL -t test-unixctl log message]) +AT_CHECK([APPCTL -t test-unixctl log message2]) + +# After closing the log file, message3 won't appear anywhere. +AT_CHECK([APPCTL -t test-unixctl vlog/close]) +mv log log.old +AT_CHECK([APPCTL -t test-unixctl log message3]) + +# Closing the log file again is harmless. +AT_CHECK([APPCTL -t test-unixctl vlog/close]) +AT_CHECK([APPCTL -t test-unixctl log message4]) + +# After reopening the log file, further messages start appearing again. +AT_CHECK([APPCTL -t test-unixctl vlog/reopen]) +AT_CHECK([APPCTL -t test-unixctl log message5]) +AT_CHECK([APPCTL -t test-unixctl exit]) + +AT_CHECK([vlog_filt log.old], [0], [dnl +opened log file +Entering run loop. +message +message2 +]) +AT_CHECK([vlog_filt log], [0], [dnl +opened log file +message5 +]) +AT_CLEANUP + +AT_SETUP([vlog - vlog/close - Python]) +AT_SKIP_IF([test $HAVE_PYTHON = no]) +on_exit 'kill `cat test-unixctl.py.pid`' + +AT_CAPTURE_FILE([log]) +AT_CAPTURE_FILE([log.old]) +AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach]) + +AT_CHECK([APPCTL -t test-unixctl.py log message]) +AT_CHECK([APPCTL -t test-unixctl.py log message2]) + +# After closing the log file, message3 won't appear anywhere. +AT_CHECK([APPCTL -t test-unixctl.py vlog/close]) +mv log log.old +AT_CHECK([APPCTL -t test-unixctl.py log message3]) + +# Closing the log file again is harmless. +AT_CHECK([APPCTL -t test-unixctl.py vlog/close]) +AT_CHECK([APPCTL -t test-unixctl.py log message4]) + +# After reopening the log file, further messages start appearing again. +AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen]) +AT_CHECK([APPCTL -t test-unixctl.py log message5]) +AT_CHECK([APPCTL -t test-unixctl.py exit]) + +AT_CHECK([sed 's/.*|//' log.old], [0], [dnl + Entering run loop. + message + message2 +]) +AT_CHECK([sed 's/.*|//' log], [0], [dnl + message5 +]) +AT_CLEANUP + AT_SETUP([vlog - vlog/set and vlog/list - C]) on_exit 'kill `cat test-unixctl.pid`' -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev