about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-07-02 08:42:22 +0000
committerEric Wong <e@80x24.org>2018-07-02 08:42:22 +0000
commit53dfbf1ebcf508c5958c0b23a8470829b3842612 (patch)
treee3bd9e12af9f8c48f9416fc6cb7bb061ae158ab4
parent387d17cb130daf7d547d40f067bac61b735b2087 (diff)
downloadmwrap-53dfbf1ebcf508c5958c0b23a8470829b3842612.tar.gz
And drop redundant versions in case people upgrade
by replacing a running process.
-rwxr-xr-xbin/mwrap14
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/mwrap b/bin/mwrap
index 17e3570..964fdf8 100755
--- a/bin/mwrap
+++ b/bin/mwrap
@@ -1,9 +1,21 @@
 #!/usr/bin/ruby
 # frozen_string_literal: true
+# Copyright (C) 2018 mwrap hackers <mwrap-public@80x24.org>
+# License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
 require 'mwrap'
 mwrap_so = $".grep(%r{/mwrap\.so\z})[0] or abort "mwrap.so not loaded"
 cur = ENV['LD_PRELOAD']
-ENV['LD_PRELOAD'] = cur ? "#{mwrap_so}:#{cur}" : mwrap_so
+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 = {}