require 'fsdb'

include FSDB

$stdout.sync = true $stderr.sync = true

Thread.abort_on_exception = true

$db = Database.new('/tmp/fsdb-test')

trap 'INT' do

last_msgs 60
exit!

end

$eputs_msgs = [] def eputs str

Thread.exclusive do
  $eputs_msgs <<
    "Process #{Process.pid}, thread #{Thread.current[:number]} #{str}"
end

end

def last_msgs n

Thread.exclusive do
  $stderr.puts $eputs_msgs[-n..-1]
end

end