ruby-changes:72119
From: Koichi <ko1@a...>
Date: Fri, 10 Jun 2022 23:57:00 +0900 (JST)
Subject: [ruby-changes:72119] 1e528e8cbe (master): small fix on `setup_debug_log()`
https://git.ruby-lang.org/ruby.git/commit/?id=1e528e8cbe From 1e528e8cbef3231e1ffd908c9e1fb90b6b14173c Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 10 Jun 2022 15:40:12 +0900 Subject: small fix on `setup_debug_log()` * print `ruby_debug_log_mode` at first. * show filters when `ruby_debug_log_mode` is not "disabled". --- debug.c | 68 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/debug.c b/debug.c index b9df026af8..6b5684efb2 100644 --- a/debug.c +++ b/debug.c @@ -322,38 +322,10 @@ filter_type(const char *str, int *skiplen) https://github.com/ruby/ruby/blob/trunk/debug.c#L322 } static void -setup_debug_log(void) +setup_debug_log_filter(void) { - // check RUBY_DEBUG_LOG - const char *log_config = getenv("RUBY_DEBUG_LOG"); - if (log_config) { - fprintf(stderr, "RUBY_DEBUG_LOG=%s\n", log_config); - - if (strcmp(log_config, "mem") == 0) { - debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN); - if (debug_log.mem == NULL) { - fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n"); - exit(1); - } - ruby_debug_log_mode |= ruby_debug_log_memory; - } - else if (strcmp(log_config, "stderr") == 0) { - ruby_debug_log_mode |= ruby_debug_log_stderr; - } - else { - ruby_debug_log_mode |= ruby_debug_log_file; - if ((debug_log.output = fopen(log_config, "w")) == NULL) { - fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config); - exit(1); - } - setvbuf(debug_log.output, NULL, _IONBF, 0); - } - - rb_nativethread_lock_initialize(&debug_log.lock); - } - - // check RUBY_DEBUG_LOG_FILTER const char *filter_config = getenv("RUBY_DEBUG_LOG_FILTER"); + if (filter_config && strlen(filter_config) > 0) { unsigned int i; for (i=0; i<MAX_DEBUG_LOG_FILTER_NUM && filter_config; i++) { @@ -404,6 +376,42 @@ setup_debug_log(void) https://github.com/ruby/ruby/blob/trunk/debug.c#L376 } } +static void +setup_debug_log(void) +{ + // check RUBY_DEBUG_LOG + const char *log_config = getenv("RUBY_DEBUG_LOG"); + if (log_config && strlen(log_config) > 0) { + if (strcmp(log_config, "mem") == 0) { + debug_log.mem = (char *)malloc(MAX_DEBUG_LOG * MAX_DEBUG_LOG_MESSAGE_LEN); + if (debug_log.mem == NULL) { + fprintf(stderr, "setup_debug_log failed (can't allocate memory)\n"); + exit(1); + } + ruby_debug_log_mode |= ruby_debug_log_memory; + } + else if (strcmp(log_config, "stderr") == 0) { + ruby_debug_log_mode |= ruby_debug_log_stderr; + } + else { + ruby_debug_log_mode |= ruby_debug_log_file; + if ((debug_log.output = fopen(log_config, "w")) == NULL) { + fprintf(stderr, "can not open %s for RUBY_DEBUG_LOG\n", log_config); + exit(1); + } + setvbuf(debug_log.output, NULL, _IONBF, 0); + } + + fprintf(stderr, "RUBY_DEBUG_LOG=%s %s%s%s\n", log_config, + (ruby_debug_log_mode & ruby_debug_log_memory) ? "[mem]" : "", + (ruby_debug_log_mode & ruby_debug_log_stderr) ? "[stderr]" : "", + (ruby_debug_log_mode & ruby_debug_log_file) ? "[file]" : ""); + rb_nativethread_lock_initialize(&debug_log.lock); + + setup_debug_log_filter(); + } +} + static bool check_filter(const char *str, const struct debug_log_filter *filter, bool *state) { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/