diff options
author | Eric Wong <e@80x24.org> | 2023-01-08 05:03:26 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-01-08 05:05:01 +0000 |
commit | b5ab9be6686aa778a4cfd7622c598736b9c42321 (patch) | |
tree | a967297606a1f91f8359e287d5a85ad018e185e3 /bin/mwrap | |
parent | 4356beb8237a92b3902b17f55cfe93d347b593d5 (diff) | |
parent | 2c25edb01139365f4754985c1e3494765dd1e5a7 (diff) | |
download | mwrap-b5ab9be6686aa778a4cfd7622c598736b9c42321.tar.gz |
This contains many changes from https://80x24.org/mwrap-perl.git commit * Built-in RCU-friendly version of dlmalloc, no more fragile dlsym(3m) resolution of malloc-family functions in the constructor * Allocations are now backed by O_TMPFILE on $TMPDIR on modern Linux. Since mwrap increases memory usage greatly and I needed to use it on a system where I needed more VM space but lacked the ability to add swap. * Configurable C backtrace level via MWRAP=bt:$DEPTH where $DEPTH is a non-negative integer. Be careful about increasing it, even a depth of 3-4 can be orders-of-magnitude more expensive in time and space. This can be changed dynamically at runtime via local HTTP (see below). * Embedded per-process local-socket-only HTTP server obsoletes MwrapRack when combined with mwrap-rproxy from the Perl dist (set `MWRAP=socket_dir:/dir/of/sockets') See https://80x24.org/mwrap-perl/20221210015518.272576-4-e@80x24.org/ for more info. It now supports downloading CSV (suitable for importing into sqlite 3.32.0+) * License switched to GPL-3+ to be compatible with GNU binutils since we may take code from addr2line in the future. * libxxhash supported if XXH3_64bits is available.
Diffstat (limited to 'bin/mwrap')
-rwxr-xr-x | bin/mwrap | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/mwrap b/bin/mwrap new file mode 100755 index 0000000..054b3a3 --- /dev/null +++ b/bin/mwrap @@ -0,0 +1,55 @@ +#!/usr/bin/ruby +# frozen_string_literal: true +# Copyright (C) mwrap hackers <mwrap-public@80x24.org> +# License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt> +help = <<EOM +usage: mwrap COMMAND [ARGS] +see https://80x24.org/mwrap/README.html for more info +EOM +ARGV.empty? and abort help +ARGV.each do |x| + case x + when '--version', '-v' + require 'mwrap/version' + puts "mwrap #{Mwrap::VERSION} - #{RUBY_DESCRIPTION}" + exit 0 + when '--help', '-h' + puts help + exit 0 + else # don't intercept --version/--help intended for commands we wrap + break + end +end + +require 'mwrap' +mwrap_so = $".grep(%r{/mwrap\.so\z})[0] or abort "mwrap.so not loaded" +cur = ENV['LD_PRELOAD'] +if cur + cur = cur.split(/[:\s]+/) + if !cur.include?(mwrap_so) + # drop old versions + cur.delete_if { |path| path.end_with?('/mwrap.so') } + cur.unshift(mwrap_so) + ENV['LD_PRELOAD'] = cur.join(':') + end +else + ENV['LD_PRELOAD'] = mwrap_so +end + +# work around close-on-exec by default behavior in Ruby: +opts = {} +if ENV['MWRAP'] =~ /dump_fd:(\d+)/ + dump_fd = $1.to_i + if dump_fd > 2 + dump_io = IO.new(dump_fd) + opts[dump_fd] = dump_io + end +end + +# allow inheriting FDs from systemd +n = ENV['LISTEN_FDS'] +if n && ENV['LISTEN_PID'].to_i == $$ + n = 3 + n.to_i + (3...n).each { |fd| opts[fd] = IO.new(fd) } +end +exec *ARGV, opts |