je 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/je CHANGED
@@ -1,19 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'timeout'
2
3
 
3
4
  # Set ENV for preloading jemalloc
4
5
  lib_dir = File.expand_path('../lib/', File.dirname(__FILE__))
5
6
  if File.exists? (lib_dir + "/jemalloc.so")
6
7
  puts "=> Injecting jemalloc..."
7
8
  ENV.store("LD_PRELOAD", lib_dir + "/jemalloc.so")
9
+ elsif File.exists? (lib_dir + "/jemalloc.bundle")
10
+ puts "=> Injecting jemalloc..."
11
+ ENV.store("DYLD_INSERT_LIBRARIES", lib_dir + "/jemalloc.bundle")
8
12
  else
9
13
  puts "=> Skip injecting jemalloc. Your platform is not supported."
10
14
  end
11
15
 
12
- # fork(2) and exec(2)
16
+ # fork(2)
13
17
  pid = Process.fork
18
+
19
+ # set signal handlerss
20
+ def terminate_gracefully(pid)
21
+ begin
22
+ Process.kill("SIGTERM", pid) rescue Errno::ESRCH
23
+ Timeout.timeout(3) {
24
+ pid, status = Process.wait2
25
+ Kernel.exit (status.exitstatus || 0)
26
+ }
27
+ rescue Timeout::Error
28
+ Process.kill("SIGKILL", pid) rescue Errno::ESRCH
29
+ end
30
+ end
31
+ trap("INT") { puts "SIGINT received"; terminate_gracefully pid }
32
+ trap("TERM") { puts "SIGTERM received"; terminate_gracefully pid }
33
+
34
+ # exec(2)
14
35
  if pid.nil? then
15
36
  Kernel.exec *ARGV
16
37
  else
17
38
  pid, status = Process.wait2
18
- Kernel.exit status.exitstatus
39
+ Kernel.exit (status.exitstatus || 0)
19
40
  end
@@ -1,10 +1,10 @@
1
1
  require 'mkmf'
2
2
  require 'rbconfig'
3
- require File.expand_path('../../lib/je/version', File.dirname(__FILE__))
4
3
 
5
4
  $stdout.sync = true
6
5
  pkg = "jemalloc-3.0.0"
7
6
 
7
+ # monfigure and copy sources to cur_dir
8
8
  cur_dir = Dir.pwd
9
9
  Dir.chdir File.dirname(__FILE__) do
10
10
  # cleanup
@@ -13,12 +13,12 @@ Dir.chdir File.dirname(__FILE__) do
13
13
  Dir.chdir(pkg) do
14
14
  # configure
15
15
  puts `./configure`
16
- # mkmf only allows *.c file on current dir
17
- puts `cp src/*.c ../`
18
16
  # zone.c is only for Mac OS X
19
17
  if RbConfig::CONFIG['target_vendor'] != "apple"
20
- puts `rm -fR ../zone.c`
18
+ puts `rm -fR src/zone.c`
21
19
  end
20
+ # mkmf only allows *.c files on current dir
21
+ puts `cp src/*.c #{cur_dir}`
22
22
  end
23
23
  end
24
24
  Dir.chdir cur_dir
@@ -27,3 +27,13 @@ include_dir= File.dirname(__FILE__) + "/#{pkg}/include/"
27
27
  $CFLAGS << %[ -std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -D_GNU_SOURCE -D_REENTRANT -I.. -I#{include_dir}]
28
28
 
29
29
  create_makefile('jemalloc')
30
+
31
+ # modify Makefile to create .dylib, instead of .bundle
32
+ # NOTICE: Mac OS X only
33
+ if RbConfig::CONFIG['target_vendor'] == "apple"
34
+ makefile = open('Makefile').read
35
+ makefile.gsub!(/-dynamic\ -bundle/, '-shared')
36
+ makefile.gsub!(/-flat_namespace/, '-dylib_install_name')
37
+ #,-dylib_install_name
38
+ open('Makefile', 'w'){ |f| f.write(makefile) }
39
+ end
data/lib/je/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JE
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: je
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-05 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler