diff options
author | William Tu <u9012063@gmail.com> | 2020-03-24 07:17:02 -0700 |
---|---|---|
committer | William Tu <u9012063@gmail.com> | 2020-03-24 07:46:37 -0700 |
commit | ecbc7f0aa2e112afc5ce63cf8a20ebd41e20b73b (patch) | |
tree | 71a73456559a680edbfd7d0bcee08962806bc3fc /lib | |
parent | ae2d6e3f5b066fe0f64a3c03b68501022450ad30 (diff) | |
download | openvswitch-ecbc7f0aa2e112afc5ce63cf8a20ebd41e20b73b.tar.gz |
fatal-signal: Fix clang error due to lock.
Due to not acquiring lock, clang reports:
lib/vlog.c:618:12: error: reading variable 'log_fd' requires holding mutex
'log_file_mutex' [-Werror,-Wthread-safety-analysis]
return log_fd;
The patch fixes it by creating a function in vlog.c to write
directly to log file unsafely.
Tested-at: https://travis-ci.org/github/williamtu/ovs-travis/builds/666165883
Fixes: ecd4a8fcdff2 ("fatal-signal: Log backtrace when no monitor daemon.")
Suggested-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: William Tu <u9012063@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fatal-signal.c | 8 | ||||
-rw-r--r-- | lib/vlog.c | 15 |
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 4965c1ae8..51cf628d9 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -197,11 +197,7 @@ send_backtrace_to_monitor(void) { */ char str[] = "SIGSEGV detected, backtrace:\n"; - if (vlog_get_fd() < 0) { - return; - } - - ignore(write(vlog_get_fd(), str, strlen(str))); + vlog_direct_write_to_log_file_unsafe(str); for (int i = 0; i < dep; i++) { char line[64]; @@ -210,7 +206,7 @@ send_backtrace_to_monitor(void) { unw_bt[i].ip, unw_bt[i].func, unw_bt[i].offset); - ignore(write(vlog_get_fd(), line, strlen(line))); + vlog_direct_write_to_log_file_unsafe(line); } } } diff --git a/lib/vlog.c b/lib/vlog.c index 502b33fc8..6d17d4837 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -612,10 +612,19 @@ vlog_set_syslog_target(const char *target) ovs_rwlock_unlock(&pattern_rwlock); } -int -vlog_get_fd(void) +/* + * This function writes directly to log file without using async writer or + * taking a lock. Caller must hold 'log_file_mutex' or be sure that it's + * not necessary. Could be used in exceptional cases like dumping of backtrace + * on fatal signals. + */ +void +vlog_direct_write_to_log_file_unsafe(const char *s) + OVS_NO_THREAD_SAFETY_ANALYSIS { - return log_fd; + if (log_fd >= 0) { + ignore(write(log_fd, s, strlen(s))); + } } /* Returns 'false' if 'facility' is not a valid string. If 'facility' |