From 43622f62162a5369bd0cf1c89dc565b9ba0b8f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Mon, 21 Jul 2025 17:43:08 +0200 Subject: [PATCH 1/2] Recognize quote as well as backtick in error message Ruby 3.4 started use singlequote instead of opening backtick in the error messages [[1]]. This exhibited in error: ~~~ 2) ABRT handles exception in 'abrt.rb' with RubyGems enabled Failure/Error: expect { system "ruby --disable-gems -rrubygems #{abrt_rb}" } .to output(/\A\Z/).to_stdout_from_any_process .and output(output_message_pattern).to_stderr_from_any_process expected block to output /\A\/mnt\/abrt\/spec\/..\/lib\/abrt.rb:\d+:in `
': can't modify frozen Array(: \[1, 2, 3\])? \((FrozenError|RuntimeError)\)\n\Z/ to stderr, but output "/mnt/abrt/spec/../lib/abrt.rb:15:in '
': can't modify frozen Array: [1, 2, 3] (FrozenError)\n" Diff for (output /\A\/mnt\/abrt\/spec\/..\/lib\/abrt.rb:\d+:in `
':...): @@ -1 +1 @@ -/\A\/mnt\/abrt\/spec\/..\/lib\/abrt.rb:\d+:in `
': can't modify frozen Array(: \[1, 2, 3\])? \((FrozenError|RuntimeError)\)\n\Z/ +/mnt/abrt/spec/../lib/abrt.rb:15:in '
': can't modify frozen Array: [1, 2, 3] (FrozenError) # ./spec/abrt_spec.rb:16:in 'block (3 levels) in ' ~~~ [1]: https://bugs.ruby-lang.org/issues/16495 --- spec/abrt_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/abrt_spec.rb b/spec/abrt_spec.rb index cd8ef41..3133261 100644 --- a/spec/abrt_spec.rb +++ b/spec/abrt_spec.rb @@ -3,7 +3,7 @@ describe 'ABRT' do context "handles exception in 'abrt.rb' with RubyGems" do abrt_rb = File.join(File.dirname(__FILE__), '../lib/abrt.rb') - output_message_pattern = /\A#{abrt_rb}:\d+:in `
': can't modify frozen Array(: \[1, 2, 3\])? \((FrozenError|RuntimeError)\)\n\Z/ + output_message_pattern = /\A#{abrt_rb}:\d+:in [`']
': can't modify frozen Array(: \[1, 2, 3\])? \((FrozenError|RuntimeError)\)\n\Z/ it 'disabled' do expect { system "ruby --disable-gems #{abrt_rb}" } From b35ced0fb2e92bfee3178c4714e1d5989a124d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 1 Aug 2025 13:04:20 +0200 Subject: [PATCH 2/2] Use custom `UtilLinuxLogger` instead `syslog` `syslog` used to be part of StdLib. But beginning with Ruby 3.4, it was extracted into default gems. This is problematic when Ruby is executed with `--disable-gems`, because there is no easy way to require `syslog`. Therefore, this commit introduces custom `UtilLinuxLogger`. This use `logger` command from util-linux and implemnts just minimal `Syslog` interface required. While this could have been used just as a fallback, when `syslog` can't be required, it will be easier to use it every time. Fixes #12 --- README.md | 5 +++++ lib/abrt/handler.rb | 4 ++-- lib/abrt/util_linux_logger.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/abrt/util_linux_logger.rb diff --git a/README.md b/README.md index 8a4c503..23e2f86 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,11 @@ gem "abrt", :require => false line into your *Gemfile*. +### Dependencies + +This library is `logger` utility from util-linux for logging purposes. Please +make sure it is available on your system for proper functionality. + ## Usage There are several ways how to run any application with ABRT handler enabled. diff --git a/lib/abrt/handler.rb b/lib/abrt/handler.rb index e116fde..27ee525 100644 --- a/lib/abrt/handler.rb +++ b/lib/abrt/handler.rb @@ -1,5 +1,5 @@ require 'socket' -require 'syslog' +require_relative 'util_linux_logger' require_relative 'exception' module ABRT @@ -16,7 +16,7 @@ def self.handle_exception(exception) private def self.syslog - @syslog ||= Syslog.open 'abrt' + @syslog ||= UtilLinuxLogger.open 'abrt' end def self.report(exception, io = nil) diff --git a/lib/abrt/util_linux_logger.rb b/lib/abrt/util_linux_logger.rb new file mode 100644 index 0000000..32b85fa --- /dev/null +++ b/lib/abrt/util_linux_logger.rb @@ -0,0 +1,34 @@ +# UtilLinuxLogger is small utility class intended to be drop in replacement for +# Syslog. It uses `logger` command from util-linux project to provide system +# logging facilities. +# +# It implements just minimal interface required by ABRT project. +class UtilLinuxLogger + # :yields: syslog + # + # Open the UtilLinuxLoggersyslog facility. + # + # `ident` is a String which identifies the calling program. + def self.open(ident) + self.new(ident) + end + + def initialize(ident) + @ident = ident + end + + def notice(format_string, *arguments) + log 'user.notice', format_string, *arguments + end + + def err(format_string, *arguments) + log 'user.err', format_string, *arguments + end + +private + def log(priority, format_string, *arguments) + IO.popen "logger -p #{priority} -t #{@ident} --socket-errors=off", 'w' do |io| + io.write sprintf(format_string, *arguments) + end + end +end